Kijavitottam a preflow_push algoritmust az uj koncept szerint.
5 #include "list_graph.hh"
6 #include "marci_graph_traits.hh"
7 //#include "marci_property_vector.hh"
8 #include "preflow_push.hh"
10 using namespace marci;
13 int main (int, char*[])
17 typedef ListGraph::NodeIt NodeIt;
18 typedef ListGraph::EdgeIt EdgeIt;
20 typedef ListGraph::EachNodeIt EachNodeIt;
21 typedef ListGraph::EachEdgeIt EachEdgeIt;
22 typedef ListGraph::OutEdgeIt OutEdgeIt;
23 typedef ListGraph::InEdgeIt InEdgeIt;
24 typedef ListGraph::SymEdgeIt SymEdgeIt;
30 NodeIt s=flowG.addNode();
31 NodeIt v1=flowG.addNode();
32 NodeIt v2=flowG.addNode();
33 NodeIt v3=flowG.addNode();
34 NodeIt v4=flowG.addNode();
35 NodeIt t=flowG.addNode();
38 EdgeIt s_v1=flowG.addEdge(s, v1);
39 EdgeIt s_v2=flowG.addEdge(s, v2);
40 EdgeIt v1_v2=flowG.addEdge(v1, v2);
41 EdgeIt v2_v1=flowG.addEdge(v2, v1);
42 EdgeIt v1_v3=flowG.addEdge(v1, v3);
43 EdgeIt v3_v2=flowG.addEdge(v3, v2);
44 EdgeIt v2_v4=flowG.addEdge(v2, v4);
45 EdgeIt v4_v3=flowG.addEdge(v4, v3);
46 EdgeIt v3_t=flowG.addEdge(v3, t);
47 EdgeIt v4_t=flowG.addEdge(v4, t);
49 ListGraph::EdgeMap<int> cap(flowG);
70 node_iterator s=flow_test.add_node();
71 NodeIt v2=flow_test.add_node();
72 NodeIt v3=flow_test.add_node();
73 NodeIt v4=flow_test.add_node();
74 NodeIt v5=flow_test.add_node();
75 NodeIt t=flow_test.add_node();
77 node_property_vector<list_graph, std::string> node_name(flow_test);
78 node_name.put(s, "s");
79 node_name.put(v2, "v2");
80 node_name.put(v3, "v3");
81 node_name.put(v4, "v4");
82 node_name.put(v5, "v5");
83 node_name.put(t, "t");
86 edge_iterator s_v2=flow_test.add_edge(s, v2);
87 edge_iterator s_v3=flow_test.add_edge(s, v3);
89 edge_iterator v2_v4=flow_test.add_edge(v2, v4);
90 edge_iterator v2_v5=flow_test.add_edge(v2, v5);
92 edge_iterator v3_v5=flow_test.add_edge(v3, v5);
94 edge_iterator v4_t=flow_test.add_edge(v4, t);
95 edge_iterator v5_t=flow_test.add_edge(v5, t);
98 edge_iterator v2_s=flow_test.add_edge(v2, s);
100 edge_property_vector<list_graph, int> cap(flow_test);
113 //edge_iterator t_s=flow_test.add_edge(t, s);
121 NodeIt s=flow_test.add_node();
122 NodeIt v1=flow_test.add_node();
123 NodeIt v2=flow_test.add_node();
124 NodeIt t=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");
132 edge_iterator s_v1=flow_test.add_edge(s, v1);
133 edge_iterator v1_v2=flow_test.add_edge(v1, v2);
134 edge_iterator v2_t=flow_test.add_edge(v2, t);
136 edge_property_vector<list_graph, int> cap(flow_test);
143 std::cout << "preflow-push algorithm test..." << std::endl;
146 std::cout << "on directed graph graph" << std::endl; //<< flow_test;
147 std::cout << "names and capacity values" << std::endl;
148 for(EachNodeIt i=flow_test.first_node(); i.valid(); ++i) {
149 std::cout << node_name.get(i) << ": ";
150 std::cout << "out edges: ";
151 for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j)
152 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
153 std::cout << "in edges: ";
154 for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j)
155 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
156 std::cout << std::endl;
160 //for(each_NodeIt i=flow_test.first_node(); i.valid(); ++i) {
161 // std::cout << i << " ";
164 preflow_push<ListGraph, int> preflow_push_test(flowG, s, t, cap);
165 cout << preflow_push_test.run()<<endl;
168 //cout << preflow_push_test.run()<<endl;