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