5 #include <marci_list_graph.hh>
6 #include <marci_graph_traits.hh>
7 #include <marci_property_vector.hh>
8 #include <marci_bfs.hh>
9 #include <marci_max_flow.hh>
11 using namespace marci;
13 int main (int, char*[])
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;
24 std::vector<node_iterator> vector_of_node_iterators;
25 for(int i=0; i!=8; ++i) vector_of_node_iterators.push_back(G.add_node());
26 for(int i=0; i!=8; ++i)
27 for(int j=0; j!=8; ++j) {
28 if ((i<j)&&(i+j)%3) G.add_edge(vector_of_node_iterators[i], vector_of_node_iterators[j]);
31 std::cout << "We construct a directed graph on the node set {0,1,2,...,7}," <<std::endl << "i-->j is arc iff i<j and (i+j)%3." << std::endl;
32 std::cout << "number of nodes: " << number_of(G.first_node()) << std::endl;
34 for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) {
35 std::cout << "node " << G.id(i) << std::endl;
36 std::cout << " outdegree (out_edge_iterator): " << number_of(G.first_out_edge(i)) << " ";
37 for(out_edge_iterator j=G.first_out_edge(i); j.is_valid(); ++j) {
38 std::cout << "(" << G.id(G.tail(j)) << "--" << G.id(j) << "->" << G.id(G.head(j)) << ") ";
40 std::cout << std::endl;
43 for(out_edge_iterator j=G.first_out_edge(i); j.is_valid(); ++j) {
44 std::cout << G.a_node(j) << "->" << G.b_node(j) << " "; }
47 std::cout << " indegree: (in_edge_oterator) " << number_of(G.first_in_edge(i)) << " ";
48 for(in_edge_iterator j=G.first_in_edge(i); j.is_valid(); ++j) {
49 std::cout << j << " "; }
50 std::cout << std::endl;
53 for(in_edge_iterator j=G.first_in_edge(i); j.is_valid(); ++j) {
54 std::cout << G.a_node(j) << "->" << G.b_node(j) << " "; }
57 std::cout << " degree: (sym_edge_iterator) " << number_of(G.first_sym_edge(i)) << " ";
58 for(sym_edge_iterator j=G.first_sym_edge(i); j.is_valid(); ++j) {
59 std::cout << j << " "; }
63 for(sym_edge_iterator j=G.first_sym_edge(i); j.is_valid(); ++j) {
64 std::cout << G.a_node(j) << "->" << G.b_node(j) << " "; }
68 std::cout << "all edges: ";
69 for(each_edge_iterator i=G.first_edge(); i.is_valid(); ++i) {
70 std::cout << i << " ";
72 std::cout << std::endl;
74 std::cout << "node property array test" << std::endl;
75 node_property_vector<list_graph, int> my_property_vector(G);
78 my_property_vector.put(v, 42);
79 my_property_vector.put(++G.first_node(), 314);
80 my_property_vector.put(++++G.first_node(), 1956);
81 my_property_vector.put(vector_of_node_iterators[3], 1989);
82 my_property_vector.put(vector_of_node_iterators[4], 2003);
83 my_property_vector.put(vector_of_node_iterators[7], 1978);
84 std::cout << "some node property values..." << std::endl;
85 for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) {
86 std::cout << my_property_vector.get(i) << std::endl;
90 edge_property_vector<list_graph, int> my_edge_property(G);
91 for(each_edge_iterator i=G.first_edge(); i.is_valid(); ++i) {
92 my_edge_property.put(i, _i);
96 std::cout << "node and edge property values on the tails and heads of edges..." << std::endl;
97 for(each_edge_iterator j=G.first_edge(); j.is_valid(); ++j) {
98 std::cout << my_property_vector.get(G.tail(j)) << "--" << my_edge_property.get(j) << "-->" << my_property_vector.get(G.head(j)) << " ";
100 std::cout << std::endl;
102 //std::cout << "the same for inedges of the nodes..." << std::endl;
104 //for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) {
105 // for(in_edge_iterator j=G.first_in_edge(i); j.is_valid(); ++j) {
106 // std::cout << my_property_vector.get(G.tail(j)) << "-->" << my_property_vector.get(G.head(j)) << " ";
108 // std::cout << std::endl;
111 std::cout << "bfs from the first node" << std::endl;
112 bfs<list_graph> bfs_test(G, G.first_node());
114 std::cout << "reached: ";
115 for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) {
116 std::cout << bfs_test.reached.get(i) << " ";
118 std::cout<<std::endl;
119 std::cout << "dist: ";
120 for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) {
121 std::cout << bfs_test.dist.get(i) << " ";
123 std::cout<<std::endl;
126 std::cout << "augmenting path flow algorithm test..." << std::endl;
127 list_graph flow_test;
129 node_iterator s=flow_test.add_node();
130 node_iterator v1=flow_test.add_node();
131 node_iterator v2=flow_test.add_node();
132 node_iterator v3=flow_test.add_node();
133 node_iterator v4=flow_test.add_node();
134 node_iterator t=flow_test.add_node();
136 node_property_vector<list_graph, std::string> node_name(flow_test);
137 node_name.put(s, "s");
138 node_name.put(v1, "v1");
139 node_name.put(v2, "v2");
140 node_name.put(v3, "v3");
141 node_name.put(v4, "v4");
142 node_name.put(t, "t");
144 edge_iterator s_v1=flow_test.add_edge(s, v1);
145 edge_iterator s_v2=flow_test.add_edge(s, v2);
146 edge_iterator v1_v2=flow_test.add_edge(v1, v2);
147 edge_iterator v2_v1=flow_test.add_edge(v2, v1);
148 edge_iterator v1_v3=flow_test.add_edge(v1, v3);
149 edge_iterator v3_v2=flow_test.add_edge(v3, v2);
150 edge_iterator v2_v4=flow_test.add_edge(v2, v4);
151 edge_iterator v4_v3=flow_test.add_edge(v4, v3);
152 edge_iterator v3_t=flow_test.add_edge(v3, t);
153 edge_iterator v4_t=flow_test.add_edge(v4, t);
155 edge_property_vector<list_graph, int> cap(flow_test);
168 std::cout << "on directed graph graph" << std::endl; //<< flow_test;
169 std::cout << "names and capacity values" << std::endl;
170 for(each_node_iterator i=flow_test.first_node(); i.is_valid(); ++i) {
171 std::cout << node_name.get(i) << ": ";
172 std::cout << "out edges: ";
173 for(out_edge_iterator j=flow_test.first_out_edge(i); j.is_valid(); ++j)
174 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
175 std::cout << "in edges: ";
176 for(in_edge_iterator j=flow_test.first_in_edge(i); j.is_valid(); ++j)
177 std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
178 std::cout << std::endl;
182 //for(each_node_iterator i=flow_test.first_node(); i.is_valid(); ++i) {
183 // std::cout << i << " ";
186 max_flow_type<list_graph, int> max_flow_test(flow_test, s, t, cap);