COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/merge_node_graph_wrapper_test.cc @ 1015:e3bb0e118bb4

Last change on this file since 1015:e3bb0e118bb4 was 1013:b3bdd856faf4, checked in by marci, 19 years ago

MergeGraphWrapper?

File size: 3.6 KB
Line 
1#include <iostream>
2#include <fstream>
3
4#include <lemon/list_graph.h>
5#include <lemon/smart_graph.h>
6#include <lemon/dimacs.h>
7#include <lemon/full_graph.h>
8#include <merge_node_graph_wrapper.h>
9
10#include<lemon/concept_check.h>
11#include<lemon/concept/graph.h>
12
13using std::cout;
14using std::endl;
15
16using namespace lemon;
17using namespace lemon::concept;
18
19class Graph3 : ListGraph {
20public:
21  class Node : public ListGraph::Node { };
22  class Edge { };
23};
24
25template <typename Graph>
26void printGraph(const Graph& g) {
27  cout << " nodes:" << endl;
28  for (typename Graph::NodeIt n(g); n!=INVALID; ++n) {
29    cout << "  " << g.id(n) << endl;
30  }
31  cout << " edges:" << endl;
32  for (typename Graph::EdgeIt n(g); n!=INVALID; ++n) {
33    cout << "  " << g.id(n) << ": "
34         << g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl;
35  } 
36}
37
38int main() {
39  {
40    cout << "FIRST TEST" << endl;
41    typedef SmartGraph Graph1;
42    typedef ListGraph Graph2;
43   
44    {
45      checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();   
46      MergeEdgeGraphWrapper<Graph1, Graph2>::printNode();
47      MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge();
48      checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >();   
49      MergeEdgeGraphWrapper<Graph1, Graph1>::printNode();
50      MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge();
51    }
52 
53    Graph1 g1;
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
72  }
73
74
75  {
76    cout << "SECOND TEST" << endl;
77    typedef SmartGraph Graph1;
78    {
79      checkConcept<StaticGraph, Graph1>();
80    }
81
82    Graph1 g1;
83
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
160  }
161
162}
Note: See TracBrowser for help on using the repository browser.