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