4 #include <lemon/list_graph.h>
5 #include <lemon/smart_graph.h>
6 #include <lemon/dimacs.h>
7 #include <merge_node_graph_wrapper.h>
9 #include<lemon/concept_check.h>
10 #include<lemon/concept/graph.h>
15 using namespace lemon;
16 using namespace lemon::concept;
18 class Graph3 : ListGraph {
20 class Node : public ListGraph::Node { };
25 typedef SmartGraph Graph1;
26 typedef ListGraph Graph2;
29 checkConcept<StaticGraph, NewEdgeSetGraphWrapper<Graph1, Graph2> >();
32 checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();
37 typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
40 std::ifstream f1("graph1.dim");
41 std::ifstream f2("graph2.dim");
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);
57 cout << "1st graph" << endl;
58 cout << " nodes:" << endl;
59 for (Graph1::NodeIt n(g); n!=INVALID; ++n) {
60 cout << " " << g.id(n) << endl;
62 cout << " edges:" << endl;
63 for (Graph1::EdgeIt n(g); n!=INVALID; ++n) {
64 cout << " " << g.id(n) << ": "
65 << g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl;
67 cout << "2nd graph" << endl;
68 cout << " nodes:" << endl;
69 for (Graph2::NodeIt n(h); n!=INVALID; ++n) {
70 cout << " " << h.id(n) << endl;
72 cout << " edges:" << endl;
73 for (Graph2::EdgeIt n(h); n!=INVALID; ++n) {
74 cout << " " << h.id(n) << ": "
75 << h.id(h.source(n)) << "->" << h.id(h.target(n)) << endl;
77 cout << "merged graph" << endl;
78 cout << " nodes:" << endl;
79 for (GW::NodeIt n(gw); n!=INVALID; ++n) {
80 cout << " "<< gw.id(n) << endl;
82 cout << " edges:" << endl;
83 for (GW::EdgeIt n(gw); n!=INVALID; ++n) {
84 cout << " " << gw.id(n) << ": "
85 << gw.id(gw.source(n)) << "->" << gw.id(gw.target(n)) << endl;
88 GW::NodeMap<int> nm(gw);
90 for (GW::NodeIt n(gw); n!=INVALID; ++n) {
94 for (Graph1::NodeIt n(g); n!=INVALID; ++n) {
95 cout << nm[GW::Node(n,INVALID,false)] << endl;
97 for (Graph2::NodeIt n(h); n!=INVALID; ++n) {
98 cout << nm[GW::Node(INVALID,n,true)] << endl;
104 // typedef SmartGraph Graph1;
105 typedef ListGraph Graph1;
106 typedef ListGraph Graph2;
109 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
114 // typedef SmartGraph Graph1;
115 typedef Graph3 Graph1;
116 typedef ListGraph Graph2;
119 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
124 // typedef SmartGraph Graph1;
125 typedef ListGraph Graph1;
126 typedef Graph3 Graph2;
129 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
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) {
145 e_node.set(n, INVALID);
147 for (int i=0; i<4; ++i) {
148 Graph1::Node n1=g.addNode();
149 Graph2::Node n2=h.addNode();
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);
161 // gw.addEdge(n1, n2);
162 // gw.addEdge(n1, n2);
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;
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) {