src/work/alpar/smart_graph_demo.cc
changeset 742 235fd36336b7
parent 164 970b265696b0
child 880 9d0bfd35b97c
equal deleted inserted replaced
1:599ff1ce9a56 2:d592c0d01713
     4 #include <iostream>
     4 #include <iostream>
     5 #include <vector>
     5 #include <vector>
     6 
     6 
     7 using namespace hugo;
     7 using namespace hugo;
     8 
     8 
     9 //typedef SmartGraph Graph;
     9 typedef SmartGraph Graph;
    10 typedef EmptyGraph Graph;
    10 //typedef GraphSkeleton Graph;
    11 
    11 
    12 
    12 
    13 Graph::OutEdgeIt safeFirstOut(const Graph &G, Graph::Node n)
    13 Graph::OutEdgeIt safeFirstOut(const Graph &G, Graph::Node n)
    14 {
    14 {
    15   return G.valid(n) ? Graph::OutEdgeIt(G,n):INVALID;
    15   return G.valid(n) ? Graph::OutEdgeIt(G,n):INVALID;
    24   typedef Graph::EdgeIt EdgeIt;
    24   typedef Graph::EdgeIt EdgeIt;
    25   typedef Graph::Node Node;
    25   typedef Graph::Node Node;
    26   typedef Graph::NodeIt NodeIt;
    26   typedef Graph::NodeIt NodeIt;
    27   
    27   
    28   Graph G;
    28   Graph G;
    29   NodeIt n;
    29   
       
    30   {
       
    31     NodeIt n;
    30 
    32 
       
    33     for(int i=0;i<10;i++) G.addNode();
       
    34     for(G.first(n);G.valid(n);G.next(n)) 
       
    35       for(NodeIt m(G);m!=INVALID;G.next(m)) 
       
    36 	if(n!=m) G.addEdge(n,m);
       
    37     
       
    38     OutEdgeIt e = safeFirstOut(G,n);
       
    39     OutEdgeIt f = safeFirstOut(G,NodeIt(G));
       
    40     
       
    41     
       
    42     InEdgeIt i(INVALID), j;
       
    43     InEdgeIt ii(i);
       
    44     ii=G.first(i,n);
       
    45     ii=G.next(i);
       
    46     
       
    47     OutEdgeIt o(INVALID), oo;
       
    48     OutEdgeIt ooo(oo);
       
    49     oo=G.first(o,n);
       
    50     oo=G.next(o);
       
    51     
       
    52     EdgeIt ei(INVALID), eie;
       
    53     EdgeIt eiee(ei);
       
    54     eie=G.first(ei);
       
    55     eie=G.next(ei);
       
    56     
       
    57     Edge eee(i);
       
    58     eee=o;
       
    59     eee=eie;
       
    60     
       
    61     
       
    62     bool tm;
       
    63     tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
       
    64     
       
    65     std::vector<InEdgeIt> v(10);
       
    66     std::vector<InEdgeIt> w(10,INVALID);
       
    67     
       
    68   }
       
    69   
       
    70   // Test of maps
    31 
    71 
       
    72   G.clear();
       
    73   
    32   for(int i=0;i<10;i++) G.addNode();
    74   for(int i=0;i<10;i++) G.addNode();
    33   for(G.first(n);G.valid(n);G.next(n)) 
    75   for(NodeIt i(G);G.valid(i);G.next(i)) 
    34     for(NodeIt m(G);m!=INVALID;G.next(m)) 
    76     for(NodeIt j(G);G.valid(j);G.next(j)) 
    35       if(n!=m) G.addEdge(n,m);
    77       if(i<j) G.addEdge(i,j);           //The iterators are comparable
       
    78   
       
    79   Graph::NodeMap<int> n(G);
       
    80   int count=0;
       
    81   for(NodeIt i(G);G.valid(i);G.next(i)) n[i]=count++;
       
    82   
       
    83   Graph::NodeMap<int> nn=n;
       
    84   Graph::NodeMap<double> dd=n;
    36 
    85 
    37   OutEdgeIt e = safeFirstOut(G,n);
    86   n = nn;
    38   OutEdgeIt f = safeFirstOut(G,NodeIt(G));
       
    39   
    87   
       
    88   dd = nn;
       
    89   
       
    90   Graph::EdgeMap<int> emap(G);
    40 
    91 
    41   InEdgeIt i(INVALID), j;
    92   // Test of SymSmartGraph
    42   InEdgeIt ii(i);
       
    43   ii=G.first(i,n);
       
    44   ii=G.next(i);
       
    45   
    93   
    46   OutEdgeIt o(INVALID), oo;
    94   {
    47   OutEdgeIt ooo(oo);
    95     typedef SymSmartGraph Graph;
    48   oo=G.first(o,n);
    96     typedef Graph::Edge Edge;
    49   oo=G.next(o);
    97     typedef Graph::InEdgeIt InEdgeIt;
       
    98     typedef Graph::OutEdgeIt OutEdgeIt;
       
    99     typedef Graph::EdgeIt EdgeIt;
       
   100     typedef Graph::Node Node;
       
   101     typedef Graph::NodeIt NodeIt;
       
   102 
       
   103     Graph G;
       
   104 
       
   105     for(int i=0;i<10;i++) G.addNode();
       
   106     for(NodeIt i(G);G.valid(i);G.next(i)) 
       
   107       for(NodeIt j(G);G.valid(j);G.next(j)) 
       
   108 	if(i<j) G.addEdge(i,j);           //The iterators are comparable
    50   
   109   
    51   EdgeIt ei(INVALID), eie;
   110     Graph::EdgeMap<int> em(G);
    52   EdgeIt eiee(ei);
   111     Graph::SymEdgeMap<int> sm(G);
    53   eie=G.first(ei);
   112     for(EdgeIt e(G);G.valid(e);G.next(e)) em[e]=G.id(e);
    54   eie=G.next(ei);
   113     for(EdgeIt e(G);G.valid(e);G.next(e))
    55 
   114       if(G.tail(e)<G.head(e)) sm[e]=G.id(e);
    56   Edge eee(i);
   115     
    57   eee=o;
   116     for(EdgeIt e(G);G.valid(e);G.next(e))
    58   eee=eie;
   117       std::cout << G.id(G.tail(e)) << "->" << G.id(G.head(e))
    59   
   118 		<< ": id=" << G.id(e) << " oppid=" << G.id(G.opposite(e))
    60   
   119 		<< " em=" << em[e]
    61   bool tm;
   120 		<< " sm=" << sm[e] << "\n";
    62   tm = G.valid(n) && G.valid(i) && G.valid(o) && G.valid(ei);
   121     
    63 
   122   }
    64   std::vector<InEdgeIt> v(10);
       
    65   std::vector<InEdgeIt> w(10,INVALID);
       
    66   
   123   
    67 }
   124 }