Completions.
4 #include <lemon/list_graph.h>
5 #include <lemon/smart_graph.h>
6 #include <lemon/dimacs.h>
7 #include <lemon/preflow.h>
8 #include <lemon/full_graph.h>
9 #include <merge_node_graph_wrapper.h>
11 #include<lemon/concept_check.h>
12 #include<lemon/concept/graph.h>
17 using namespace lemon;
18 using namespace lemon::concept;
20 class Graph3 : ListGraph {
22 class Node : public ListGraph::Node { };
26 template <typename Graph>
27 void printGraph(const Graph& g) {
28 cout << " nodes:" << endl;
29 for (typename Graph::NodeIt n(g); n!=INVALID; ++n) {
30 cout << " " << g.id(n) << ": out edges:" << endl;
31 for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e)
32 cout << " " << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
34 cout << " edges:" << endl;
35 for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) {
36 cout << " " << g.id(e) << ": "
37 << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
43 cout << "FIRST TEST" << endl;
44 //typedef SmartGraph Graph1;
45 typedef ListGraph Graph1;
46 typedef ListGraph Graph2;
47 typedef SmartGraph Graph3;
50 // checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();
51 // MergeEdgeGraphWrapper<Graph1, Graph2>::printNode();
52 // MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge();
53 // checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >();
54 // MergeEdgeGraphWrapper<Graph1, Graph1>::printNode();
55 // MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge();
56 // typedef ResGraphWrapper<Graph1, int,
57 // ConstMap<Graph1, int>, ConstMap<Graph1, int> > Graph4;
58 // checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph4> >();
59 // MergeEdgeGraphWrapper<Graph1, Graph4>::printNode();
60 // MergeEdgeGraphWrapper<Graph1, Graph4>::printEdge();
61 // checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph4, Graph1> >();
62 // MergeEdgeGraphWrapper<Graph4, Graph1>::printNode();
63 // MergeEdgeGraphWrapper<Graph4, Graph1>::printEdge();
68 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
72 Graph1::EdgeMap<int> cap1(g1);
73 Graph2::EdgeMap<int> cap2(g2);
75 std::ifstream f1("graph1.dim");
76 std::ifstream f2("graph2.dim");
80 // GW::NodeMap<int> ize(gw, 8);
81 // for (GW::NodeIt n(gw); n!=INVALID; ++n) ize.set(n, 9);
82 // GW::EdgeMap<int> mize(gw, 8);
83 // for (GW::EdgeIt n(gw); n!=INVALID; ++n) mize.set(n, 7);
85 // std::ifstream f1("flow-1.dim");
86 // std::ifstream f2("flow2.dim");
87 // readDimacs(f1, g1, cap1, s1, t1);
88 // readDimacs(f2, g2, cap2, s2, t2);
90 // GW::EdgeMap<int> cap(gw);
91 // for (GW::EdgeIt e(gw); e!=INVALID; ++e) {
92 // if (gw.forward(e)) cap.set(e, cap1[e]);
93 // if (gw.backward(e)) cap.set(e, cap2[e]);
97 // GW::EdgeMap<int> flow(gw, 0);
98 // Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false),
99 // GW::Node(t1, INVALID, false), cap, flow);
101 // std::cout << "s1->t1: " << preflow.flowValue() << std::endl;
104 // GW::EdgeMap<int> flow(gw, 0);
105 // Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true),
106 // GW::Node(INVALID, t2, true), cap, flow);
108 // std::cout << "s2->t2: " << preflow.flowValue() << std::endl;
111 // GW::EdgeMap<int> flow(gw, 0);
112 // Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false),
113 // GW::Node(INVALID, t2, true), cap, flow);
115 // std::cout << "s1->t2: " << preflow.flowValue() << std::endl;
118 // GW::EdgeMap<int> flow(gw, 0);
119 // Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true),
120 // GW::Node(s1, INVALID, false), cap, flow);
122 // std::cout << "s2->t1: " << preflow.flowValue() << std::endl;
124 cout << "1st graph" << endl;
127 cout << "2nd graph" << endl;
130 cout << "merged graph" << endl;
133 // for (GW::NodeIt n(gw); n!=INVALID; ++n)
134 // std::cout << ize[n] << std::endl;
135 // for (GW::EdgeIt n(gw); n!=INVALID; ++n)
136 // std::cout << mize[n] << std::endl;
138 typedef NewEdgeSetGraphWrapper2<GW, Graph3> GWW;
140 // checkConcept<StaticGraph, GWW>();
145 cout << "new edges graph" << endl;
156 cout << "new edges graph" << endl;
159 typedef AugmentingGraphWrapper<GW, GWW> GWWW;
161 // checkConcept<StaticGraph, GWWW>();
165 cout << "fully merged graph" << endl;
171 cout << "SECOND TEST" << endl;
172 typedef SmartGraph Graph1;
174 // checkConcept<StaticGraph, Graph1>();
180 ConstMap<FullGraph::Edge, bool> const_false_map(false);
181 typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> >
184 // checkConcept<StaticGraph, Graph2>();
187 Graph2 g2(pre_g2, const_false_map);
189 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
191 // checkConcept<StaticGraph, GW>();
197 Graph2::NodeIt k(g2);
198 sw=GW::Node(INVALID, k, true);
200 tw=GW::Node(INVALID, k, true);
203 std::ifstream f1("graph2.dim");
206 cout << "1st graph" << endl;
209 cout << "2nd graph" << endl;
212 cout << "merged graph" << endl;
215 typedef ListGraph Graph3;
216 //typedef SmartGraph Graph3;
218 GW::NodeMap<Graph3::Node> gwn(gw);
219 Graph3::NodeMap<GW::Node> g3n(g3);
220 for (GW::NodeIt n(gw); n!=INVALID; ++n) {
221 Graph3::Node m=g3.addNode();
226 typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW;
228 // checkConcept<StaticGraph, GWW>();
231 GWW gww(gw, g3, gwn, g3n);
233 for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
234 g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]);
237 // for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
238 // gww.addEdge(sw, GW::Node(n,INVALID,false));
241 cout << "new edges" << endl;
244 cout << "new edges in the new graph" << endl;
247 typedef AugmentingGraphWrapper<GW, GWW> GWWW;
249 // checkConcept<StaticGraph, GWWW>();
253 cout << "new edges merged into the original graph" << endl;