src/work/bfsdemo.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/bfsdemo.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,128 +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 -class IGraph 
    1.12 -{
    1.13 -public:
    1.14 -
    1.15 -  //  struct NodeType {bfs_node_data<TestGraph> bfs;};
    1.16 -  struct NodeType {bool isVis;};
    1.17 -
    1.18 -  vector<NodeType> nodes;
    1.19 -  
    1.20 -  class NodeIterator 
    1.21 -  {
    1.22 -  public:
    1.23 -    IGraph *G;
    1.24 -    int n;
    1.25 -    NodeIterator &operator ++() { n++; return *this;}
    1.26 -    NodeType &operator *() const { return G->nodes[n];}
    1.27 -    NodeType *operator ->() const { return &(G->nodes[n]);}
    1.28 -    bool isValid() const {return n<=5000;}
    1.29 -    int Index() {return n;} //csak a kiirashoz kell
    1.30 -
    1.31 -    NodeIterator() {}
    1.32 -    NodeIterator(IGraph &Gr) {G=&Gr;n=1;} //Bfs class prefer this.
    1.33 -  };
    1.34 -  
    1.35 -  void GetFirst(NodeIterator &i) {i.G=this;i.n=1;}
    1.36 -
    1.37 -  class OutEdgeIterator 
    1.38 -  {    
    1.39 -  public:
    1.40 -    IGraph *G;
    1.41 -    int f,t;
    1.42 -    int gcd() { int a=f;int b=t;int c;while((c=a%b)) {a=b;b=c;} ; return b;}
    1.43 -    OutEdgeIterator &operator ++() {while(++t<=5000&&gcd()==1);return *this;}
    1.44 -    bool isValid() const {return t<=5000;}
    1.45 -    NodeIterator From() const {NodeIterator i; i.G=G;i.n=f;return i;}
    1.46 -    NodeIterator To() const {NodeIterator i; i.G=G;i.n=t;return i;}
    1.47 -    NodeIterator Anode() const {return From();}
    1.48 -    NodeIterator Bnode() const {return To();}
    1.49 -
    1.50 -    OutEdgeIterator() {}
    1.51 -    OutEdgeIterator(IGraph &Gr,NodeIterator &n)  //Bfs class prefer this.
    1.52 -    {G=&Gr;f=n.n;t=0;operator++();}
    1.53 -  };
    1.54 -
    1.55 -  typedef OutEdgeIterator EdgeIterator;
    1.56 -  void GetFirst(OutEdgeIterator &i,const NodeIterator &n)
    1.57 -  {i.G=this;i.f=n.n;i.t=0;++i;}
    1.58 -
    1.59 -  IGraph() : nodes(5001) {}
    1.60 -};
    1.61 -
    1.62 -class IMaps_t
    1.63 -{
    1.64 -public:
    1.65 -//     class_element_map<IGraph::NodeIterator,
    1.66 -//   		    IGraph::NodeType,
    1.67 -//   		    bool,
    1.68 -//   		    &IGraph::NodeType::isVis> visited;
    1.69 -  struct _visited_map_t {
    1.70 -    typedef bool value_type;
    1.71 -    void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
    1.72 -    value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
    1.73 -    void SetG(IGraph &G) {}
    1.74 -  } visited;
    1.75 -  struct _tree_map_t {
    1.76 -    typedef IGraph::EdgeIterator value_type;
    1.77 -    void Put(const IGraph::NodeIterator &n,const value_type &t)
    1.78 -    { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
    1.79 -    void SetG(IGraph &G) {}
    1.80 -  } tree;
    1.81 -  do_nothing_map dist;   //node->int (W)
    1.82 -  do_nothing_map priority; //node->int (W)
    1.83 -};
    1.84 -
    1.85 -// New style bfs traits
    1.86 -class BFS_T 
    1.87 -{
    1.88 -public:
    1.89 -
    1.90 -  typedef IGraph Graph;
    1.91 -  typedef IGraph::OutEdgeIterator SearchEdgeIterator;
    1.92 -  
    1.93 -  struct visited_map_t {
    1.94 -    typedef bool value_type;
    1.95 -    void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
    1.96 -    value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
    1.97 -    void SetG(IGraph &G) {}
    1.98 -  };
    1.99 -  struct tree_map_t {
   1.100 -    typedef IGraph::EdgeIterator value_type;
   1.101 -    void Put(const IGraph::NodeIterator &n,const value_type &t)
   1.102 -    { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
   1.103 -    void SetG(IGraph &G) {}
   1.104 -  };
   1.105 -  typedef do_nothing_map dist_map_t;   //node->int (W)
   1.106 -  typedef do_nothing_map priority_map_t; //node->int (W)
   1.107 -};
   1.108 -
   1.109 -
   1.110 -int main()
   1.111 -{
   1.112 -  IGraph IG;
   1.113 -
   1.114 -//   //Function-syte calling
   1.115 -//   IMaps_t IMaps;
   1.116 -
   1.117 -//   IGraph::NodeIterator in;
   1.118 -//   IG.GetFirst(in);
   1.119 -//   ++in;
   1.120 -//   bfs_fn(IG,in,IMaps);  
   1.121 -
   1.122 -  //Class-style calling:
   1.123 -  
   1.124 -  IGraph::NodeIterator in;
   1.125 -  IG.GetFirst(in);
   1.126 -  ++in;
   1.127 -  Bfs<BFS_T> bfs;
   1.128 -  bfs.SetG(IG);
   1.129 -  bfs.Init(in);
   1.130 -  bfs.Run();
   1.131 -}