src/work/alpar/smart_graph_demo.cc
author alpar
Fri, 15 Apr 2005 19:56:25 +0000
changeset 1359 1581f961cfaa
parent 921 818510fa3d99
permissions -rw-r--r--
Correct the english name of EGRES.
alpar@157
     1
#include<smart_graph.h>
alpar@164
     2
#include<emptygraph.h>
alpar@157
     3
alpar@157
     4
#include <iostream>
alpar@164
     5
#include <vector>
alpar@157
     6
alpar@921
     7
using namespace lemon;
alpar@157
     8
alpar@185
     9
typedef SmartGraph Graph;
alpar@880
    10
//typedef Graph Graph;
alpar@164
    11
alpar@164
    12
alpar@164
    13
Graph::OutEdgeIt safeFirstOut(const Graph &G, Graph::Node n)
alpar@157
    14
{
alpar@164
    15
  return G.valid(n) ? Graph::OutEdgeIt(G,n):INVALID;
alpar@157
    16
}
alpar@157
    17
alpar@157
    18
int main()
alpar@157
    19
{
alpar@157
    20
alpar@164
    21
  typedef Graph::Edge Edge;
alpar@164
    22
  typedef Graph::InEdgeIt InEdgeIt;
alpar@164
    23
  typedef Graph::OutEdgeIt OutEdgeIt;
alpar@164
    24
  typedef Graph::EdgeIt EdgeIt;
alpar@164
    25
  typedef Graph::Node Node;
alpar@164
    26
  typedef Graph::NodeIt NodeIt;
alpar@157
    27
  
alpar@164
    28
  Graph G;
alpar@185
    29
  
alpar@185
    30
  {
alpar@185
    31
    NodeIt n;
alpar@157
    32
alpar@185
    33
    for(int i=0;i<10;i++) G.addNode();
alpar@185
    34
    for(G.first(n);G.valid(n);G.next(n)) 
alpar@185
    35
      for(NodeIt m(G);m!=INVALID;G.next(m)) 
alpar@185
    36
	if(n!=m) G.addEdge(n,m);
alpar@185
    37
    
alpar@185
    38
    OutEdgeIt e = safeFirstOut(G,n);
alpar@185
    39
    OutEdgeIt f = safeFirstOut(G,NodeIt(G));
alpar@185
    40
    
alpar@185
    41
    
alpar@185
    42
    InEdgeIt i(INVALID), j;
alpar@185
    43
    InEdgeIt ii(i);
alpar@185
    44
    ii=G.first(i,n);
alpar@185
    45
    ii=G.next(i);
alpar@185
    46
    
alpar@185
    47
    OutEdgeIt o(INVALID), oo;
alpar@185
    48
    OutEdgeIt ooo(oo);
alpar@185
    49
    oo=G.first(o,n);
alpar@185
    50
    oo=G.next(o);
alpar@185
    51
    
alpar@185
    52
    EdgeIt ei(INVALID), eie;
alpar@185
    53
    EdgeIt eiee(ei);
alpar@185
    54
    eie=G.first(ei);
alpar@185
    55
    eie=G.next(ei);
alpar@185
    56
    
alpar@185
    57
    Edge eee(i);
alpar@185
    58
    eee=o;
alpar@185
    59
    eee=eie;
alpar@185
    60
    
alpar@185
    61
    
alpar@185
    62
    bool tm;
alpar@185
    63
    tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
alpar@185
    64
    
alpar@185
    65
    std::vector<InEdgeIt> v(10);
alpar@185
    66
    std::vector<InEdgeIt> w(10,INVALID);
alpar@185
    67
    
alpar@185
    68
  }
alpar@185
    69
  
alpar@185
    70
  // Test of maps
alpar@157
    71
alpar@185
    72
  G.clear();
alpar@185
    73
  
alpar@157
    74
  for(int i=0;i<10;i++) G.addNode();
alpar@185
    75
  for(NodeIt i(G);G.valid(i);G.next(i)) 
alpar@185
    76
    for(NodeIt j(G);G.valid(j);G.next(j)) 
alpar@185
    77
      if(i<j) G.addEdge(i,j);           //The iterators are comparable
alpar@185
    78
  
alpar@185
    79
  Graph::NodeMap<int> n(G);
alpar@185
    80
  int count=0;
alpar@185
    81
  for(NodeIt i(G);G.valid(i);G.next(i)) n[i]=count++;
alpar@185
    82
  
alpar@185
    83
  Graph::NodeMap<int> nn=n;
alpar@185
    84
  Graph::NodeMap<double> dd=n;
alpar@157
    85
alpar@185
    86
  n = nn;
alpar@164
    87
  
alpar@185
    88
  dd = nn;
alpar@185
    89
  
alpar@185
    90
  Graph::EdgeMap<int> emap(G);
alpar@164
    91
alpar@185
    92
  // Test of SymSmartGraph
alpar@164
    93
  
alpar@185
    94
  {
alpar@185
    95
    typedef SymSmartGraph Graph;
alpar@185
    96
    typedef Graph::Edge Edge;
alpar@185
    97
    typedef Graph::InEdgeIt InEdgeIt;
alpar@185
    98
    typedef Graph::OutEdgeIt OutEdgeIt;
alpar@185
    99
    typedef Graph::EdgeIt EdgeIt;
alpar@185
   100
    typedef Graph::Node Node;
alpar@185
   101
    typedef Graph::NodeIt NodeIt;
alpar@185
   102
alpar@185
   103
    Graph G;
alpar@185
   104
alpar@185
   105
    for(int i=0;i<10;i++) G.addNode();
alpar@185
   106
    for(NodeIt i(G);G.valid(i);G.next(i)) 
alpar@185
   107
      for(NodeIt j(G);G.valid(j);G.next(j)) 
alpar@185
   108
	if(i<j) G.addEdge(i,j);           //The iterators are comparable
alpar@164
   109
  
alpar@185
   110
    Graph::EdgeMap<int> em(G);
alpar@185
   111
    Graph::SymEdgeMap<int> sm(G);
alpar@185
   112
    for(EdgeIt e(G);G.valid(e);G.next(e)) em[e]=G.id(e);
alpar@185
   113
    for(EdgeIt e(G);G.valid(e);G.next(e))
alpar@986
   114
      if(G.source(e)<G.target(e)) sm[e]=G.id(e);
alpar@185
   115
    
alpar@185
   116
    for(EdgeIt e(G);G.valid(e);G.next(e))
alpar@986
   117
      std::cout << G.id(G.source(e)) << "->" << G.id(G.target(e))
alpar@185
   118
		<< ": id=" << G.id(e) << " oppid=" << G.id(G.opposite(e))
alpar@185
   119
		<< " em=" << em[e]
alpar@185
   120
		<< " sm=" << sm[e] << "\n";
alpar@185
   121
    
alpar@185
   122
  }
alpar@157
   123
  
alpar@157
   124
}