marci@915
|
1 |
#include <iostream>
|
marci@1009
|
2 |
#include <fstream>
|
marci@915
|
3 |
|
alpar@921
|
4 |
#include <lemon/list_graph.h>
|
alpar@921
|
5 |
#include <lemon/smart_graph.h>
|
marci@1009
|
6 |
#include <lemon/dimacs.h>
|
marci@1013
|
7 |
#include <lemon/full_graph.h>
|
marci@915
|
8 |
#include <merge_node_graph_wrapper.h>
|
marci@915
|
9 |
|
marci@1008
|
10 |
#include<lemon/concept_check.h>
|
marci@1008
|
11 |
#include<lemon/concept/graph.h>
|
marci@1008
|
12 |
|
marci@915
|
13 |
using std::cout;
|
marci@915
|
14 |
using std::endl;
|
marci@915
|
15 |
|
alpar@921
|
16 |
using namespace lemon;
|
marci@1008
|
17 |
using namespace lemon::concept;
|
marci@915
|
18 |
|
marci@1007
|
19 |
class Graph3 : ListGraph {
|
marci@1007
|
20 |
public:
|
marci@1007
|
21 |
class Node : public ListGraph::Node { };
|
marci@1007
|
22 |
class Edge { };
|
marci@1007
|
23 |
};
|
marci@1007
|
24 |
|
marci@1013
|
25 |
template <typename Graph>
|
marci@1013
|
26 |
void printGraph(const Graph& g) {
|
marci@1009
|
27 |
cout << " nodes:" << endl;
|
marci@1013
|
28 |
for (typename Graph::NodeIt n(g); n!=INVALID; ++n) {
|
marci@1009
|
29 |
cout << " " << g.id(n) << endl;
|
marci@1009
|
30 |
}
|
marci@1009
|
31 |
cout << " edges:" << endl;
|
marci@1013
|
32 |
for (typename Graph::EdgeIt n(g); n!=INVALID; ++n) {
|
marci@1009
|
33 |
cout << " " << g.id(n) << ": "
|
marci@1009
|
34 |
<< g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl;
|
marci@1013
|
35 |
}
|
marci@1013
|
36 |
}
|
marci@1013
|
37 |
|
marci@1013
|
38 |
int main() {
|
marci@1013
|
39 |
{
|
marci@1013
|
40 |
cout << "FIRST TEST" << endl;
|
marci@1013
|
41 |
typedef SmartGraph Graph1;
|
marci@1013
|
42 |
typedef ListGraph Graph2;
|
marci@1013
|
43 |
|
marci@1013
|
44 |
{
|
marci@1013
|
45 |
checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();
|
marci@1013
|
46 |
MergeEdgeGraphWrapper<Graph1, Graph2>::printNode();
|
marci@1013
|
47 |
MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge();
|
marci@1013
|
48 |
checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >();
|
marci@1013
|
49 |
MergeEdgeGraphWrapper<Graph1, Graph1>::printNode();
|
marci@1013
|
50 |
MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge();
|
marci@1016
|
51 |
typedef ResGraphWrapper<Graph1, int,
|
marci@1016
|
52 |
ConstMap<Graph1, int>, ConstMap<Graph1, int> > Graph4;
|
marci@1016
|
53 |
checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph4> >();
|
marci@1016
|
54 |
MergeEdgeGraphWrapper<Graph1, Graph4>::printNode();
|
marci@1016
|
55 |
MergeEdgeGraphWrapper<Graph1, Graph4>::printEdge();
|
marci@1016
|
56 |
checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph4, Graph1> >();
|
marci@1016
|
57 |
MergeEdgeGraphWrapper<Graph4, Graph1>::printNode();
|
marci@1016
|
58 |
MergeEdgeGraphWrapper<Graph4, Graph1>::printEdge();
|
marci@1013
|
59 |
}
|
marci@1013
|
60 |
|
marci@1013
|
61 |
Graph1 g1;
|
marci@1013
|
62 |
Graph2 g2;
|
marci@1013
|
63 |
typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
|
marci@1013
|
64 |
GW gw(g1, g2);
|
marci@1013
|
65 |
|
marci@1013
|
66 |
std::ifstream f1("graph1.dim");
|
marci@1013
|
67 |
std::ifstream f2("graph2.dim");
|
marci@1013
|
68 |
readDimacs(f1, g1);
|
marci@1013
|
69 |
readDimacs(f2, g2);
|
marci@1013
|
70 |
|
marci@1013
|
71 |
cout << "1st graph" << endl;
|
marci@1013
|
72 |
printGraph(g1);
|
marci@1013
|
73 |
|
marci@1013
|
74 |
cout << "2nd graph" << endl;
|
marci@1013
|
75 |
printGraph(g2);
|
marci@1013
|
76 |
|
marci@1013
|
77 |
cout << "merged graph" << endl;
|
marci@1013
|
78 |
printGraph(gw);
|
marci@1013
|
79 |
|
marci@915
|
80 |
}
|
marci@917
|
81 |
|
marci@1013
|
82 |
|
marci@1013
|
83 |
{
|
marci@1013
|
84 |
cout << "SECOND TEST" << endl;
|
marci@1013
|
85 |
typedef SmartGraph Graph1;
|
marci@1013
|
86 |
{
|
marci@1013
|
87 |
checkConcept<StaticGraph, Graph1>();
|
marci@1013
|
88 |
}
|
marci@1013
|
89 |
|
marci@1013
|
90 |
Graph1 g1;
|
marci@1013
|
91 |
|
marci@1013
|
92 |
FullGraph pre_g2(2);
|
marci@1013
|
93 |
ConstMap<FullGraph::Edge, bool> const_false_map(false);
|
marci@1013
|
94 |
typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> >
|
marci@1013
|
95 |
Graph2;
|
marci@1013
|
96 |
{
|
marci@1013
|
97 |
checkConcept<StaticGraph, Graph2>();
|
marci@1013
|
98 |
}
|
marci@1013
|
99 |
|
marci@1013
|
100 |
Graph2 g2(pre_g2, const_false_map);
|
marci@1013
|
101 |
|
marci@1013
|
102 |
typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
|
marci@1013
|
103 |
{
|
marci@1013
|
104 |
checkConcept<StaticGraph, GW>();
|
marci@1013
|
105 |
}
|
marci@1013
|
106 |
GW gw(g1, g2);
|
marci@1013
|
107 |
GW::Node sw;
|
marci@1013
|
108 |
GW::Node tw;
|
marci@1013
|
109 |
{
|
marci@1013
|
110 |
Graph2::NodeIt k(g2);
|
marci@1013
|
111 |
sw=GW::Node(INVALID, k, true);
|
marci@1013
|
112 |
++k;
|
marci@1013
|
113 |
tw=GW::Node(INVALID, k, true);
|
marci@1013
|
114 |
}
|
marci@1013
|
115 |
|
marci@1013
|
116 |
std::ifstream f1("graph2.dim");
|
marci@1013
|
117 |
readDimacs(f1, g1);
|
marci@1013
|
118 |
|
marci@1013
|
119 |
cout << "1st graph" << endl;
|
marci@1013
|
120 |
printGraph(g1);
|
marci@1013
|
121 |
|
marci@1013
|
122 |
cout << "2nd graph" << endl;
|
marci@1013
|
123 |
printGraph(g2);
|
marci@1013
|
124 |
|
marci@1013
|
125 |
cout << "merged graph" << endl;
|
marci@1013
|
126 |
printGraph(gw);
|
marci@1013
|
127 |
|
marci@1013
|
128 |
typedef ListGraph Graph3;
|
marci@1016
|
129 |
//typedef SmartGraph Graph3;
|
marci@1013
|
130 |
Graph3 g3;
|
marci@1013
|
131 |
GW::NodeMap<Graph3::Node> gwn(gw);
|
marci@1013
|
132 |
Graph3::NodeMap<GW::Node> g3n(g3);
|
marci@1013
|
133 |
for (GW::NodeIt n(gw); n!=INVALID; ++n) {
|
marci@1013
|
134 |
Graph3::Node m=g3.addNode();
|
marci@1013
|
135 |
gwn.set(n, m);
|
marci@1013
|
136 |
g3n.set(m, n);
|
marci@1013
|
137 |
}
|
marci@1013
|
138 |
|
marci@1013
|
139 |
typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW;
|
marci@1013
|
140 |
{
|
marci@1013
|
141 |
checkConcept<StaticGraph, GWW>();
|
marci@1013
|
142 |
}
|
marci@1013
|
143 |
|
marci@1013
|
144 |
GWW gww(gw, g3, gwn, g3n);
|
marci@1013
|
145 |
|
marci@1013
|
146 |
for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
|
marci@1013
|
147 |
g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]);
|
marci@1013
|
148 |
}
|
marci@1013
|
149 |
|
marci@1013
|
150 |
// for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
|
marci@1013
|
151 |
// gww.addEdge(sw, GW::Node(n,INVALID,false));
|
marci@1013
|
152 |
// }
|
marci@1013
|
153 |
|
marci@1013
|
154 |
cout << "new edges" << endl;
|
marci@1013
|
155 |
printGraph(g3);
|
marci@1013
|
156 |
|
marci@1013
|
157 |
cout << "new edges in the new graph" << endl;
|
marci@1013
|
158 |
printGraph(gww);
|
marci@1013
|
159 |
|
marci@1013
|
160 |
typedef AugmentingGraphWrapper<GW, GWW> GWWW;
|
marci@1013
|
161 |
{
|
marci@1013
|
162 |
checkConcept<StaticGraph, GWWW>();
|
marci@1013
|
163 |
}
|
marci@1013
|
164 |
GWWW gwww(gw, gww);
|
marci@1013
|
165 |
|
marci@1013
|
166 |
cout << "new edges merged into the original graph" << endl;
|
marci@1013
|
167 |
printGraph(gwww);
|
marci@1013
|
168 |
|
marci@917
|
169 |
}
|
marci@1007
|
170 |
|
marci@915
|
171 |
}
|