src/work/marci/merge_node_graph_wrapper_test.cc
author alpar
Tue, 04 Jan 2005 22:16:46 +0000
changeset 1050 bcc0766a7b86
parent 1016 18d009b23e42
permissions -rw-r--r--
Several new named parameters and documentation added to graphToEps().
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@1025
     7
#include <lemon/preflow.h>
marci@1013
     8
#include <lemon/full_graph.h>
marci@915
     9
#include <merge_node_graph_wrapper.h>
marci@915
    10
marci@1008
    11
#include<lemon/concept_check.h>
marci@1008
    12
#include<lemon/concept/graph.h>
marci@1008
    13
marci@915
    14
using std::cout;
marci@915
    15
using std::endl;
marci@915
    16
alpar@921
    17
using namespace lemon;
marci@1008
    18
using namespace lemon::concept;
marci@915
    19
marci@1007
    20
class Graph3 : ListGraph {
marci@1007
    21
public:
marci@1007
    22
  class Node : public ListGraph::Node { };
marci@1007
    23
  class Edge { };
marci@1007
    24
};
marci@1007
    25
marci@1013
    26
template <typename Graph>
marci@1013
    27
void printGraph(const Graph& g) {
marci@1009
    28
  cout << " nodes:" << endl;
marci@1013
    29
  for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { 
marci@1025
    30
    cout << "  " << g.id(n) << ": out edges:" << endl;
marci@1025
    31
    for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) 
marci@1025
    32
      cout << "   " << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
marci@1009
    33
  }
marci@1009
    34
  cout << " edges:" << endl;
marci@1025
    35
  for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { 
marci@1025
    36
    cout << "   " << g.id(e) << ": " 
marci@1025
    37
	 << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
marci@1013
    38
  }  
marci@1013
    39
}
marci@1013
    40
marci@1013
    41
int main() {
marci@1013
    42
  {
marci@1013
    43
    cout << "FIRST TEST" << endl;
marci@1025
    44
    //typedef SmartGraph Graph1;
marci@1025
    45
    typedef ListGraph Graph1;
marci@1013
    46
    typedef ListGraph Graph2;
marci@1025
    47
    typedef SmartGraph Graph3;
marci@1013
    48
    
marci@1025
    49
//     {
marci@1025
    50
//       checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();   
marci@1025
    51
//       MergeEdgeGraphWrapper<Graph1, Graph2>::printNode(); 
marci@1025
    52
//       MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge(); 
marci@1025
    53
//       checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >();   
marci@1025
    54
//       MergeEdgeGraphWrapper<Graph1, Graph1>::printNode(); 
marci@1025
    55
//       MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge(); 
marci@1025
    56
//       typedef ResGraphWrapper<Graph1, int, 
marci@1025
    57
// 	ConstMap<Graph1, int>, ConstMap<Graph1, int> > Graph4;
marci@1025
    58
//       checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph4> >();   
marci@1025
    59
//       MergeEdgeGraphWrapper<Graph1, Graph4>::printNode(); 
marci@1025
    60
//       MergeEdgeGraphWrapper<Graph1, Graph4>::printEdge();
marci@1025
    61
//       checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph4, Graph1> >();   
marci@1025
    62
//       MergeEdgeGraphWrapper<Graph4, Graph1>::printNode(); 
marci@1025
    63
//       MergeEdgeGraphWrapper<Graph4, Graph1>::printEdge();  
marci@1025
    64
//     }
marci@1013
    65
  
marci@1013
    66
    Graph1 g1;
marci@1013
    67
    Graph2 g2;
marci@1013
    68
    typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
marci@1013
    69
    GW gw(g1, g2);
marci@1025
    70
    Graph1::Node s1, t1;
marci@1025
    71
    Graph2::Node s2, t2;
marci@1025
    72
    Graph1::EdgeMap<int> cap1(g1);
marci@1025
    73
    Graph2::EdgeMap<int> cap2(g2);
marci@1013
    74
marci@1013
    75
    std::ifstream f1("graph1.dim");
marci@1013
    76
    std::ifstream f2("graph2.dim");
marci@1013
    77
    readDimacs(f1, g1);
marci@1013
    78
    readDimacs(f2, g2);
marci@1025
    79
marci@1025
    80
//     GW::NodeMap<int> ize(gw, 8);
marci@1025
    81
//     for (GW::NodeIt n(gw); n!=INVALID; ++n) ize.set(n, 9);
marci@1025
    82
//     GW::EdgeMap<int> mize(gw, 8);
marci@1025
    83
//     for (GW::EdgeIt n(gw); n!=INVALID; ++n) mize.set(n, 7);
marci@1025
    84
marci@1025
    85
//     std::ifstream f1("flow-1.dim");
marci@1025
    86
//     std::ifstream f2("flow2.dim");
marci@1025
    87
//     readDimacs(f1, g1, cap1, s1, t1);
marci@1025
    88
//     readDimacs(f2, g2, cap2, s2, t2);
marci@1013
    89
    
marci@1025
    90
//     GW::EdgeMap<int> cap(gw);
marci@1025
    91
//     for (GW::EdgeIt e(gw); e!=INVALID; ++e) {
marci@1025
    92
//       if (gw.forward(e)) cap.set(e, cap1[e]);
marci@1025
    93
//       if (gw.backward(e)) cap.set(e, cap2[e]);
marci@1025
    94
//     }
marci@1013
    95
marci@1025
    96
//     {
marci@1025
    97
//       GW::EdgeMap<int> flow(gw, 0);
marci@1025
    98
//       Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false), 
marci@1025
    99
// 			       GW::Node(t1, INVALID, false), cap, flow);
marci@1025
   100
//       preflow.run();
marci@1025
   101
//       std::cout << "s1->t1: " << preflow.flowValue() << std::endl; 
marci@1025
   102
//     }
marci@1025
   103
//     {
marci@1025
   104
//       GW::EdgeMap<int> flow(gw, 0);
marci@1025
   105
//       Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true), 
marci@1025
   106
// 			       GW::Node(INVALID, t2, true), cap, flow);
marci@1025
   107
//       preflow.run();
marci@1025
   108
//       std::cout << "s2->t2: " << preflow.flowValue() << std::endl; 
marci@1025
   109
//     }
marci@1025
   110
//     {
marci@1025
   111
//       GW::EdgeMap<int> flow(gw, 0);
marci@1025
   112
//       Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false), 
marci@1025
   113
// 			       GW::Node(INVALID, t2, true), cap, flow);
marci@1025
   114
//       preflow.run();
marci@1025
   115
//       std::cout << "s1->t2: " << preflow.flowValue() << std::endl; 
marci@1025
   116
//     }
marci@1025
   117
//     {
marci@1025
   118
//       GW::EdgeMap<int> flow(gw, 0);
marci@1025
   119
//       Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true), 
marci@1025
   120
// 			       GW::Node(s1, INVALID, false), cap, flow);
marci@1025
   121
//       preflow.run();
marci@1025
   122
//       std::cout << "s2->t1: " << preflow.flowValue() << std::endl; 
marci@1025
   123
//     }
marci@1025
   124
     cout << "1st graph" << endl;
marci@1025
   125
     printGraph(g1);
marci@1013
   126
marci@1025
   127
     cout << "2nd graph" << endl;
marci@1025
   128
     printGraph(g2);
marci@1013
   129
marci@1025
   130
     cout << "merged graph" << endl;
marci@1025
   131
     printGraph(gw);
marci@1025
   132
     
marci@1025
   133
//      for (GW::NodeIt n(gw); n!=INVALID; ++n) 
marci@1025
   134
//        std::cout << ize[n] << std::endl;
marci@1025
   135
//      for (GW::EdgeIt n(gw); n!=INVALID; ++n) 
marci@1025
   136
//        std::cout << mize[n] << std::endl;
marci@1025
   137
     
marci@1025
   138
     typedef NewEdgeSetGraphWrapper2<GW, Graph3> GWW;
marci@1025
   139
//     {
marci@1025
   140
//       checkConcept<StaticGraph, GWW>();   
marci@1025
   141
//     }
marci@1025
   142
marci@1025
   143
     GWW gww(gw);
marci@1025
   144
 
marci@1025
   145
     cout << "new edges graph" << endl;
marci@1025
   146
     printGraph(gww);
marci@1025
   147
marci@1025
   148
     GWW::NodeIt n(gww);
marci@1025
   149
     GWW::Node n1=n; 
marci@1025
   150
     ++n;
marci@1025
   151
     GWW::Node n2=n; 
marci@1025
   152
     gww.addEdge(n1, n2);
marci@1025
   153
     //     gww.addNode();
marci@1025
   154
     //     gww.addNode();
marci@1025
   155
marci@1025
   156
     cout << "new edges graph" << endl;
marci@1025
   157
     printGraph(gww);
marci@1025
   158
marci@1025
   159
     typedef AugmentingGraphWrapper<GW, GWW> GWWW;
marci@1025
   160
     //     {
marci@1025
   161
     //       checkConcept<StaticGraph, GWWW>();   
marci@1025
   162
     //     }
marci@1025
   163
     GWWW gwww(gw, gww);
marci@1025
   164
marci@1025
   165
     cout << "fully merged graph" << endl;
marci@1025
   166
     printGraph(gwww);
marci@915
   167
  }
marci@917
   168
marci@1013
   169
marci@1013
   170
  {
marci@1013
   171
    cout << "SECOND TEST" << endl;
marci@1013
   172
    typedef SmartGraph Graph1;
marci@1025
   173
//     {
marci@1025
   174
//       checkConcept<StaticGraph, Graph1>();
marci@1025
   175
//     }
marci@1013
   176
marci@1013
   177
    Graph1 g1;
marci@1013
   178
marci@1013
   179
    FullGraph pre_g2(2);
marci@1013
   180
    ConstMap<FullGraph::Edge, bool> const_false_map(false);
marci@1013
   181
    typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> >
marci@1013
   182
      Graph2;
marci@1025
   183
//     {
marci@1025
   184
//       checkConcept<StaticGraph, Graph2>();
marci@1025
   185
//     }
marci@1013
   186
marci@1013
   187
    Graph2 g2(pre_g2, const_false_map);
marci@1013
   188
marci@1013
   189
    typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
marci@1025
   190
//     {
marci@1025
   191
//       checkConcept<StaticGraph, GW>();   
marci@1025
   192
//     }
marci@1013
   193
    GW gw(g1, g2);
marci@1013
   194
    GW::Node sw;
marci@1013
   195
    GW::Node tw;
marci@1013
   196
    {
marci@1013
   197
      Graph2::NodeIt k(g2);
marci@1013
   198
      sw=GW::Node(INVALID, k, true);
marci@1013
   199
      ++k;
marci@1013
   200
      tw=GW::Node(INVALID, k, true);
marci@1013
   201
    }
marci@1013
   202
marci@1013
   203
    std::ifstream f1("graph2.dim");
marci@1013
   204
    readDimacs(f1, g1);
marci@1013
   205
marci@1013
   206
    cout << "1st graph" << endl;
marci@1013
   207
    printGraph(g1);
marci@1013
   208
marci@1013
   209
    cout << "2nd graph" << endl;
marci@1013
   210
    printGraph(g2);
marci@1013
   211
marci@1013
   212
    cout << "merged graph" << endl;
marci@1013
   213
    printGraph(gw);
marci@1013
   214
marci@1013
   215
    typedef ListGraph Graph3;
marci@1016
   216
    //typedef SmartGraph Graph3;
marci@1013
   217
    Graph3 g3;
marci@1013
   218
    GW::NodeMap<Graph3::Node> gwn(gw);
marci@1013
   219
    Graph3::NodeMap<GW::Node> g3n(g3);
marci@1013
   220
    for (GW::NodeIt n(gw); n!=INVALID; ++n) {
marci@1013
   221
      Graph3::Node m=g3.addNode();
marci@1013
   222
      gwn.set(n, m);
marci@1013
   223
      g3n.set(m, n);
marci@1013
   224
    }
marci@1013
   225
marci@1013
   226
    typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW;
marci@1025
   227
//     {
marci@1025
   228
//       checkConcept<StaticGraph, GWW>();   
marci@1025
   229
//     }
marci@1013
   230
marci@1013
   231
    GWW gww(gw, g3, gwn, g3n);
marci@1013
   232
marci@1013
   233
    for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
marci@1013
   234
      g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]);
marci@1013
   235
    }
marci@1013
   236
marci@1013
   237
//     for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
marci@1013
   238
//       gww.addEdge(sw, GW::Node(n,INVALID,false));
marci@1013
   239
//     }
marci@1013
   240
marci@1013
   241
    cout << "new edges" << endl;
marci@1013
   242
    printGraph(g3);
marci@1013
   243
marci@1013
   244
    cout << "new edges in the new graph" << endl;
marci@1013
   245
    printGraph(gww);
marci@1013
   246
marci@1013
   247
    typedef AugmentingGraphWrapper<GW, GWW> GWWW;
marci@1025
   248
//     {
marci@1025
   249
//       checkConcept<StaticGraph, GWWW>();   
marci@1025
   250
//     }
marci@1013
   251
    GWWW gwww(gw, gww);
marci@1013
   252
marci@1013
   253
    cout << "new edges merged into the original graph" << endl;
marci@1013
   254
    printGraph(gwww);
marci@1013
   255
marci@917
   256
  }
marci@1007
   257
marci@915
   258
}