1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/jacint/edmonds.cc Fri Apr 30 06:46:39 2004 +0000
1.3 @@ -0,0 +1,220 @@
1.4 +#include <iostream>
1.5 +#include <vector>
1.6 +#include <string>
1.7 +
1.8 +#include <list_graph.h>
1.9 +#include <edmonds.h>
1.10 +
1.11 +using namespace hugo;
1.12 +
1.13 +int main (int, char*[])
1.14 +{
1.15 + typedef ListGraph::NodeIt NodeIt;
1.16 + typedef ListGraph::EdgeIt EdgeIt;
1.17 + typedef ListGraph::Node Node;
1.18 + typedef ListGraph::Edge Edge;
1.19 + typedef ListGraph::OutEdgeIt OutEdgeIt;
1.20 + typedef ListGraph::InEdgeIt InEdgeIt;
1.21 +
1.22 + ListGraph flow_test;
1.23 +
1.24 + /* //Ahuja könyv példája, maxflowvalue=13*/
1.25 + Node s=flow_test.addNode();
1.26 + Node v1=flow_test.addNode();
1.27 + Node v2=flow_test.addNode();
1.28 + Node v3=flow_test.addNode();
1.29 + Node v4=flow_test.addNode();
1.30 + Node v5=flow_test.addNode();
1.31 + Node t=flow_test.addNode();
1.32 +
1.33 + ListGraph::NodeMap<std::string> Node_name(flow_test);
1.34 + Node_name.set(s, "s");
1.35 + Node_name.set(v1, "v1");
1.36 + Node_name.set(v2, "v2");
1.37 + Node_name.set(v3, "v3");
1.38 + Node_name.set(v4, "v4");
1.39 + Node_name.set(v5, "v5");
1.40 + Node_name.set(t, "t");
1.41 +
1.42 + Edge s_v1=flow_test.addEdge(s, v1);
1.43 + Edge s_v2=flow_test.addEdge(s, v2);
1.44 + Edge s_v3=flow_test.addEdge(s, v3);
1.45 + Edge v2_v4=flow_test.addEdge(v2, v4);
1.46 + Edge v2_v5=flow_test.addEdge(v2, v5);
1.47 + Edge v3_v5=flow_test.addEdge(v3, v5);
1.48 + Edge v4_t=flow_test.addEdge(v4, t);
1.49 + Edge v5_t=flow_test.addEdge(v5, t);
1.50 + Edge v2_s=flow_test.addEdge(v2, s);
1.51 +
1.52 + ListGraph::EdgeMap<int> cap(flow_test);
1.53 + cap.set(s_v1, 0);
1.54 + cap.set(s_v2, 10);
1.55 + cap.set(s_v3, 10);
1.56 + cap.set(v2_v4, 5);
1.57 + cap.set(v2_v5, 8);
1.58 + cap.set(v3_v5, 5);
1.59 + cap.set(v4_t, 8);
1.60 + cap.set(v5_t, 8);
1.61 + cap.set(v2_s, 0);
1.62 +
1.63 +
1.64 + Edmonds<ListGraph> edmonds(flow_test);
1.65 + std::vector<Edge> matching(0);
1.66 + std::cout<< edmonds.run(matching);
1.67 +
1.68 +
1.69 + /* //Marci példája, maxflowvalue=23
1.70 + Node s=flow_test.addNode();
1.71 + Node v1=flow_test.addNode();
1.72 + Node v2=flow_test.addNode();
1.73 + Node v3=flow_test.addNode();
1.74 + Node v4=flow_test.addNode();
1.75 + Node t=flow_test.addNode();
1.76 + Node z=flow_test.addNode();
1.77 +
1.78 +
1.79 + ListGraph::NodeMap<std::string> Node_name(flow_test);
1.80 + Node_name.set(s, "s");
1.81 + Node_name.set(v1, "v1");
1.82 + Node_name.set(v2, "v2");
1.83 + Node_name.set(v3, "v3");
1.84 + Node_name.set(v4, "v4");
1.85 + Node_name.set(t, "t");
1.86 + Node_name.set(z, "z");
1.87 +
1.88 + Edge s_v1=flow_test.addEdge(s, v1);
1.89 + Edge s_v2=flow_test.addEdge(s, v2);
1.90 + Edge v1_v2=flow_test.addEdge(v1, v2);
1.91 + Edge v2_v1=flow_test.addEdge(v2, v1);
1.92 + Edge v1_v3=flow_test.addEdge(v1, v3);
1.93 + Edge v3_v2=flow_test.addEdge(v3, v2);
1.94 + Edge v2_v4=flow_test.addEdge(v2, v4);
1.95 + Edge v4_v3=flow_test.addEdge(v4, v3);
1.96 + Edge v3_t=flow_test.addEdge(v3, t);
1.97 + Edge v4_t=flow_test.addEdge(v4, t);
1.98 + Edge v3_v3=flow_test.addEdge(v3, v3);
1.99 + Edge s_z=flow_test.addEdge(s, z);
1.100 + // Edge v2_s=flow_test.addEdge(v2, s);
1.101 +
1.102 +
1.103 +
1.104 + ListGraph::EdgeMap<int> cap(flow_test);
1.105 + cap.set(s_v1, 16);
1.106 + cap.set(s_v2, 13);
1.107 + cap.set(v1_v2, 10);
1.108 + cap.set(v2_v1, 4);
1.109 + cap.set(v1_v3, 12);
1.110 + cap.set(v3_v2, 9);
1.111 + cap.set(v2_v4, 14);
1.112 + cap.set(v4_v3, 7);
1.113 + cap.set(v3_t, 20);
1.114 + cap.set(v4_t, 4);
1.115 + cap.set(v3_v3, 4);
1.116 + cap.set(s_z, 4);
1.117 + // cap.set(v2_s, 0);
1.118 +
1.119 + */
1.120 +
1.121 + //pelda 3, maxflowvalue=4
1.122 + /* Node s=flow_test.addNode();
1.123 + Node v1=flow_test.addNode();
1.124 + Node v2=flow_test.addNode();
1.125 + Node t=flow_test.addNode();
1.126 + Node w=flow_test.addNode();
1.127 +
1.128 + NodeMap<ListGraph, std::string> Node_name(flow_test);
1.129 + Node_name.set(s, "s");
1.130 + Node_name.set(v1, "v1");
1.131 + Node_name.set(v2, "v2");
1.132 + Node_name.set(t, "t");
1.133 + Node_name.set(w, "w");
1.134 +
1.135 + Edge s_v1=flow_test.addEdge(s, v1);
1.136 + Edge v1_v2=flow_test.addEdge(v1, v2);
1.137 + Edge v2_t=flow_test.addEdge(v2, t);
1.138 + Edge v1_v1=flow_test.addEdge(v1, v1);
1.139 + Edge s_w=flow_test.addEdge(s, w);
1.140 +
1.141 +
1.142 + EdgeMap<ListGraph, int> cap(flow_test);
1.143 +
1.144 + cap.set(s_v1, 16);
1.145 + cap.set(v1_v2, 10);
1.146 + cap.set(v2_t, 4);
1.147 + cap.set(v1_v1, 3);
1.148 + cap.set(s_w, 5);
1.149 + */
1.150 +
1.151 +
1.152 +
1.153 + /*
1.154 + std::cout << "Testing reverse_bfs..." << std::endl;
1.155 +
1.156 + reverse_bfs<ListGraph> bfs_test(flow_test, t);
1.157 +
1.158 + bfs_test.run();
1.159 +
1.160 + for (EachNodeIt w=flow_test.first_Node(); w.valid(); ++w) {
1.161 + std::cout <<"The distance of " << w << " is " << bfs_test.dist(w) <<std::endl;
1.162 + }
1.163 +
1.164 + */
1.165 +
1.166 +
1.167 + /*
1.168 + std::cout << "Testing preflow_push_hl..." << std::endl;
1.169 +
1.170 + preflow_push_hl<ListGraph, int> preflow_push_test(flow_test, s, t, cap);
1.171 +
1.172 + preflow_push_test.run();
1.173 +
1.174 + std::cout << "Maximum flow value is: " << preflow_push_test.maxflow() << "."<<std::endl;
1.175 +
1.176 + std::cout<< "The flow on Edge s-v1 is "<< preflow_push_test.flowonEdge(s_v1) << "."<<std::endl;
1.177 +
1.178 + ListGraph::EdgeMap<int> flow=preflow_push_test.allflow();
1.179 + for (EachEdgeIt e=flow_test.template first<EachEdgeIt>(); e.valid(); ++e) {
1.180 + std::cout <<"Flow on Edge " << flow_test.tail(e) <<"-" << flow_test.head(e)<< " is " <<flow.get(e) <<std::endl;
1.181 + }
1.182 +
1.183 + std::cout << "A minimum cut: " <<std::endl;
1.184 + ListGraph::NodeMap<bool> mincut=preflow_push_test.mincut();
1.185 +
1.186 + for (EachNodeIt v=flow_test.template first<EachNodeIt>(); v.valid(); ++v) {
1.187 + if (mincut.get(v)) std::cout <<Node_name.get(v)<< " ";
1.188 + }
1.189 +
1.190 + std::cout<<"\n\n"<<std::endl;
1.191 +
1.192 +
1.193 +
1.194 +
1.195 + std::cout << "Testing preflow_push_max_flow..." << std::endl;
1.196 +
1.197 + preflow_push_max_flow<ListGraph, int> max_flow_test(flow_test, s, t, cap);
1.198 +
1.199 + max_flow_test.run();
1.200 +
1.201 + std::cout << "Maximum flow value is: " << max_flow_test.maxflow() << "."<< std::endl;
1.202 +
1.203 + std::cout << "A minimum cut: " <<std::endl;
1.204 + ListGraph::NodeMap<bool> mincut2=max_flow_test.mincut();
1.205 +
1.206 + for (EachNodeIt v=flow_test.template first<EachNodeIt>(); v.valid(); ++v) {
1.207 + if (mincut2.get(v)) std::cout <<Node_name.get(v)<< " ";
1.208 + }
1.209 +
1.210 + std::cout << std::endl <<std::endl;
1.211 + */
1.212 +
1.213 + return 0;
1.214 +}
1.215 +
1.216 +
1.217 +
1.218 +
1.219 +
1.220 +
1.221 +
1.222 +
1.223 +