src/work/alpar/smart_graph_demo.cc
changeset 185 259540358bbf
parent 164 970b265696b0
child 880 9d0bfd35b97c
     1.1 --- a/src/work/alpar/smart_graph_demo.cc	Sat Mar 13 22:49:54 2004 +0000
     1.2 +++ b/src/work/alpar/smart_graph_demo.cc	Sat Mar 13 22:53:07 2004 +0000
     1.3 @@ -6,8 +6,8 @@
     1.4  
     1.5  using namespace hugo;
     1.6  
     1.7 -//typedef SmartGraph Graph;
     1.8 -typedef EmptyGraph Graph;
     1.9 +typedef SmartGraph Graph;
    1.10 +//typedef GraphSkeleton Graph;
    1.11  
    1.12  
    1.13  Graph::OutEdgeIt safeFirstOut(const Graph &G, Graph::Node n)
    1.14 @@ -26,42 +26,99 @@
    1.15    typedef Graph::NodeIt NodeIt;
    1.16    
    1.17    Graph G;
    1.18 -  NodeIt n;
    1.19 +  
    1.20 +  {
    1.21 +    NodeIt n;
    1.22  
    1.23 +    for(int i=0;i<10;i++) G.addNode();
    1.24 +    for(G.first(n);G.valid(n);G.next(n)) 
    1.25 +      for(NodeIt m(G);m!=INVALID;G.next(m)) 
    1.26 +	if(n!=m) G.addEdge(n,m);
    1.27 +    
    1.28 +    OutEdgeIt e = safeFirstOut(G,n);
    1.29 +    OutEdgeIt f = safeFirstOut(G,NodeIt(G));
    1.30 +    
    1.31 +    
    1.32 +    InEdgeIt i(INVALID), j;
    1.33 +    InEdgeIt ii(i);
    1.34 +    ii=G.first(i,n);
    1.35 +    ii=G.next(i);
    1.36 +    
    1.37 +    OutEdgeIt o(INVALID), oo;
    1.38 +    OutEdgeIt ooo(oo);
    1.39 +    oo=G.first(o,n);
    1.40 +    oo=G.next(o);
    1.41 +    
    1.42 +    EdgeIt ei(INVALID), eie;
    1.43 +    EdgeIt eiee(ei);
    1.44 +    eie=G.first(ei);
    1.45 +    eie=G.next(ei);
    1.46 +    
    1.47 +    Edge eee(i);
    1.48 +    eee=o;
    1.49 +    eee=eie;
    1.50 +    
    1.51 +    
    1.52 +    bool tm;
    1.53 +    tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
    1.54 +    
    1.55 +    std::vector<InEdgeIt> v(10);
    1.56 +    std::vector<InEdgeIt> w(10,INVALID);
    1.57 +    
    1.58 +  }
    1.59 +  
    1.60 +  // Test of maps
    1.61  
    1.62 +  G.clear();
    1.63 +  
    1.64    for(int i=0;i<10;i++) G.addNode();
    1.65 -  for(G.first(n);G.valid(n);G.next(n)) 
    1.66 -    for(NodeIt m(G);m!=INVALID;G.next(m)) 
    1.67 -      if(n!=m) G.addEdge(n,m);
    1.68 +  for(NodeIt i(G);G.valid(i);G.next(i)) 
    1.69 +    for(NodeIt j(G);G.valid(j);G.next(j)) 
    1.70 +      if(i<j) G.addEdge(i,j);           //The iterators are comparable
    1.71 +  
    1.72 +  Graph::NodeMap<int> n(G);
    1.73 +  int count=0;
    1.74 +  for(NodeIt i(G);G.valid(i);G.next(i)) n[i]=count++;
    1.75 +  
    1.76 +  Graph::NodeMap<int> nn=n;
    1.77 +  Graph::NodeMap<double> dd=n;
    1.78  
    1.79 -  OutEdgeIt e = safeFirstOut(G,n);
    1.80 -  OutEdgeIt f = safeFirstOut(G,NodeIt(G));
    1.81 +  n = nn;
    1.82    
    1.83 +  dd = nn;
    1.84 +  
    1.85 +  Graph::EdgeMap<int> emap(G);
    1.86  
    1.87 -  InEdgeIt i(INVALID), j;
    1.88 -  InEdgeIt ii(i);
    1.89 -  ii=G.first(i,n);
    1.90 -  ii=G.next(i);
    1.91 +  // Test of SymSmartGraph
    1.92    
    1.93 -  OutEdgeIt o(INVALID), oo;
    1.94 -  OutEdgeIt ooo(oo);
    1.95 -  oo=G.first(o,n);
    1.96 -  oo=G.next(o);
    1.97 +  {
    1.98 +    typedef SymSmartGraph Graph;
    1.99 +    typedef Graph::Edge Edge;
   1.100 +    typedef Graph::InEdgeIt InEdgeIt;
   1.101 +    typedef Graph::OutEdgeIt OutEdgeIt;
   1.102 +    typedef Graph::EdgeIt EdgeIt;
   1.103 +    typedef Graph::Node Node;
   1.104 +    typedef Graph::NodeIt NodeIt;
   1.105 +
   1.106 +    Graph G;
   1.107 +
   1.108 +    for(int i=0;i<10;i++) G.addNode();
   1.109 +    for(NodeIt i(G);G.valid(i);G.next(i)) 
   1.110 +      for(NodeIt j(G);G.valid(j);G.next(j)) 
   1.111 +	if(i<j) G.addEdge(i,j);           //The iterators are comparable
   1.112    
   1.113 -  EdgeIt ei(INVALID), eie;
   1.114 -  EdgeIt eiee(ei);
   1.115 -  eie=G.first(ei);
   1.116 -  eie=G.next(ei);
   1.117 -
   1.118 -  Edge eee(i);
   1.119 -  eee=o;
   1.120 -  eee=eie;
   1.121 -  
   1.122 -  
   1.123 -  bool tm;
   1.124 -  tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
   1.125 -
   1.126 -  std::vector<InEdgeIt> v(10);
   1.127 -  std::vector<InEdgeIt> w(10,INVALID);
   1.128 +    Graph::EdgeMap<int> em(G);
   1.129 +    Graph::SymEdgeMap<int> sm(G);
   1.130 +    for(EdgeIt e(G);G.valid(e);G.next(e)) em[e]=G.id(e);
   1.131 +    for(EdgeIt e(G);G.valid(e);G.next(e))
   1.132 +      if(G.tail(e)<G.head(e)) sm[e]=G.id(e);
   1.133 +    
   1.134 +    for(EdgeIt e(G);G.valid(e);G.next(e))
   1.135 +      std::cout << G.id(G.tail(e)) << "->" << G.id(G.head(e))
   1.136 +		<< ": id=" << G.id(e) << " oppid=" << G.id(G.opposite(e))
   1.137 +		<< " em=" << em[e]
   1.138 +		<< " sm=" << sm[e] << "\n";
   1.139 +    
   1.140 +  }
   1.141    
   1.142  }