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