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