COIN-OR::LEMON - Graph Library

Changeset 226:616bc397c83a in lemon-0.x for src/work/klao/path.h


Ignore:
Timestamp:
03/21/04 18:09:16 (20 years ago)
Author:
Mihaly Barasz
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@323
Message:

Reszutas konstruktorok

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/klao/path.h

    r225 r226  
    1111
    1212#include <deque>
     13#include <algorithm>
    1314
    1415#include <invalid.h>
     
    4041    Path(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {}
    4142
    42     /// Subpath defined by two nodes
    43     Path(Path const& P, NodeIt a, NodeIt b) { FIXME; }
    44     /// Subpath defined by tow edges. Contains edges in [a,b)
    45     Path(Path const& P, EdgeIt a, EdgeIt b) { FIXME; }
     43    /// Subpath defined by two nodes.
     44    /// Nodes may be in reversed order, then
     45    /// we contstruct the reversed path.
     46    Path(const Path &P, const NodeIt &a, const NodeIt &b);
     47    /// Subpath defined by two edges. Contains edges in [a,b)
     48    /// It is an error if the two edges are not in order!
     49    Path(const Path &P, const EdgeIt &a, const EdgeIt &b);
    4650   
    4751    size_t length() const { return edges.size(); }
     
    7175
    7276    bool isForward(const EdgeIt &e) const { return e.forw; }
     77
     78    /// index of a node on the path. Returns length+2 for the invalid NodeIt
     79    int index(const NodeIt &n) const { return n.idx; }
     80    /// index of an edge on the path. Returns length+1 for the invalid EdgeIt
     81    int index(const EdgeIt &e) const { return e.it - edges.begin(); }
    7382
    7483    EdgeIt& next(EdgeIt &e) const;
     
    123132      friend class EdgeIt;
    124133
    125       int idx;
     134      size_t idx;
    126135      bool tail;  // Is this node the tail of the edge with same idx?
    127136
     
    302311    n.idx = e.it-edges.begin();
    303312    n.tail = e.forw;
     313    return n;
    304314  }
    305315
     
    378388  }
    379389
     390  // Reszut konstruktorok:
     391
     392
     393  template<typename Gr>
     394  Path<Gr>::Path(const Path &P, const EdgeIt &a, const EdgeIt &b) :
     395    G(P.G), edges(a.it, b.it)    // WARNING: if b.it < a.it this will blow up!
     396  {
     397    if( G.valid(P._first) && a.it < P.edges.end() ) {
     398      _first = ( a.forw ? G.tail(*a.it) : G.head(*a.it) );
     399      if( b.it < P.edges.end() ) {
     400        _last = ( b.forw ? G.tail(*b.it) : G.head(*b.it) );
     401      }
     402      else {
     403        _last = P._last;
     404      }
     405    }
     406  }
     407
     408
     409  template<typename Gr>
     410  Path<Gr>::Path(const Path &P, const NodeIt &a, const NodeIt &b) :
     411    G(P.G)
     412  {
     413    if( !P.valid(a) || !P.valid(b) )
     414      return;
     415
     416    int ai = a.idx, bi = b.idx;
     417    if( bi<ai )
     418      swap(ai,bi);
     419   
     420    edges.resize(bi-ai);
     421    copy(P.edges.begin()+ai, P.edges.begin()+bi, edges.begin());
     422
     423    _first = P.graphNode(a);
     424    _last = P.graphNode(b);
     425  }
     426
    380427
    381428} // namespace hugo
Note: See TracChangeset for help on using the changeset viewer.