COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/graphdemo.cc @ 126:89c6e4687fcc

Last change on this file since 126:89c6e4687fcc was 35:65dca0f43fba, checked in by Alpar Juttner, 21 years ago

.

File size: 2.8 KB
RevLine 
[1]1#include <iostream>
2#include <graph.h>
[2]3#include <bfs.h>
[1]4
5using namespace NEGRO;
6using namespace std;
7
8class NodeData;
9class EdgeData;
10
11typedef Graph<NodeData,EdgeData> TestGraph;
12
13class NodeData
14{
15public:
16  int id;
17  bool isVis;
[2]18  bfs_node_data<TestGraph> bfs;
[1]19};
20
21class EdgeData
22{
23public:
24  int id;
25};
26
[2]27typedef Graph<NodeData,EdgeData> TestGraph;
[1]28
[3]29int main()
[1]30{
31  TestGraph G;
[3]32  TestGraph::NodeIterator n,m;
33  TestGraph::OutEdgeIterator e;
34  int i;
[1]35
36 
37  //for(i=1;i<=10;i++) G.AddNode().n=i; //Ez nagyon rossz!!!!!!!!
38  for(i=1;i<=10;i++) G.AddNode()->id=i; //Ez a jo!!!!!!!!
39
40  //n=G.AddNode();
41 
42   //for(i=1;i<=10;i++) cout << (G.AddNode()->n=i) << ' ';
43   //cout << '\n';
44 
45  i=0;
[35]46  for(G.GetFirst(n);n.Valid();n++)
47    for(G.GetFirst(m);m.Valid();++m)
[1]48      if(n!=m) G.AddEdge(n,m)->id=++i;
49   
50  cout << "Number of edges: " << i << "\n\n";
51
52  TestGraph::AllEdgeIterator a;
[35]53  for(G.GetFirst(a);a.Valid();++a)
[1]54    cout << a->id << ":" << a.From()->id << "->" << a.To()->id << "   ";
55
56  cout << "\n\n\n";
57 
[35]58  for(G.GetFirst(n);n.Valid();++n)
[1]59    {
60      cout << n->id << "->";
[35]61      for(G.GetFirst(e,n);e.Valid();++e)
[1]62        cout << e->id << ":" << e.To()->id << ' ';
63      cout << '\n';
64    }
65 
66  cout << "\n\n\n\nB-verzio:\n\n\n";
67 
68  G.Clean();
69
70  for(i=1;i<=10;i++) G.AddNode()->id=i;
71 
72  i=0;
[35]73  for(n=G.First();n.Valid();n++)
74    for(m=G.First();m.Valid();++m)
[1]75      if(n!=m) G.AddEdge(n,m)->id=++i;
76   
77  ;
[35]78  for(n=G.First();n.Valid();++n) //Demo
[1]79    {
80      e=G.First(n);
[35]81      while(e.Valid())
[3]82        if((e->id)%2) G.Delete(e++);  //it may be nice to have a postfix ++
[1]83        else ++e;
84    }
85 
[2]86  // cout << "Number of edges: " << i << "\n\n";
87
[35]88  for(a=G.First();a.Valid();++a)
[1]89    cout << a->id << ": " << a.From()->id << "->" << a.To()->id << "   ";
90 
91  cout << "\n\n\n";
92 
[35]93  for(n=G.First();n.Valid();++n)
[1]94    {
95      cout << n->id << "->";
[35]96      for(e=G.First(n);e.Valid();++e)
[1]97        cout << e->id << ":" << e.To()->id << ' ';
98      cout << '\n';
99    }
100 
[3]101  // For Marci's sake
[2]102 
[3]103  {
104    G.Clean();
105   
106    for(int i=1;i<=10;i++) G.AddNode()->id=i;
107   
108   
109    {  //I would'n say I'm really happy with this.
[35]110      int i=0;
111      for(TestGraph::NodeIterator n(G);n.Valid();n++)
112        for(TestGraph::NodeIterator m(G);m.Valid();++m)
[3]113          if(n!=m) G.AddEdge(n,m)->id=++i;
114    }
115   
[35]116    for(TestGraph::NodeIterator n(G);n.Valid();++n) //Demo
[3]117      {
118        TestGraph::OutEdgeIterator e(G,n);
[35]119        while(e.Valid())
[3]120          if((e->id)%2) G.Delete(e++);  //it may be nice to have a postfix ++
121          else ++e;
122      }
123   
[35]124    for(TestGraph::AllEdgeIterator a(G);a.Valid();++a)
[3]125      cout << a->id << ": " << a.From()->id << "->" << a.To()->id << "   ";
126   
127    cout << "\n\n\n";
128   
[35]129    for(TestGraph::NodeIterator n(G);n.Valid();++n)
[3]130      {
131        cout << n->id << "->";
[35]132        for(TestGraph::OutEdgeIterator e(G,n);e.Valid();++e)
[3]133          cout << e->id << ":" << e.To()->id << ' ';
134        cout << '\n';
135      }
136  }
[1]137}
Note: See TracBrowser for help on using the repository browser.