src/work/peter/edgepathgraph_test.cc
author marci
Fri, 01 Oct 2004 11:31:03 +0000
changeset 933 1b7c88fbb950
parent 677 af3b5c85a227
child 986 e997802b855c
permissions -rw-r--r--
NodeSubGraphWrapper, test, and ducumentation modifications.
hegyi@677
     1
#include <string>
hegyi@677
     2
#include <iostream>
hegyi@677
     3
#include <stdio.h>
hegyi@677
     4
hegyi@677
     5
#include "edgepathgraph.h"
alpar@921
     6
#include <lemon/list_graph.h>
alpar@921
     7
#include <lemon/smart_graph.h>
hegyi@677
     8
#include <path.h>
hegyi@677
     9
alpar@921
    10
using namespace lemon;
hegyi@677
    11
using namespace std;
hegyi@677
    12
hegyi@677
    13
bool passed = true;
hegyi@677
    14
hegyi@677
    15
void check(bool rc) {
hegyi@677
    16
  passed = passed && rc;
hegyi@677
    17
  if(!rc) {
hegyi@677
    18
    cout << "Test failed!" << endl;
hegyi@677
    19
  }
hegyi@677
    20
}
hegyi@677
    21
hegyi@677
    22
int main()
hegyi@677
    23
{
hegyi@677
    24
  {
hegyi@677
    25
      EdgePathGraph<DirPath<ListGraph>, SmartGraph, ListGraph> EPGr;
hegyi@677
    26
      EPGr.addNode();
hegyi@677
    27
      EPGr.addNode();
hegyi@677
    28
      EPGr.addNode();
hegyi@677
    29
      EPGr.addNode();
hegyi@677
    30
      printf("%d node is in EPGr, after addition of 4 nodes.\n", EPGr.nodeNum());
hegyi@677
    31
hegyi@677
    32
      EdgePathGraph<DirPath<ListGraph>, SmartGraph, ListGraph> EPGr2(EPGr);
hegyi@677
    33
      printf("%d node is in EPGr2 created by copy constructor from EPGr.\n", EPGr2.nodeNum());
hegyi@677
    34
hegyi@677
    35
      EPGr2.addNode();
hegyi@677
    36
      EPGr2.addNode();
hegyi@677
    37
      printf("%d node is in EPGr2 after addition of 2 more nodes.\n", EPGr2.nodeNum());
hegyi@677
    38
hegyi@677
    39
      printf("%d nodes are in EPGr, before clear.\n", EPGr.nodeNum());
hegyi@677
    40
      EPGr.clear();
hegyi@677
    41
      printf("%d nodes are in EPGr, after clear.\n", EPGr.nodeNum());
hegyi@677
    42
      printf("%d nodes are in EPGr2, after clear of EPGr.\n", EPGr2.nodeNum());
hegyi@677
    43
      EPGr2.clear();
hegyi@677
    44
  }
hegyi@677
    45
  {
hegyi@677
    46
      EdgePathGraph<DirPath<ListGraph>, SmartGraph, ListGraph> EPGr;
hegyi@677
    47
      //EdgePathGraph<DirPath<ListGraph>, SmartGraph, EdgePathGraph<DirPath<SmartGraph>, ListGraph, SmartGraph> > EPGr;
hegyi@677
    48
      EdgePathGraph<DirPath<SmartGraph>, ListGraph, SmartGraph> EPGr2;
hegyi@677
    49
   
hegyi@677
    50
      typedef EdgePathGraph<DirPath<SmartGraph>, SmartGraph, ListGraph>::Node Node;
hegyi@677
    51
      typedef EdgePathGraph<DirPath<SmartGraph>, SmartGraph, ListGraph>::Edge Edge;
hegyi@677
    52
      typedef EdgePathGraph<DirPath<SmartGraph>, SmartGraph, ListGraph>::EdgeIt EdgeIt;
hegyi@677
    53
hegyi@677
    54
      Node n0, n1, n2;
hegyi@677
    55
      Edge e0, e1, e2, e3, e4, e5;
hegyi@677
    56
hegyi@677
    57
      ListGraph::Node m0, m1, m2, m3;
hegyi@677
    58
      ListGraph::Edge f0, f1, f2, f3, f4, f5;
hegyi@677
    59
hegyi@677
    60
hegyi@677
    61
      n0=EPGr.addNode();
hegyi@677
    62
      n1=EPGr.addNode();
hegyi@677
    63
      n2=EPGr.addNode();
hegyi@677
    64
hegyi@677
    65
      e0=EPGr.addEdge(n0,n1);
hegyi@677
    66
      e1=EPGr.addEdge(n1,n0);
hegyi@677
    67
      e2=EPGr.addEdge(n0,n2);
hegyi@677
    68
      e3=EPGr.addEdge(n2,n0);
hegyi@677
    69
      e4=EPGr.addEdge(n1,n2);
hegyi@677
    70
      e5=EPGr.addEdge(n2,n1);
hegyi@677
    71
hegyi@677
    72
hegyi@677
    73
      m0=EPGr2.addNode();
hegyi@677
    74
      m1=EPGr2.addNode();
hegyi@677
    75
      m2=EPGr2.addNode();
hegyi@677
    76
      m3=EPGr2.addNode();
hegyi@677
    77
    
hegyi@677
    78
      f0=EPGr2.addEdge(m0,m3);
hegyi@677
    79
      f1=EPGr2.addEdge(m3,m0);
hegyi@677
    80
      f2=EPGr2.addEdge(m2,m3);
hegyi@677
    81
      f3=EPGr2.addEdge(m3,m2);
hegyi@677
    82
      f4=EPGr2.addEdge(m1,m2);
hegyi@677
    83
      f5=EPGr2.addEdge(m2,m1);
hegyi@677
    84
hegyi@677
    85
      EPGr.sublayer=&(EPGr2.actuallayer);
hegyi@677
    86
      //EPGr.sublayer=&(EPGr2);
hegyi@677
    87
    
hegyi@677
    88
      EPGr.projection[n0]=&m0;
hegyi@677
    89
      EPGr.projection[n1]=&m1;
hegyi@677
    90
      EPGr.projection[n2]=&m2;
hegyi@677
    91
hegyi@677
    92
      
hegyi@677
    93
      typedef DirPath<ListGraph> DPath;
hegyi@677
    94
hegyi@677
    95
      //DPath P(EPGr2);
hegyi@677
    96
hegyi@677
    97
      DPath P1(EPGr2.actuallayer);//0-2
hegyi@677
    98
      DPath::Builder B1(P1);
hegyi@677
    99
      B1.pushBack(f0);
hegyi@677
   100
      B1.pushBack(f3);
hegyi@677
   101
      B1.commit();
hegyi@677
   102
      cout << P1.length() << " hosszu utvonal letrehozva" << endl;
hegyi@677
   103
hegyi@677
   104
      DPath P2(EPGr2.actuallayer);//2-0
hegyi@677
   105
      DPath::Builder B2(P2);
hegyi@677
   106
      B2.pushBack(f2);
hegyi@677
   107
      B2.pushBack(f1);
hegyi@677
   108
      B2.commit();
hegyi@677
   109
      cout << P2.length() << " hosszu utvonal letrehozva" << endl;
hegyi@677
   110
hegyi@677
   111
      DPath P3(EPGr2.actuallayer);//0-1
hegyi@677
   112
      DPath::Builder B3(P3);
hegyi@677
   113
      B3.pushBack(f0);
hegyi@677
   114
      B3.pushBack(f3);
hegyi@677
   115
      B3.pushBack(f5);
hegyi@677
   116
      B3.commit();
hegyi@677
   117
      cout << P3.length() << " hosszu utvonal letrehozva" << endl;
hegyi@677
   118
hegyi@677
   119
      DPath P4(EPGr2.actuallayer);//1-0
hegyi@677
   120
      DPath::Builder B4(P4);
hegyi@677
   121
      B4.pushBack(f4);
hegyi@677
   122
      B4.pushBack(f2);
hegyi@677
   123
      B4.pushBack(f1);
hegyi@677
   124
      B4.commit();
hegyi@677
   125
      cout << P4.length() << " hosszu utvonal letrehozva" << endl;
hegyi@677
   126
hegyi@677
   127
hegyi@677
   128
      EPGr.edgepath[e0]=&P3;
hegyi@677
   129
      EPGr.edgepath[e1]=&P4;
hegyi@677
   130
      EPGr.edgepath[e2]=&P1;
hegyi@677
   131
      EPGr.edgepath[e3]=&P2;
hegyi@677
   132
hegyi@677
   133
      for(EdgeIt e(EPGr.actuallayer);EPGr.actuallayer.valid(e);EPGr.actuallayer.next(e))
hegyi@677
   134
      {
hegyi@677
   135
	typedef DPath::EdgeIt PEdgeIt;
hegyi@677
   136
	PEdgeIt f;
hegyi@677
   137
hegyi@677
   138
	cout << "Edge " << EPGr.id(EPGr.tail(e)) << " - " << EPGr.id(EPGr.head(e)) << " in actual layer is";
hegyi@677
   139
        if(EPGr.edgepath[e])
hegyi@677
   140
	{
hegyi@677
   141
	  cout << endl << "Path";
hegyi@677
   142
	  for(EPGr.edgepath[e]->first(f); EPGr.edgepath[e]->valid(f); EPGr.edgepath[e]->next(f))
hegyi@677
   143
	  {
hegyi@677
   144
	    cout << " " << EPGr2.id(EPGr2.tail(f)) << "-" << EPGr2.id(EPGr2.head(f));
hegyi@677
   145
	  }
hegyi@677
   146
	  //cout << EPGr2.id(EPGr2.head(f)) << endl;
hegyi@677
   147
	  cout << endl;
hegyi@677
   148
	}
hegyi@677
   149
	else
hegyi@677
   150
	{
hegyi@677
   151
	  cout << " itself." <<endl;
hegyi@677
   152
	}
hegyi@677
   153
      }
hegyi@677
   154
    
hegyi@677
   155
hegyi@677
   156
      cout << "================================" << endl;
hegyi@677
   157
    
hegyi@677
   158
      SmartGraph::EdgeMap<int> actlaymap(EPGr.actuallayer);
hegyi@677
   159
      //EdgePathGraph<DirPath<ListGraph>, SmartGraph, EdgePathGraph<DirPath<SmartGraph>, ListGraph, SmartGraph> > EPGr;
hegyi@677
   160
      ListGraph::EdgeMap<double> sublaymap(EPGr2.actuallayer);
hegyi@677
   161
      
hegyi@677
   162
hegyi@677
   163
      actlaymap[e1]=5;
hegyi@677
   164
hegyi@677
   165
      //EdgeMap-ok kiirasa
hegyi@677
   166
hegyi@677
   167
      cout << "EdgeMaps before addMap:" << endl;
hegyi@677
   168
    
hegyi@677
   169
      cout << "actlaymap: ";
hegyi@677
   170
      for(EdgeIt e(EPGr.actuallayer);EPGr.actuallayer.valid(e);EPGr.actuallayer.next(e))
hegyi@677
   171
      {
hegyi@677
   172
	cout << EPGr.id(EPGr.tail(e)) << "-" << EPGr.id(EPGr.head(e)) << ":" << actlaymap[e] << " ";
hegyi@677
   173
      }
hegyi@677
   174
      cout << endl;
hegyi@677
   175
      cout << "sublaymap: ";
hegyi@677
   176
      for(ListGraph::EdgeIt e(EPGr2.actuallayer);EPGr2.actuallayer.valid(e);EPGr2.actuallayer.next(e))
hegyi@677
   177
      {
hegyi@677
   178
	cout << EPGr2.id(EPGr2.tail(e)) << "-" << EPGr2.id(EPGr2.head(e)) << ":" << sublaymap[e] << " ";
hegyi@677
   179
      }
hegyi@677
   180
      cout << endl;
hegyi@677
   181
      //EdgeMap-ok kiirasa#vege
hegyi@677
   182
hegyi@677
   183
      
hegyi@677
   184
      EPGr.addMap<int, double>(actlaymap, sublaymap);
hegyi@677
   185
hegyi@677
   186
      //EdgeMap-ok kiirasa
hegyi@677
   187
hegyi@677
   188
      cout << "EdgeMaps after addMap:" << endl;
hegyi@677
   189
    
hegyi@677
   190
      cout << "actlaymap: ";
hegyi@677
   191
      for(EdgeIt e(EPGr.actuallayer);EPGr.actuallayer.valid(e);EPGr.actuallayer.next(e))
hegyi@677
   192
      {
hegyi@677
   193
	cout << EPGr.id(EPGr.tail(e)) << "-" << EPGr.id(EPGr.head(e)) << ":" << actlaymap[e] << " ";
hegyi@677
   194
      }
hegyi@677
   195
      cout << endl;
hegyi@677
   196
      cout << "sublaymap: ";
hegyi@677
   197
      for(ListGraph::EdgeIt e(EPGr2.actuallayer);EPGr2.actuallayer.valid(e);EPGr2.actuallayer.next(e))
hegyi@677
   198
      {
hegyi@677
   199
	cout << EPGr2.id(EPGr2.tail(e)) << "-" << EPGr2.id(EPGr2.head(e)) << ":" << sublaymap[e] << " ";
hegyi@677
   200
      }
hegyi@677
   201
      cout << endl;
hegyi@677
   202
      //EdgeMap-ok kiirasa#vege
hegyi@677
   203
    
hegyi@677
   204
    
hegyi@677
   205
  }
hegyi@677
   206
}