|
1 #include <iostream> |
|
2 #include <vector> |
|
3 #include <string> |
|
4 |
|
5 #include "marci_list_graph.hh" |
|
6 #include "marci_graph_traits.hh" |
|
7 #include "marci_property_vector.hh" |
|
8 #include "preflow_push.hh" |
|
9 |
|
10 using namespace marci; |
|
11 |
|
12 |
|
13 int main (int, char*[]) |
|
14 { |
|
15 typedef graph_traits<list_graph>::node_iterator node_iterator; |
|
16 typedef graph_traits<list_graph>::edge_iterator edge_iterator; |
|
17 typedef graph_traits<list_graph>::each_node_iterator each_node_iterator; |
|
18 typedef graph_traits<list_graph>::each_edge_iterator each_edge_iterator; |
|
19 typedef graph_traits<list_graph>::out_edge_iterator out_edge_iterator; |
|
20 typedef graph_traits<list_graph>::in_edge_iterator in_edge_iterator; |
|
21 typedef graph_traits<list_graph>::sym_edge_iterator sym_edge_iterator; |
|
22 |
|
23 list_graph flow_test; |
|
24 |
|
25 |
|
26 //Ahuja könyv példája |
|
27 node_iterator s=flow_test.add_node(); |
|
28 node_iterator v2=flow_test.add_node(); |
|
29 node_iterator v3=flow_test.add_node(); |
|
30 node_iterator v4=flow_test.add_node(); |
|
31 node_iterator v5=flow_test.add_node(); |
|
32 node_iterator t=flow_test.add_node(); |
|
33 |
|
34 node_property_vector<list_graph, std::string> node_name(flow_test); |
|
35 node_name.put(s, "s"); |
|
36 node_name.put(v2, "v2"); |
|
37 node_name.put(v3, "v3"); |
|
38 node_name.put(v4, "v4"); |
|
39 node_name.put(v5, "v5"); |
|
40 node_name.put(t, "t"); |
|
41 |
|
42 |
|
43 edge_iterator s_v2=flow_test.add_edge(s, v2); |
|
44 edge_iterator s_v3=flow_test.add_edge(s, v3); |
|
45 |
|
46 edge_iterator v2_v4=flow_test.add_edge(v2, v4); |
|
47 edge_iterator v2_v5=flow_test.add_edge(v2, v5); |
|
48 |
|
49 edge_iterator v3_v5=flow_test.add_edge(v3, v5); |
|
50 |
|
51 edge_iterator v4_t=flow_test.add_edge(v4, t); |
|
52 edge_iterator v5_t=flow_test.add_edge(v5, t); |
|
53 |
|
54 //Kis modositas |
|
55 edge_iterator v2_s=flow_test.add_edge(v2, s); |
|
56 |
|
57 edge_property_vector<list_graph, int> cap(flow_test); |
|
58 cap.put(s_v2, 10); |
|
59 cap.put(s_v3, 10); |
|
60 cap.put(v2_v4, 5); |
|
61 cap.put(v2_v5, 8); |
|
62 cap.put(v3_v5, 5); |
|
63 cap.put(v4_t, 8); |
|
64 cap.put(v5_t, 8); |
|
65 |
|
66 //Kis modositas |
|
67 cap.put(v2_s, 100); |
|
68 |
|
69 //Kis modositas |
|
70 //edge_iterator t_s=flow_test.add_edge(t, s); |
|
71 //cap.put(t_s, 20); |
|
72 |
|
73 |
|
74 /* |
|
75 //Marci példája |
|
76 node_iterator s=flow_test.add_node(); |
|
77 node_iterator v1=flow_test.add_node(); |
|
78 node_iterator v2=flow_test.add_node(); |
|
79 node_iterator v3=flow_test.add_node(); |
|
80 node_iterator v4=flow_test.add_node(); |
|
81 node_iterator t=flow_test.add_node(); |
|
82 |
|
83 node_property_vector<list_graph, std::string> node_name(flow_test); |
|
84 node_name.put(s, "s"); |
|
85 node_name.put(v1, "v1"); |
|
86 node_name.put(v2, "v2"); |
|
87 node_name.put(v3, "v3"); |
|
88 node_name.put(v4, "v4"); |
|
89 node_name.put(t, "t"); |
|
90 |
|
91 edge_iterator s_v1=flow_test.add_edge(s, v1); |
|
92 edge_iterator s_v2=flow_test.add_edge(s, v2); |
|
93 edge_iterator v1_v2=flow_test.add_edge(v1, v2); |
|
94 edge_iterator v2_v1=flow_test.add_edge(v2, v1); |
|
95 edge_iterator v1_v3=flow_test.add_edge(v1, v3); |
|
96 edge_iterator v3_v2=flow_test.add_edge(v3, v2); |
|
97 edge_iterator v2_v4=flow_test.add_edge(v2, v4); |
|
98 edge_iterator v4_v3=flow_test.add_edge(v4, v3); |
|
99 edge_iterator v3_t=flow_test.add_edge(v3, t); |
|
100 edge_iterator v4_t=flow_test.add_edge(v4, t); |
|
101 |
|
102 edge_property_vector<list_graph, int> cap(flow_test); |
|
103 cap.put(s_v1, 16); |
|
104 cap.put(s_v2, 13); |
|
105 cap.put(v1_v2, 10); |
|
106 cap.put(v2_v1, 4); |
|
107 cap.put(v1_v3, 12); |
|
108 cap.put(v3_v2, 9); |
|
109 cap.put(v2_v4, 14); |
|
110 cap.put(v4_v3, 7); |
|
111 cap.put(v3_t, 20); |
|
112 cap.put(v4_t, 4); |
|
113 */ |
|
114 /*Egyszerű példa |
|
115 node_iterator s=flow_test.add_node(); |
|
116 node_iterator v1=flow_test.add_node(); |
|
117 node_iterator v2=flow_test.add_node(); |
|
118 node_iterator t=flow_test.add_node(); |
|
119 |
|
120 node_property_vector<list_graph, std::string> node_name(flow_test); |
|
121 node_name.put(s, "s"); |
|
122 node_name.put(v1, "v1"); |
|
123 node_name.put(v2, "v2"); |
|
124 node_name.put(t, "t"); |
|
125 |
|
126 edge_iterator s_v1=flow_test.add_edge(s, v1); |
|
127 edge_iterator v1_v2=flow_test.add_edge(v1, v2); |
|
128 edge_iterator v2_t=flow_test.add_edge(v2, t); |
|
129 |
|
130 edge_property_vector<list_graph, int> cap(flow_test); |
|
131 |
|
132 cap.put(s_v1, 16); |
|
133 cap.put(v1_v2, 10); |
|
134 cap.put(v2_t, 4); |
|
135 */ |
|
136 |
|
137 std::cout << "preflow-push algorithm test..." << std::endl; |
|
138 std::cout << "on directed graph graph" << std::endl; //<< flow_test; |
|
139 std::cout << "names and capacity values" << std::endl; |
|
140 for(each_node_iterator i=flow_test.first_node(); i.valid(); ++i) { |
|
141 std::cout << node_name.get(i) << ": "; |
|
142 std::cout << "out edges: "; |
|
143 for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) |
|
144 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; |
|
145 std::cout << "in edges: "; |
|
146 for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) |
|
147 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; |
|
148 std::cout << std::endl; |
|
149 } |
|
150 |
|
151 |
|
152 //for(each_node_iterator i=flow_test.first_node(); i.valid(); ++i) { |
|
153 // std::cout << i << " "; |
|
154 //} |
|
155 |
|
156 preflow_push<list_graph, int> preflow_push_test(flow_test, s, t, cap); |
|
157 cout << preflow_push_test.run()<<endl; |
|
158 |
|
159 //cap.put(v5_t, 9); |
|
160 //cout << preflow_push_test.run()<<endl; |
|
161 |
|
162 return 0; |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |