COIN-OR::LEMON - Graph Library

Changeset 4:8009bb5ddd09 in lemon-0.x for src/work/bfsdemo.cc


Ignore:
Timestamp:
12/14/03 16:32:46 (17 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@16
Message:

a 'bfs algorithm class' proposal added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/bfsdemo.cc

    r3 r4  
    2525    bool isValid() const {return n<=5000;}
    2626    int Index() {return n;} //csak a kiirashoz kell
     27
     28    NodeIterator() {}
     29    NodeIterator(IGraph &Gr) {G=&Gr;n=1;} //Bfs class prefer this.
    2730  };
    2831 
     
    4144    NodeIterator Anode() const {return From();}
    4245    NodeIterator Bnode() const {return To();}
     46
     47    OutEdgeIterator() {}
     48    OutEdgeIterator(IGraph &Gr,NodeIterator &n)  //Bfs class prefer this.
     49    {G=&Gr;f=n.n;t=0;operator++();}
    4350  };
    4451
     
    7178};
    7279
     80// New style bfs traits
     81class BFS_T
     82{
     83public:
     84
     85  typedef IGraph Graph_t;
     86  typedef IGraph::OutEdgeIterator SearchEdgeIterator;
     87 
     88  struct visited_map_t {
     89    typedef bool value_type;
     90    void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
     91    value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
     92  };
     93  struct tree_map_t {
     94    typedef IGraph::EdgeIterator value_type;
     95    void Put(const IGraph::NodeIterator &n,const value_type &t)
     96    { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
     97  };
     98  typedef do_nothing_map dist_map_t;   //node->int (W)
     99  typedef do_nothing_map priority_map_t; //node->int (W)
     100};
     101
    73102
    74103int main()
    75104{
    76105  IGraph IG;
    77   IMaps_t IMaps;
    78106
     107//   //Function-syte calling
     108//   IMaps_t IMaps;
     109
     110//   IGraph::NodeIterator in;
     111//   IG.GetFirst(in);
     112//   ++in;
     113//   bfs_fn(IG,in,IMaps); 
     114
     115  //Class-style calling:
     116 
    79117  IGraph::NodeIterator in;
    80118  IG.GetFirst(in);
    81119  ++in;
    82   bfs(IG,in,IMaps); 
     120  Bfs<BFS_T> bfs;
     121  bfs.SetG(IG);
     122  bfs.Init(in);
     123  bfs.Run();
    83124}
Note: See TracChangeset for help on using the changeset viewer.