src/work/bfsdemo2.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/bfsdemo2.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,50 +0,0 @@
     1.4 -#include <iostream>
     1.5 -#include <graph.h>
     1.6 -#include <bfs.h>
     1.7 -
     1.8 -using namespace NEGRO;
     1.9 -using namespace std;
    1.10 -
    1.11 -typedef Graph<int,int> TestGraph;
    1.12 -
    1.13 -int gcd(int a,int b) {int c; while((c=a%b)) {a=b;b=c;} ; return b;}
    1.14 -
    1.15 -int main()
    1.16 -{
    1.17 -  TestGraph G;
    1.18 -  
    1.19 -  TestGraph::NodeIterator tn,n2;
    1.20 -  
    1.21 -  cout << "Create nodes\n";
    1.22 -
    1.23 -  for(int i=1;i<=500;i++)
    1.24 -    {
    1.25 -      *(tn=G.AddNode())=i;
    1.26 -      if(i==2) n2=tn;
    1.27 -    }
    1.28 -  
    1.29 -  cout << "Create Edges\n";
    1.30 -  
    1.31 -  for(TestGraph::NodeIterator n(G);n.isValid();++n)
    1.32 -    for(TestGraph::NodeIterator m(G);m.isValid();++m) if(n!=m)
    1.33 -      if(gcd(*n,*m)>1) G.AddEdge(n,m);
    1.34 -  
    1.35 -  
    1.36 -  cout << "Run BFS\n";
    1.37 -
    1.38 -  Bfs<default_bfs_T<TestGraph> > bfs;
    1.39 -
    1.40 -  bfs.SetG(G);
    1.41 -  bfs.Init(n2);
    1.42 -  bfs.Run();
    1.43 -
    1.44 -  for(TestGraph::NodeIterator n(G);n.isValid();++n)
    1.45 -    if((*n)!=2)
    1.46 -      cout << (Get(bfs.dist_map,n)) << '\n';
    1.47 -
    1.48 -  for(TestGraph::NodeIterator n(G);n.isValid();++n)
    1.49 -    if(Get(bfs.dist_map,n))
    1.50 -      cout << *(Get(bfs.tree_map,n).From()) << "->"
    1.51 -	   << *(Get(bfs.tree_map,n).To())
    1.52 -	   << '\n';
    1.53 -}