src/work/alpar/list_graph_demo.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/alpar/list_graph_demo.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,154 +0,0 @@
     1.4 -#include<list_graph.h>
     1.5 -#include<concept/graph.h>
     1.6 -
     1.7 -#include <iostream>
     1.8 -#include <vector>
     1.9 -
    1.10 -using namespace lemon;
    1.11 -
    1.12 -typedef ListGraph Graph;
    1.13 -//typedef Graph Graph;
    1.14 -
    1.15 -
    1.16 -Graph::OutEdgeIt safeFirstOut(const Graph &G, Graph::Node n)
    1.17 -{
    1.18 -  return G.valid(n) ? Graph::OutEdgeIt(G,n):INVALID;
    1.19 -}
    1.20 -
    1.21 -int main()
    1.22 -{
    1.23 -
    1.24 -  typedef Graph::Edge Edge;
    1.25 -  typedef Graph::InEdgeIt InEdgeIt;
    1.26 -  typedef Graph::OutEdgeIt OutEdgeIt;
    1.27 -  typedef Graph::EdgeIt EdgeIt;
    1.28 -  typedef Graph::Node Node;
    1.29 -  typedef Graph::NodeIt NodeIt;
    1.30 -  
    1.31 -  Graph G;
    1.32 -  
    1.33 -  {
    1.34 -    NodeIt n;
    1.35 -
    1.36 -    for(int i=0;i<10;i++) G.addNode();
    1.37 -    for(G.first(n);G.valid(n);G.next(n)) 
    1.38 -      for(NodeIt m(G);m!=INVALID;G.next(m)) 
    1.39 -	if(n!=m) G.addEdge(n,m);
    1.40 -    
    1.41 -    OutEdgeIt e = safeFirstOut(G,n);
    1.42 -    OutEdgeIt f = safeFirstOut(G,NodeIt(G));
    1.43 -    
    1.44 -    
    1.45 -    InEdgeIt i(INVALID), j;
    1.46 -    InEdgeIt ii(i);
    1.47 -    ii=G.first(i,n);
    1.48 -    ii=G.next(i);
    1.49 -    
    1.50 -    OutEdgeIt o(INVALID), oo;
    1.51 -    OutEdgeIt ooo(oo);
    1.52 -    oo=G.first(o,n);
    1.53 -    oo=G.next(o);
    1.54 -    
    1.55 -    EdgeIt ei(INVALID), eie;
    1.56 -    EdgeIt eiee(ei);
    1.57 -    eie=G.first(ei);
    1.58 -    eie=G.next(ei);
    1.59 -    
    1.60 -    Edge eee(i);
    1.61 -    eee=o;
    1.62 -    eee=eie;
    1.63 -    
    1.64 -    
    1.65 -    bool tm;
    1.66 -    tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
    1.67 -    
    1.68 -    std::vector<InEdgeIt> v(10);
    1.69 -    std::vector<InEdgeIt> w(10,INVALID);
    1.70 -    
    1.71 -  }
    1.72 -  
    1.73 -  // Test of maps
    1.74 -
    1.75 -  G.clear();
    1.76 -  
    1.77 -  for(int i=0;i<10;i++) G.addNode();
    1.78 -  for(NodeIt i(G);G.valid(i);G.next(i)) 
    1.79 -    for(NodeIt j(G);G.valid(j);G.next(j)) 
    1.80 -      if(i<j) G.addEdge(i,j);           //The iterators are comparable
    1.81 -  
    1.82 -  Graph::NodeMap<int> n(G);
    1.83 -  int count=0;
    1.84 -  for(NodeIt i(G);G.valid(i);G.next(i)) n[i]=count++;
    1.85 -  
    1.86 -  Graph::NodeMap<int> nn=n;
    1.87 -  Graph::NodeMap<double> dd=n;
    1.88 -
    1.89 -  n = nn;
    1.90 -  
    1.91 -  dd = nn;
    1.92 -  
    1.93 -  Graph::EdgeMap<int> emap(G);
    1.94 -
    1.95 -  // Test of SymListGraph
    1.96 -  
    1.97 -  {
    1.98 -    typedef SymListGraph 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 -    Graph::EdgeMap<int> em(G);
   1.114 -    Graph::SymEdgeMap<int> sm(G);
   1.115 -    for(EdgeIt e(G);G.valid(e);G.next(e)) em[e]=G.id(e);
   1.116 -    for(EdgeIt e(G);G.valid(e);G.next(e))
   1.117 -      if(G.source(e)<G.target(e)) sm[e]=G.id(e);
   1.118 -    
   1.119 -    for(EdgeIt e(G);G.valid(e);G.next(e))
   1.120 -      std::cout << G.id(G.source(e)) << "->" << G.id(G.target(e))
   1.121 -		<< ": id=" << G.id(e) << " oppid=" << G.id(G.opposite(e))
   1.122 -		<< " em=" << em[e]
   1.123 -		<< " sm=" << sm[e] << "\n";
   1.124 -    
   1.125 -    //Delete all nodes
   1.126 -    NodeIt n;
   1.127 -    while(G.valid(G.first(n))) G.erase(n);
   1.128 -  }
   1.129 -
   1.130 -  // Tests for NodeSet and EdgeSet
   1.131 -  
   1.132 -  {
   1.133 -    NodeSet N;
   1.134 -    
   1.135 -    typedef EdgeSet<NodeSet> ES;
   1.136 -    
   1.137 -    ES E(N);
   1.138 -    ES F(N);
   1.139 -    for(int i=0;i<10;i++) G.addNode();
   1.140 -    
   1.141 -    for(ES::NodeIt n(E);E.valid(n);E.next(n))
   1.142 -      for(ES::NodeIt m(E);E.valid(m);E.next(m))
   1.143 -	if(n!=m) F.addEdge(n,m);
   1.144 -    for(ES::NodeIt n(F);F.valid(n);F.next(n))
   1.145 -      for(ES::NodeIt m(F);F.valid(m);F.next(m))
   1.146 -	if(n<m) F.addEdge(n,m);
   1.147 -    
   1.148 -
   1.149 -    NodeSet::NodeMap<int> nm1(N);
   1.150 -    ES::NodeMap<int> nm2(E);
   1.151 -    ES::EdgeMap<int> eme(E);
   1.152 -    ES::EdgeMap<int> emf(F);
   1.153 -    
   1.154 -       
   1.155 -  }
   1.156 -  
   1.157 -}