COIN-OR::LEMON - Graph Library

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


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

Location:
src/work/klao
Files:
2 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
  • src/work/klao/path_test.cc

    r225 r226  
    110110  }
    111111
     112  {
     113    cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
     114    LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
     115
     116    cout << "P2.length() == " << P2.length() << endl;
     117    check(P2.length() == 2);
     118   
     119    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
     120    check(P2.from() == v1);
     121    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
     122    check(P2.to() == v3);
     123  }
     124  {
     125    cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
     126    LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
     127
     128    cout << "P2.length() == " << P2.length() << endl;
     129    check(P2.length() == 5);
     130   
     131    cout << "P2.from()==s ? " << (P2.from()==s) << endl;
     132    check(P2.from() == s);
     133    cout << "P2.to()==t ? " << (P2.to()==t) << endl;
     134    check(P2.to() == t);
     135  }
     136
     137  {
     138    cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
     139         << endl;
     140    LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
     141
     142    cout << "P2.length() == " << P2.length() << endl;
     143    check(P2.length() == 2);
     144   
     145    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
     146    check(P2.from() == v1);
     147    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
     148    check(P2.to() == v3);
     149  }
     150  {
     151    cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
     152         << endl;
     153    LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
     154
     155    cout << "P2.length() == " << P2.length() << endl;
     156    check(P2.length() == 0);
     157   
     158    cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
     159    check(P2.from() == v3);
     160    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
     161    check(P2.to() == v3);
     162  }
     163  {
     164    cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
     165         << endl;
     166    LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
     167
     168    cout << "P2.length() == " << P2.length() << endl;
     169    check(P2.length() == 5);
     170   
     171    cout << "P2.from()==t ? " << (P2.from()==t) << endl;
     172    check(P2.from() == t);
     173    cout << "P2.to()==s ? " << (P2.to()==s) << endl;
     174    check(P2.to() == s);
     175  }
    112176
    113177
Note: See TracChangeset for help on using the changeset viewer.