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