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