19 public: |
20 public: |
20 class Node : public ListGraph::Node { }; |
21 class Node : public ListGraph::Node { }; |
21 class Edge { }; |
22 class Edge { }; |
22 }; |
23 }; |
23 |
24 |
24 int main() { |
25 template <typename Graph> |
25 typedef SmartGraph Graph1; |
26 void printGraph(const Graph& g) { |
26 typedef ListGraph Graph2; |
|
27 |
|
28 { |
|
29 checkConcept<StaticGraph, NewEdgeSetGraphWrapper<Graph1, Graph2> >(); |
|
30 } |
|
31 { |
|
32 checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >(); |
|
33 } |
|
34 |
|
35 Graph1 g; |
|
36 Graph2 h; |
|
37 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW; |
|
38 GW gw(g, h); |
|
39 |
|
40 std::ifstream f1("graph1.dim"); |
|
41 std::ifstream f2("graph2.dim"); |
|
42 readDimacs(f1, g); |
|
43 readDimacs(f2, h); |
|
44 { |
|
45 |
|
46 // Graph1::Node n1=g.addNode(); |
|
47 // Graph1::Node n2=g.addNode(); |
|
48 // Graph1::Node n3=g.addNode(); |
|
49 // Graph2::Node n4=h.addNode(); |
|
50 // Graph2::Node n5=h.addNode(); |
|
51 // Graph2::Node n6=h.addNode(); |
|
52 // Graph1::Edge e1=g.addEdge(n1, n2); |
|
53 // Graph1::Edge e2=g.addEdge(n1, n3); |
|
54 // Graph2::Edge e3=h.addEdge(n4, n5); |
|
55 // Graph2::Edge e4=h.addEdge(n4, n5); |
|
56 //GW::NodeIt n(gw) |
|
57 cout << "1st graph" << endl; |
|
58 cout << " nodes:" << endl; |
27 cout << " nodes:" << endl; |
59 for (Graph1::NodeIt n(g); n!=INVALID; ++n) { |
28 for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { |
60 cout << " " << g.id(n) << endl; |
29 cout << " " << g.id(n) << endl; |
61 } |
30 } |
62 cout << " edges:" << endl; |
31 cout << " edges:" << endl; |
63 for (Graph1::EdgeIt n(g); n!=INVALID; ++n) { |
32 for (typename Graph::EdgeIt n(g); n!=INVALID; ++n) { |
64 cout << " " << g.id(n) << ": " |
33 cout << " " << g.id(n) << ": " |
65 << g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl; |
34 << g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl; |
66 } |
35 } |
67 cout << "2nd graph" << endl; |
36 } |
68 cout << " nodes:" << endl; |
37 |
69 for (Graph2::NodeIt n(h); n!=INVALID; ++n) { |
38 int main() { |
70 cout << " " << h.id(n) << endl; |
39 { |
71 } |
40 cout << "FIRST TEST" << endl; |
72 cout << " edges:" << endl; |
41 typedef SmartGraph Graph1; |
73 for (Graph2::EdgeIt n(h); n!=INVALID; ++n) { |
42 typedef ListGraph Graph2; |
74 cout << " " << h.id(n) << ": " |
43 |
75 << h.id(h.source(n)) << "->" << h.id(h.target(n)) << endl; |
44 { |
76 } |
45 checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >(); |
77 cout << "merged graph" << endl; |
46 MergeEdgeGraphWrapper<Graph1, Graph2>::printNode(); |
78 cout << " nodes:" << endl; |
47 MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge(); |
79 for (GW::NodeIt n(gw); n!=INVALID; ++n) { |
48 checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >(); |
80 cout << " "<< gw.id(n) << endl; |
49 MergeEdgeGraphWrapper<Graph1, Graph1>::printNode(); |
81 } |
50 MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge(); |
82 cout << " edges:" << endl; |
51 } |
83 for (GW::EdgeIt n(gw); n!=INVALID; ++n) { |
52 |
84 cout << " " << gw.id(n) << ": " |
53 Graph1 g1; |
85 << gw.id(gw.source(n)) << "->" << gw.id(gw.target(n)) << endl; |
54 Graph2 g2; |
|
55 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW; |
|
56 GW gw(g1, g2); |
|
57 |
|
58 std::ifstream f1("graph1.dim"); |
|
59 std::ifstream f2("graph2.dim"); |
|
60 readDimacs(f1, g1); |
|
61 readDimacs(f2, g2); |
|
62 |
|
63 cout << "1st graph" << endl; |
|
64 printGraph(g1); |
|
65 |
|
66 cout << "2nd graph" << endl; |
|
67 printGraph(g2); |
|
68 |
|
69 cout << "merged graph" << endl; |
|
70 printGraph(gw); |
|
71 |
86 } |
72 } |
87 |
73 |
88 GW::NodeMap<int> nm(gw); |
74 |
89 int i=0; |
75 { |
90 for (GW::NodeIt n(gw); n!=INVALID; ++n) { |
76 cout << "SECOND TEST" << endl; |
91 ++i; |
77 typedef SmartGraph Graph1; |
92 nm.set(n, i); |
78 { |
93 } |
79 checkConcept<StaticGraph, Graph1>(); |
94 for (Graph1::NodeIt n(g); n!=INVALID; ++n) { |
80 } |
95 cout << nm[GW::Node(n,INVALID,false)] << endl; |
81 |
96 } |
82 Graph1 g1; |
97 for (Graph2::NodeIt n(h); n!=INVALID; ++n) { |
83 |
98 cout << nm[GW::Node(INVALID,n,true)] << endl; |
84 FullGraph pre_g2(2); |
|
85 ConstMap<FullGraph::Edge, bool> const_false_map(false); |
|
86 typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> > |
|
87 Graph2; |
|
88 { |
|
89 checkConcept<StaticGraph, Graph2>(); |
|
90 } |
|
91 |
|
92 Graph2 g2(pre_g2, const_false_map); |
|
93 |
|
94 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW; |
|
95 { |
|
96 checkConcept<StaticGraph, GW>(); |
|
97 } |
|
98 GW gw(g1, g2); |
|
99 GW::Node sw; |
|
100 GW::Node tw; |
|
101 { |
|
102 Graph2::NodeIt k(g2); |
|
103 sw=GW::Node(INVALID, k, true); |
|
104 ++k; |
|
105 tw=GW::Node(INVALID, k, true); |
|
106 } |
|
107 |
|
108 std::ifstream f1("graph2.dim"); |
|
109 readDimacs(f1, g1); |
|
110 |
|
111 cout << "1st graph" << endl; |
|
112 printGraph(g1); |
|
113 |
|
114 cout << "2nd graph" << endl; |
|
115 printGraph(g2); |
|
116 |
|
117 cout << "merged graph" << endl; |
|
118 printGraph(gw); |
|
119 |
|
120 typedef ListGraph Graph3; |
|
121 Graph3 g3; |
|
122 GW::NodeMap<Graph3::Node> gwn(gw); |
|
123 Graph3::NodeMap<GW::Node> g3n(g3); |
|
124 for (GW::NodeIt n(gw); n!=INVALID; ++n) { |
|
125 Graph3::Node m=g3.addNode(); |
|
126 gwn.set(n, m); |
|
127 g3n.set(m, n); |
|
128 } |
|
129 |
|
130 typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW; |
|
131 { |
|
132 checkConcept<StaticGraph, GWW>(); |
|
133 } |
|
134 |
|
135 GWW gww(gw, g3, gwn, g3n); |
|
136 |
|
137 for (Graph1::NodeIt n(g1); n!=INVALID; ++n) { |
|
138 g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]); |
|
139 } |
|
140 |
|
141 // for (Graph1::NodeIt n(g1); n!=INVALID; ++n) { |
|
142 // gww.addEdge(sw, GW::Node(n,INVALID,false)); |
|
143 // } |
|
144 |
|
145 cout << "new edges" << endl; |
|
146 printGraph(g3); |
|
147 |
|
148 cout << "new edges in the new graph" << endl; |
|
149 printGraph(gww); |
|
150 |
|
151 typedef AugmentingGraphWrapper<GW, GWW> GWWW; |
|
152 { |
|
153 checkConcept<StaticGraph, GWWW>(); |
|
154 } |
|
155 GWWW gwww(gw, gww); |
|
156 |
|
157 cout << "new edges merged into the original graph" << endl; |
|
158 printGraph(gwww); |
|
159 |
99 } |
160 } |
100 |
161 |
101 gw.printNode(); |
|
102 |
|
103 { |
|
104 // typedef SmartGraph Graph1; |
|
105 typedef ListGraph Graph1; |
|
106 typedef ListGraph Graph2; |
|
107 Graph1 g; |
|
108 Graph2 h; |
|
109 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW; |
|
110 GW gw(g, h); |
|
111 gw.printNode(); |
|
112 } |
|
113 { |
|
114 // typedef SmartGraph Graph1; |
|
115 typedef Graph3 Graph1; |
|
116 typedef ListGraph Graph2; |
|
117 Graph1 g; |
|
118 Graph2 h; |
|
119 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW; |
|
120 GW gw(g, h); |
|
121 gw.printNode(); |
|
122 } |
|
123 { |
|
124 // typedef SmartGraph Graph1; |
|
125 typedef ListGraph Graph1; |
|
126 typedef Graph3 Graph2; |
|
127 Graph1 g; |
|
128 Graph2 h; |
|
129 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW; |
|
130 GW gw(g, h); |
|
131 gw.printNode(); |
|
132 } |
|
133 } |
|
134 { |
|
135 Graph1 g; |
|
136 Graph2 h; |
|
137 typedef Graph1::Node Node1; |
|
138 typedef Graph2::Node Node2; |
|
139 typedef NewEdgeSetGraphWrapper<Graph1, Graph2> GW; |
|
140 Graph1::NodeMap<Graph2::Node> e_node(g); |
|
141 Graph2::NodeMap<Graph1::Node> n_node(h); |
|
142 GW gw(g, h, e_node, n_node); |
|
143 for (int i=0; i<4; ++i) { |
|
144 Node1 n=g.addNode(); |
|
145 e_node.set(n, INVALID); |
|
146 } |
|
147 for (int i=0; i<4; ++i) { |
|
148 Graph1::Node n1=g.addNode(); |
|
149 Graph2::Node n2=h.addNode(); |
|
150 e_node.set(n1, n2); |
|
151 n_node.set(n2, n1); |
|
152 } |
|
153 for (Graph2::NodeIt n(h); n!=INVALID; ++n) |
|
154 for (Graph2::NodeIt m(h); m!=INVALID; ++m) |
|
155 if ((h.id(n)+h.id(m))%3==0) h.addEdge(n, m); |
|
156 // Graph1::NodeIt n(g); |
|
157 // Node1 n1=n; |
|
158 // Node1 n2=++n; |
|
159 // Node1 n3=++n; |
|
160 // Node1 n4=n; |
|
161 // gw.addEdge(n1, n2); |
|
162 // gw.addEdge(n1, n2); |
|
163 // for (EdgeIt(e)) |
|
164 // Graph1::Node n1=g.addNode(); |
|
165 // Graph1::Node n2=g.addNode(); |
|
166 // Graph1::Node n3=g.addNode(); |
|
167 // Graph2::Node n4=h.addNode(); |
|
168 // Graph2::Node n5=h.addNode(); |
|
169 for (GW::EdgeIt e(gw); e!=INVALID; ++e) |
|
170 cout << gw.id(e) << endl; |
|
171 for (GW::NodeIt n(gw); n!=INVALID; ++n) { |
|
172 if (e_node[n]==INVALID) { |
|
173 cout<<gw.id(n)<<" INVALID"<<endl; |
|
174 } else { |
|
175 cout <<gw.id(n)<<" "<<h.id(e_node[n])<<" out_edges: "; |
|
176 // cout << &e_node << endl; |
|
177 //cout << &n_node << endl; |
|
178 for (GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) { |
|
179 cout<<gw.id(e)<<" "; |
|
180 } |
|
181 cout<< endl; |
|
182 } |
|
183 } |
|
184 } |
|
185 } |
162 } |