jacint@72: #include jacint@72: #include jacint@72: #include jacint@72: jacint@78: #include jacint@78: #include jacint@78: #include jacint@78: #include jacint@78: //#include jacint@72: jacint@72: using namespace marci; jacint@72: jacint@72: jacint@72: int main (int, char*[]) jacint@72: { jacint@78: typedef ListGraph::NodeIt NodeIt; jacint@78: typedef ListGraph::EdgeIt EdgeIt; jacint@78: typedef ListGraph::EachNodeIt EachNodeIt; jacint@78: typedef ListGraph::EachEdgeIt EachEdgeIt; jacint@78: typedef ListGraph::OutEdgeIt OutEdgeIt; jacint@78: typedef ListGraph::InEdgeIt InEdgeIt; jacint@78: jacint@78: ListGraph flow_test; jacint@72: jacint@72: //Ahuja könyv példája, maxflowvalue=13 jacint@78: NodeIt s=flow_test.addNode(); jacint@78: NodeIt v1=flow_test.addNode(); jacint@78: NodeIt v2=flow_test.addNode(); jacint@78: NodeIt v3=flow_test.addNode(); jacint@78: NodeIt v4=flow_test.addNode(); jacint@78: NodeIt v5=flow_test.addNode(); jacint@78: NodeIt t=flow_test.addNode(); jacint@72: jacint@78: ListGraph::NodeMap Node_name(flow_test); jacint@78: Node_name.set(s, "s"); jacint@78: Node_name.set(v1, "v1"); jacint@78: Node_name.set(v2, "v2"); jacint@78: Node_name.set(v3, "v3"); jacint@78: Node_name.set(v4, "v4"); jacint@78: Node_name.set(v5, "v5"); jacint@78: Node_name.set(t, "t"); jacint@72: jacint@78: EdgeIt s_v1=flow_test.addEdge(s, v1); jacint@78: EdgeIt s_v2=flow_test.addEdge(s, v2); jacint@78: EdgeIt s_v3=flow_test.addEdge(s, v3); jacint@78: EdgeIt v2_v4=flow_test.addEdge(v2, v4); jacint@78: EdgeIt v2_v5=flow_test.addEdge(v2, v5); jacint@78: EdgeIt v3_v5=flow_test.addEdge(v3, v5); jacint@78: EdgeIt v4_t=flow_test.addEdge(v4, t); jacint@78: EdgeIt v5_t=flow_test.addEdge(v5, t); jacint@78: EdgeIt v2_s=flow_test.addEdge(v2, s); jacint@72: jacint@78: ListGraph::EdgeMap cap(flow_test); jacint@78: cap.set(s_v1, 0); jacint@78: cap.set(s_v2, 10); jacint@78: cap.set(s_v3, 10); jacint@78: cap.set(v2_v4, 5); jacint@78: cap.set(v2_v5, 8); jacint@78: cap.set(v3_v5, 5); jacint@78: cap.set(v4_t, 8); jacint@78: cap.set(v5_t, 8); jacint@78: cap.set(v2_s, 0); jacint@72: jacint@72: jacint@72: jacint@72: //Marci példája, maxflowvalue=23 jacint@78: /* NodeIt s=flow_test.addNode(); jacint@78: NodeIt v1=flow_test.addNode(); jacint@78: NodeIt v2=flow_test.addNode(); jacint@78: NodeIt v3=flow_test.addNode(); jacint@78: NodeIt v4=flow_test.addNode(); jacint@78: NodeIt t=flow_test.addNode(); jacint@78: NodeIt w=flow_test.addNode(); jacint@72: jacint@72: jacint@78: NodeMap Node_name(flow_test); jacint@78: Node_name.set(s, "s"); jacint@78: Node_name.set(v1, "v1"); jacint@78: Node_name.set(v2, "v2"); jacint@78: Node_name.set(v3, "v3"); jacint@78: Node_name.set(v4, "v4"); jacint@78: Node_name.set(t, "t"); jacint@78: Node_name.set(w, "w"); jacint@72: jacint@78: EdgeIt s_v1=flow_test.addEdge(s, v1); jacint@78: EdgeIt s_v2=flow_test.addEdge(s, v2); jacint@78: EdgeIt v1_v2=flow_test.addEdge(v1, v2); jacint@78: EdgeIt v2_v1=flow_test.addEdge(v2, v1); jacint@78: EdgeIt v1_v3=flow_test.addEdge(v1, v3); jacint@78: EdgeIt v3_v2=flow_test.addEdge(v3, v2); jacint@78: EdgeIt v2_v4=flow_test.addEdge(v2, v4); jacint@78: EdgeIt v4_v3=flow_test.addEdge(v4, v3); jacint@78: EdgeIt v3_t=flow_test.addEdge(v3, t); jacint@78: EdgeIt v4_t=flow_test.addEdge(v4, t); jacint@78: EdgeIt v3_v3=flow_test.addEdge(v3, v3); jacint@78: EdgeIt s_w=flow_test.addEdge(s, w); jacint@78: // EdgeIt v2_s=flow_test.addEdge(v2, s); jacint@72: jacint@72: jacint@72: jacint@78: EdgeMap cap(flow_test); //serves as length in dijkstra jacint@78: cap.set(s_v1, 16); jacint@78: cap.set(s_v2, 13); jacint@78: cap.set(v1_v2, 10); jacint@78: cap.set(v2_v1, 4); jacint@78: cap.set(v1_v3, 12); jacint@78: cap.set(v3_v2, 9); jacint@78: cap.set(v2_v4, 14); jacint@78: cap.set(v4_v3, 7); jacint@78: cap.set(v3_t, 20); jacint@78: cap.set(v4_t, 4); jacint@78: cap.set(v3_v3, 4); jacint@78: cap.set(s_w, 4); jacint@78: // cap.set(v2_s, 0); jacint@72: jacint@72: */ jacint@72: jacint@72: //pelda 3, maxflowvalue=4 jacint@78: /* NodeIt s=flow_test.addNode(); jacint@78: NodeIt v1=flow_test.addNode(); jacint@78: NodeIt v2=flow_test.addNode(); jacint@78: NodeIt t=flow_test.addNode(); jacint@78: NodeIt w=flow_test.addNode(); jacint@72: jacint@78: NodeMap Node_name(flow_test); jacint@78: Node_name.set(s, "s"); jacint@78: Node_name.set(v1, "v1"); jacint@78: Node_name.set(v2, "v2"); jacint@78: Node_name.set(t, "t"); jacint@78: Node_name.set(w, "w"); jacint@72: jacint@78: EdgeIt s_v1=flow_test.addEdge(s, v1); jacint@78: EdgeIt v1_v2=flow_test.addEdge(v1, v2); jacint@78: EdgeIt v2_t=flow_test.addEdge(v2, t); jacint@78: EdgeIt v1_v1=flow_test.addEdge(v1, v1); jacint@78: EdgeIt s_w=flow_test.addEdge(s, w); jacint@72: jacint@72: jacint@78: EdgeMap cap(flow_test); jacint@72: jacint@78: cap.set(s_v1, 16); jacint@78: cap.set(v1_v2, 10); jacint@78: cap.set(v2_t, 4); jacint@78: cap.set(v1_v1, 3); jacint@78: cap.set(s_w, 5); jacint@72: */ jacint@72: jacint@72: jacint@72: jacint@72: /* jacint@72: std::cout << "Testing reverse_bfs..." << std::endl; jacint@72: jacint@78: reverse_bfs bfs_test(flow_test, t); jacint@72: jacint@72: bfs_test.run(); jacint@72: jacint@78: for (EachNodeIt w=flow_test.first_Node(); w.valid(); ++w) { jacint@72: std::cout <<"The distance of " << w << " is " << bfs_test.dist(w) < preflow_push_test(flow_test, s, t, cap); jacint@72: jacint@72: preflow_push_test.run(); jacint@72: jacint@72: std::cout << "Maximum flow value is: " << preflow_push_test.maxflow() << "."< flow=preflow_push_test.allflow(); jacint@78: for (EachEdgeIt e=flow_test.template first(); e.valid(); ++e) { jacint@78: std::cout <<"Flow on Edge " << flow_test.tail(e) <<"-" << flow_test.head(e)<< " is " < mincut=preflow_push_test.mincut(); jacint@72: jacint@78: for (EachNodeIt v=flow_test.template first(); v.valid(); ++v) { jacint@78: if (mincut.get(v)) std::cout < max_flow_test(flow_test, s, t, cap); jacint@72: jacint@72: max_flow_test.run(); jacint@72: jacint@72: std::cout << "Maximum flow value is: " << max_flow_test.maxflow() << "."<< std::endl; jacint@72: jacint@72: std::cout << "A minimum cut: " < mincut2=max_flow_test.mincut(); jacint@72: jacint@78: for (EachNodeIt v=flow_test.template first(); v.valid(); ++v) { jacint@78: if (mincut2.get(v)) std::cout < dijkstra_test(flow_test, root, cap); jacint@72: jacint@72: dijkstra_test.run(); jacint@72: jacint@78: for (EachNodeIt w=flow_test.first_Node(); w.valid(); ++w) { jacint@72: if (dijkstra_test.reach(w)) { jacint@72: std::cout <<"The distance of " << w << " is " << dijkstra_test.dist(w); jacint@72: if (dijkstra_test.pred(w).valid()) { jacint@78: std::cout <<", a shortest path from the root ends with Edge " << dijkstra_test.pred(w) <