5 #include <marci_list_graph.hh>
6 #include <marci_graph_traits.hh>
7 #include <marci_property_vector.hh>
8 #include <preflow_push_hl.hh>
9 #include <preflow_push_max_flow.hh>
10 #include <reverse_bfs.hh>
12 using namespace marci;
15 int main (int, char*[])
17 typedef graph_traits<list_graph>::node_iterator node_iterator;
18 typedef graph_traits<list_graph>::edge_iterator edge_iterator;
19 typedef graph_traits<list_graph>::each_node_iterator each_node_iterator;
20 typedef graph_traits<list_graph>::each_edge_iterator each_edge_iterator;
21 typedef graph_traits<list_graph>::out_edge_iterator out_edge_iterator;
22 typedef graph_traits<list_graph>::in_edge_iterator in_edge_iterator;
23 typedef graph_traits<list_graph>::sym_edge_iterator sym_edge_iterator;
27 //Ahuja könyv példája, maxflowvalue=13
28 node_iterator s=flow_test.add_node();
29 node_iterator v1=flow_test.add_node();
30 node_iterator v2=flow_test.add_node();
31 node_iterator v3=flow_test.add_node();
32 node_iterator v4=flow_test.add_node();
33 node_iterator v5=flow_test.add_node();
34 node_iterator t=flow_test.add_node();
36 node_property_vector<list_graph, std::string> node_name(flow_test);
37 node_name.put(s, "s");
38 node_name.put(v1, "v1");
39 node_name.put(v2, "v2");
40 node_name.put(v3, "v3");
41 node_name.put(v4, "v4");
42 node_name.put(v5, "v5");
43 node_name.put(t, "t");
45 edge_iterator s_v1=flow_test.add_edge(s, v1);
46 edge_iterator s_v2=flow_test.add_edge(s, v2);
47 edge_iterator s_v3=flow_test.add_edge(s, v3);
49 edge_iterator v2_v4=flow_test.add_edge(v2, v4);
50 edge_iterator v2_v5=flow_test.add_edge(v2, v5);
52 edge_iterator v3_v5=flow_test.add_edge(v3, v5);
54 edge_iterator v4_t=flow_test.add_edge(v4, t);
55 edge_iterator v5_t=flow_test.add_edge(v5, t);
57 edge_property_vector<list_graph, int> cap(flow_test);
69 //Marci példája, maxflowvalue=23
70 /* node_iterator s=flow_test.add_node();
71 node_iterator v1=flow_test.add_node();
72 node_iterator v2=flow_test.add_node();
73 node_iterator v3=flow_test.add_node();
74 node_iterator v4=flow_test.add_node();
75 node_iterator t=flow_test.add_node();
76 node_iterator w=flow_test.add_node();
79 node_property_vector<list_graph, std::string> node_name(flow_test);
80 node_name.put(s, "s");
81 node_name.put(v1, "v1");
82 node_name.put(v2, "v2");
83 node_name.put(v3, "v3");
84 node_name.put(v4, "v4");
85 node_name.put(t, "t");
86 node_name.put(w, "w");
88 edge_iterator s_v1=flow_test.add_edge(s, v1);
89 edge_iterator s_v2=flow_test.add_edge(s, v2);
90 edge_iterator v1_v2=flow_test.add_edge(v1, v2);
91 edge_iterator v2_v1=flow_test.add_edge(v2, v1);
92 edge_iterator v1_v3=flow_test.add_edge(v1, v3);
93 edge_iterator v3_v2=flow_test.add_edge(v3, v2);
94 edge_iterator v2_v4=flow_test.add_edge(v2, v4);
95 edge_iterator v4_v3=flow_test.add_edge(v4, v3);
96 edge_iterator v3_t=flow_test.add_edge(v3, t);
97 edge_iterator v4_t=flow_test.add_edge(v4, t);
98 edge_iterator v3_v3=flow_test.add_edge(v3, v3);
99 edge_iterator s_w=flow_test.add_edge(s, w);
103 edge_property_vector<list_graph, int> cap(flow_test);
119 //pelda 3, maxflowvalue=4
120 /* node_iterator s=flow_test.add_node();
121 node_iterator v1=flow_test.add_node();
122 node_iterator v2=flow_test.add_node();
123 node_iterator t=flow_test.add_node();
124 node_iterator w=flow_test.add_node();
126 node_property_vector<list_graph, std::string> node_name(flow_test);
127 node_name.put(s, "s");
128 node_name.put(v1, "v1");
129 node_name.put(v2, "v2");
130 node_name.put(t, "t");
131 node_name.put(w, "w");
133 edge_iterator s_v1=flow_test.add_edge(s, v1);
134 edge_iterator v1_v2=flow_test.add_edge(v1, v2);
135 edge_iterator v2_t=flow_test.add_edge(v2, t);
136 edge_iterator v1_v1=flow_test.add_edge(v1, v1);
137 edge_iterator s_w=flow_test.add_edge(s, w);
140 edge_property_vector<list_graph, int> cap(flow_test);
152 std::cout << "Testing reverse_bfs..." << std::endl;
154 reverse_bfs<list_graph> bfs_test(flow_test, t);
158 for (each_node_iterator w=flow_test.first_node(); w.is_valid(); ++w) {
159 std::cout <<"The distance of " << w << " is " << bfs_test.dist(w) <<std::endl;
166 std::cout << "Testing preflow_push_hl..." << std::endl;
168 preflow_push_hl<list_graph, int> preflow_push_test(flow_test, s, t, cap);
170 preflow_push_test.run();
172 std::cout << "Maximum flow value is: " << preflow_push_test.maxflow() << "."<<std::endl;
174 std::cout<< "The flow on edge s-v1 is "<< preflow_push_test.flowonedge(s_v1) << "."<<std::endl;
176 edge_property_vector<list_graph, int> flow=preflow_push_test.allflow();
177 for (each_edge_iterator e=flow_test.first_edge(); e.is_valid(); ++e) {
178 std::cout <<"Flow on edge " << flow_test.tail(e) <<"-" << flow_test.head(e)<< " is " <<flow.get(e) <<std::endl;
181 std::cout << "A minimum cut: " <<std::endl;
182 node_property_vector<list_graph, bool> mincut=preflow_push_test.mincut();
184 for (each_node_iterator v=flow_test.first_node(); v.is_valid(); ++v) {
185 if (mincut.get(v)) std::cout <<node_name.get(v)<< " ";
188 std::cout<<"\n\n"<<std::endl;
193 std::cout << "Testing preflow_push_max_flow..." << std::endl;
195 preflow_push_max_flow<list_graph, int> max_flow_test(flow_test, s, t, cap);
199 std::cout << "Maximum flow value is: " << max_flow_test.maxflow() << "."<< std::endl;
201 std::cout << "A minimum cut: " <<std::endl;
202 node_property_vector<list_graph, bool> mincut2=max_flow_test.mincut();
204 for (each_node_iterator v=flow_test.first_node(); v.is_valid(); ++v) {
205 if (mincut2.get(v)) std::cout <<node_name.get(v)<< " ";
208 std::cout << std::endl;