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