Last change
on this file since 500:1a45623b4796 was
8:cd54905012bc,
checked in by Alpar Juttner, 18 years ago

New test: bfsdemo2.cc added
 Graph class has a NodeMap? and an EdgeMap? member class
 default_bfs_T uning the above Maps is added
 a (property)map must provide a member function SetG() to attach the map
to a graph

File size:
987 bytes

Rev  Line  

[6]  1  #include <iostream> 

 2  #include <graph.h> 

 3  #include <bfs.h> 

 4  

 5  using namespace NEGRO; 

 6  using namespace std; 

 7  

 8  typedef Graph<int,int> TestGraph; 

 9  

 10  int gcd(int a,int b) {int c; while((c=a%b)) {a=b;b=c;} ; return b;} 

 11  

 12  int main() 

 13  { 

 14  TestGraph G; 

 15  

 16  TestGraph::NodeIterator tn,n2; 

 17  

[8]  18  cout << "Create nodes\n"; 

 19  

 20  for(int i=1;i<=500;i++) 

[6]  21  { 

 22  *(tn=G.AddNode())=i; 

 23  if(i==2) n2=tn; 

 24  } 

 25  

[8]  26  cout << "Create Edges\n"; 

 27  

[6]  28  for(TestGraph::NodeIterator n(G);n.isValid();++n) 

[8]  29  for(TestGraph::NodeIterator m(G);m.isValid();++m) if(n!=m) 

[6]  30  if(gcd(*n,*m)>1) G.AddEdge(n,m); 

 31  

[8]  32  

 33  cout << "Run BFS\n"; 

 34  

[6]  35  Bfs<default_bfs_T<TestGraph> > bfs; 

 36  

 37  bfs.SetG(G); 

 38  bfs.Init(n2); 

 39  bfs.Run(); 

 40  

 41  for(TestGraph::NodeIterator n(G);n.isValid();++n) 

[8]  42  if((*n)!=2) 

 43  cout << (Get(bfs.dist_map,n)) << '\n'; 

[6]  44  

[8]  45  for(TestGraph::NodeIterator n(G);n.isValid();++n) 

 46  if(Get(bfs.dist_map,n)) 

 47  cout << *(Get(bfs.tree_map,n).From()) << ">" 

 48  << *(Get(bfs.tree_map,n).To()) 

 49  << '\n'; 

[6]  50  } 

Note: See
TracBrowser
for help on using the repository browser.