src/work/marci/merge_node_graph_wrapper_test.cc
author marci
Sat, 20 Nov 2004 14:23:27 +0000
changeset 1014 aae850a2394d
parent 1009 8cb323dbae93
child 1016 18d009b23e42
permissions -rw-r--r--
Modifications for hugo 0.2
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@1013
    51
    }
marci@1013
    52
  
marci@1013
    53
    Graph1 g1;
marci@1013
    54
    Graph2 g2;
marci@1013
    55
    typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
marci@1013
    56
    GW gw(g1, g2);
marci@1013
    57
marci@1013
    58
    std::ifstream f1("graph1.dim");
marci@1013
    59
    std::ifstream f2("graph2.dim");
marci@1013
    60
    readDimacs(f1, g1);
marci@1013
    61
    readDimacs(f2, g2);
marci@1013
    62
    
marci@1013
    63
    cout << "1st graph" << endl;
marci@1013
    64
    printGraph(g1);
marci@1013
    65
marci@1013
    66
    cout << "2nd graph" << endl;
marci@1013
    67
    printGraph(g2);
marci@1013
    68
marci@1013
    69
    cout << "merged graph" << endl;
marci@1013
    70
    printGraph(gw);
marci@1013
    71
marci@915
    72
  }
marci@917
    73
marci@1013
    74
marci@1013
    75
  {
marci@1013
    76
    cout << "SECOND TEST" << endl;
marci@1013
    77
    typedef SmartGraph Graph1;
marci@1013
    78
    {
marci@1013
    79
      checkConcept<StaticGraph, Graph1>();
marci@1013
    80
    }
marci@1013
    81
marci@1013
    82
    Graph1 g1;
marci@1013
    83
marci@1013
    84
    FullGraph pre_g2(2);
marci@1013
    85
    ConstMap<FullGraph::Edge, bool> const_false_map(false);
marci@1013
    86
    typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> >
marci@1013
    87
      Graph2;
marci@1013
    88
    {
marci@1013
    89
      checkConcept<StaticGraph, Graph2>();
marci@1013
    90
    }
marci@1013
    91
marci@1013
    92
    Graph2 g2(pre_g2, const_false_map);
marci@1013
    93
marci@1013
    94
    typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
marci@1013
    95
    {
marci@1013
    96
      checkConcept<StaticGraph, GW>();   
marci@1013
    97
    }
marci@1013
    98
    GW gw(g1, g2);
marci@1013
    99
    GW::Node sw;
marci@1013
   100
    GW::Node tw;
marci@1013
   101
    {
marci@1013
   102
      Graph2::NodeIt k(g2);
marci@1013
   103
      sw=GW::Node(INVALID, k, true);
marci@1013
   104
      ++k;
marci@1013
   105
      tw=GW::Node(INVALID, k, true);
marci@1013
   106
    }
marci@1013
   107
marci@1013
   108
    std::ifstream f1("graph2.dim");
marci@1013
   109
    readDimacs(f1, g1);
marci@1013
   110
marci@1013
   111
    cout << "1st graph" << endl;
marci@1013
   112
    printGraph(g1);
marci@1013
   113
marci@1013
   114
    cout << "2nd graph" << endl;
marci@1013
   115
    printGraph(g2);
marci@1013
   116
marci@1013
   117
    cout << "merged graph" << endl;
marci@1013
   118
    printGraph(gw);
marci@1013
   119
marci@1013
   120
    typedef ListGraph Graph3;
marci@1013
   121
    Graph3 g3;
marci@1013
   122
    GW::NodeMap<Graph3::Node> gwn(gw);
marci@1013
   123
    Graph3::NodeMap<GW::Node> g3n(g3);
marci@1013
   124
    for (GW::NodeIt n(gw); n!=INVALID; ++n) {
marci@1013
   125
      Graph3::Node m=g3.addNode();
marci@1013
   126
      gwn.set(n, m);
marci@1013
   127
      g3n.set(m, n);
marci@1013
   128
    }
marci@1013
   129
marci@1013
   130
    typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW;
marci@1013
   131
    {
marci@1013
   132
      checkConcept<StaticGraph, GWW>();   
marci@1013
   133
    }
marci@1013
   134
marci@1013
   135
    GWW gww(gw, g3, gwn, g3n);
marci@1013
   136
marci@1013
   137
    for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
marci@1013
   138
      g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]);
marci@1013
   139
    }
marci@1013
   140
marci@1013
   141
//     for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
marci@1013
   142
//       gww.addEdge(sw, GW::Node(n,INVALID,false));
marci@1013
   143
//     }
marci@1013
   144
marci@1013
   145
    cout << "new edges" << endl;
marci@1013
   146
    printGraph(g3);
marci@1013
   147
marci@1013
   148
    cout << "new edges in the new graph" << endl;
marci@1013
   149
    printGraph(gww);
marci@1013
   150
marci@1013
   151
    typedef AugmentingGraphWrapper<GW, GWW> GWWW;
marci@1013
   152
    {
marci@1013
   153
      checkConcept<StaticGraph, GWWW>();   
marci@1013
   154
    }
marci@1013
   155
    GWWW gwww(gw, gww);
marci@1013
   156
marci@1013
   157
    cout << "new edges merged into the original graph" << endl;
marci@1013
   158
    printGraph(gwww);
marci@1013
   159
marci@917
   160
  }
marci@1007
   161
marci@915
   162
}