COIN-OR::LEMON - Graph Library

Changeset 777:a82713ed19f3 in lemon-0.x for src/work/marci/bfs_dfs.h


Ignore:
Timestamp:
08/31/04 19:54:22 (20 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1070
Message:

graph_wrapper.h is ready for hugo 0.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/marci/bfs_dfs.h

    r774 r777  
    2828  protected:
    2929    typedef typename Graph::Node Node;
     30    typedef typename Graph::Edge Edge;
    3031    typedef typename Graph::OutEdgeIt OutEdgeIt;
    3132    const Graph* graph;
     
    3334    ReachedMap& reached;
    3435    bool b_node_newly_reached;
    35     OutEdgeIt actual_edge;
     36    Edge actual_edge;
    3637    bool own_reached_map;
    3738  public:
     
    5657    /// and the first out-edge is processed.
    5758    /// If the queue is not empty, then \c s is simply pushed.
    58     void pushAndSetReached(Node s) {
     59    BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& pushAndSetReached(Node s) {
    5960      reached.set(s, true);
    6061      if (bfs_queue.empty()) {
    6162        bfs_queue.push(s);
    62         graph->first(actual_edge, s);
     63        actual_edge=OutEdgeIt(*graph, s);
     64        //graph->first(actual_edge, s);
    6365        if (actual_edge!=INVALID) {
    6466          Node w=graph->head(actual_edge);
     
    7476        bfs_queue.push(s);
    7577      }
     78      return *this;
    7679    }
    7780    /// As \c BfsIterator<Graph, ReachedMap> works as an edge-iterator,
     
    8083    operator++() {
    8184      if (actual_edge!=INVALID) {
    82         ++actual_edge;
     85        actual_edge=++OutEdgeIt(*graph, actual_edge);
     86        //++actual_edge;
    8387        if (actual_edge!=INVALID) {
    8488          Node w=graph->head(actual_edge);
     
    9498        bfs_queue.pop();
    9599        if (!bfs_queue.empty()) {
    96           graph->first(actual_edge, bfs_queue.front());
     100          actual_edge=OutEdgeIt(*graph, bfs_queue.front());
     101          //graph->first(actual_edge, bfs_queue.front());
    97102          if (actual_edge!=INVALID) {
    98103            Node w=graph->head(actual_edge);
     
    114119    /// to an \c out-edge-iterator.
    115120    ///\bug Edge have to be in HUGO 0.2
    116     operator OutEdgeIt() const { return actual_edge; }
     121    operator Edge() const { return actual_edge; }
    117122    /// Returns if b-node has been reached just now.
    118123    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
     
    120125    bool isANodeExamined() const { return actual_edge==INVALID; }
    121126    /// Returns a-node of the actual edge, so does if the edge is invalid.
    122     Node aNode() const { return bfs_queue.front(); }
     127    Node tail() const { return bfs_queue.front(); }
    123128    /// \pre The actual edge have to be valid.
    124     Node bNode() const { return graph->bNode(actual_edge); }
     129    Node head() const { return graph->head(actual_edge); }
    125130    /// Guess what?
    126131    /// \deprecated
     
    160165    /// in addition its pred is set to be \c INVALID, and dist to \c 0.
    161166    /// if \c s was marked previuosly, then it is simply pushed.
    162     void push(Node s) {
     167    Bfs<Graph, ReachedMap, PredMap, DistMap>& push(Node s) {
    163168      if (this->reached[s]) {
    164169        Parent::pushAndSetReached(s);
     
    168173        dist.set(s, 0);
    169174      }
     175      return *this;
    170176    }
    171177    /// A bfs is processed from \c s.
    172     void run(Node s) {
     178    Bfs<Graph, ReachedMap, PredMap, DistMap>& run(Node s) {
    173179      push(s);
    174180      while (!this->finished()) this->operator++();
     181      return *this;
    175182    }
    176183    /// Beside the bfs iteration, \c pred and \dist are saved in a
     
    180187      if (this->graph->valid(this->actual_edge) && this->b_node_newly_reached)
    181188      {
    182         pred.set(this->bNode(), this->actual_edge);
    183         dist.set(this->bNode(), dist[this->aNode()]);
     189        pred.set(this->head(), this->actual_edge);
     190        dist.set(this->head(), dist[this->tail()]);
    184191      }
    185192      return *this;
     
    202209  protected:
    203210    typedef typename Graph::Node Node;
     211    typedef typename Graph::Edge Edge;
    204212    typedef typename Graph::OutEdgeIt OutEdgeIt;
    205213    const Graph* graph;
    206214    std::stack<OutEdgeIt> dfs_stack;
    207215    bool b_node_newly_reached;
    208     OutEdgeIt actual_edge;
     216    Edge actual_edge;
    209217    Node actual_node;
    210218    ReachedMap& reached;
     
    225233    ~DfsIterator() { if (own_reached_map) delete &reached; }
    226234    /// This method markes s reached and first out-edge is processed.
    227     void pushAndSetReached(Node s) {
     235    DfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& pushAndSetReached(Node s) {
    228236      actual_node=s;
    229237      reached.set(s, true);
    230       OutEdgeIt e;
    231       graph->first(e, s);
     238      OutEdgeIt e(*graph, s);
     239      //graph->first(e, s);
    232240      dfs_stack.push(e);
     241      return *this;
    233242    }
    234243    /// As \c DfsIterator<Graph, ReachedMap> works as an edge-iterator,
     
    237246    operator++() {
    238247      actual_edge=dfs_stack.top();
    239       //actual_node=G.aNode(actual_edge);
    240248      if (actual_edge!=INVALID/*.valid()*/) {
    241249        Node w=graph->head(actual_edge);
    242250        actual_node=w;
    243251        if (!reached[w]) {
    244           OutEdgeIt e;
    245           graph->first(e, w);
     252          OutEdgeIt e(*graph, w);
     253          //graph->first(e, w);
    246254          dfs_stack.push(e);
    247255          reached.set(w, true);
     
    263271    /// to an \c out-edge-iterator.
    264272    ///\bug Edge have to be in HUGO 0.2
    265     operator OutEdgeIt() const { return actual_edge; }
     273    operator Edge() const { return actual_edge; }
    266274    /// Returns if b-node has been reached just now.
    267275    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
     
    269277    bool isANodeExamined() const { return actual_edge==INVALID; }
    270278    /// Returns a-node of the actual edge, so does if the edge is invalid.
    271     Node aNode() const { return actual_node; /*FIXME*/}
     279    Node tail() const { return actual_node; /*FIXME*/}
    272280    /// Returns b-node of the actual edge.
    273281    /// \pre The actual edge have to be valid.
    274     Node bNode() const { return graph->bNode(actual_edge); }
     282    Node head() const { return graph->head(actual_edge); }
    275283    /// Guess what?
    276284    /// \deprecated
     
    305313    /// in addition its pred is set to be \c INVALID.
    306314    /// if \c s was marked previuosly, then it is simply pushed.
    307     void push(Node s) {
     315    Dfs<Graph, ReachedMap, PredMap>& push(Node s) {
    308316      if (this->reached[s]) {
    309317        Parent::pushAndSetReached(s);
     
    312320        pred.set(s, INVALID);
    313321      }
     322      return *this;
    314323    }
    315324    /// A bfs is processed from \c s.
    316     void run(Node s) {
     325    Dfs<Graph, ReachedMap, PredMap>& run(Node s) {
    317326      push(s);
    318327      while (!this->finished()) this->operator++();
     328      return *this;
    319329    }
    320330    /// Beside the dfs iteration, \c pred is saved in a
     
    324334      if (this->graph->valid(this->actual_edge) && this->b_node_newly_reached)
    325335      {
    326         pred.set(this->bNode(), this->actual_edge);
     336        pred.set(this->head(), this->actual_edge);
    327337      }
    328338      return *this;
Note: See TracChangeset for help on using the changeset viewer.