Directed path structure.
authorklao
Wed, 21 Apr 2004 23:47:01 +0000
changeset 369dc9c19f4ca9a
parent 368 0beed7a49063
child 370 5eceadf9316c
Directed path structure.
Proposal for a path building interface.
src/work/klao/path.h
src/work/klao/path_test.cc
     1.1 --- a/src/work/klao/path.h	Wed Apr 21 20:48:00 2004 +0000
     1.2 +++ b/src/work/klao/path.h	Wed Apr 21 23:47:01 2004 +0000
     1.3 @@ -10,17 +10,204 @@
     1.4  #define HUGO_PATH_H
     1.5  
     1.6  #include <deque>
     1.7 +#include <vector>
     1.8  #include <algorithm>
     1.9  
    1.10  #include <invalid.h>
    1.11  
    1.12  namespace hugo {
    1.13  
    1.14 +  template<typename Graph>
    1.15 +  class DirPath {
    1.16 +  public:
    1.17 +    typedef typename Graph::Edge GraphEdge;
    1.18 +    typedef typename Graph::Node GraphNode;
    1.19 +    class NodeIt;
    1.20 +    class EdgeIt;
    1.21 +
    1.22 +  protected:
    1.23 +    const Graph *gr;
    1.24 +    typedef std::vector<GraphEdge> Container;
    1.25 +    Container edges;
    1.26 +
    1.27 +  public:
    1.28 +
    1.29 +    DirPath(const Graph &_G) : gr(&_G) {}
    1.30 +
    1.31 +    /// Subpath defined by two nodes.
    1.32 +    /// It is an error if the two edges are not in order!
    1.33 +    DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b);
    1.34 +    /// Subpath defined by two edges. Contains edges in [a,b)
    1.35 +    /// It is an error if the two edges are not in order!
    1.36 +    DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b);
    1.37 +
    1.38 +    size_t length() const { return edges.size(); }
    1.39 +    bool empty() const { return edges.empty(); }
    1.40 +    GraphNode from() const {
    1.41 +      return empty() ? INVALID : gr->tail(edges[0]);
    1.42 +    }
    1.43 +    GraphNode to() const {
    1.44 +      return empty() ? INVALID : gr->head(edges[length()-1]);
    1.45 +    }
    1.46 +
    1.47 +    template<typename It>
    1.48 +    It& first(It &i) const { return i=It(*this); }
    1.49 +
    1.50 +    template<typename It>
    1.51 +    It& nth(It &i, int n) const { return i=It(*this, n); }
    1.52 +
    1.53 +    template<typename It>
    1.54 +    bool valid(const It &i) const { return i.valid(); }
    1.55 +
    1.56 +    template<typename It>
    1.57 +    It& next(It &e) const { return ++e; }
    1.58 +
    1.59 +    /// \todo !
    1.60 +    NodeIt head(const EdgeIt& e) const;
    1.61 +    NodeIt tail(const EdgeIt& e) const;
    1.62 +
    1.63 +
    1.64 +    /*** Iterator classes ***/
    1.65 +    class EdgeIt {
    1.66 +      friend class DirPath;
    1.67 +
    1.68 +      int idx;
    1.69 +      const DirPath *p;
    1.70 +    public:
    1.71 +      EdgeIt() {}
    1.72 +      EdgeIt(Invalid) : idx(-1), p(0) {}
    1.73 +      EdgeIt(const DirPath &_p, int _idx = 0) :
    1.74 +	idx(_idx), p(&_p) { validate(); }
    1.75 +
    1.76 +      bool valid() const { return idx!=-1; }
    1.77 +
    1.78 +      operator GraphEdge () const {
    1.79 +	return valid() ? p->edges[idx] : INVALID;
    1.80 +      }
    1.81 +      EdgeIt& operator++() { ++idx; validate(); return *this; }
    1.82 +
    1.83 +      bool operator==(const EdgeIt& e) const { return idx==e.idx; }
    1.84 +      bool operator!=(const EdgeIt& e) const { return idx!=e.idx; }
    1.85 +      bool operator<(const EdgeIt& e) const { return idx<e.idx; }
    1.86 +
    1.87 +    private:
    1.88 +      // FIXME: comparison between signed and unsigned...
    1.89 +      // Jo ez igy? Vagy esetleg legyen a length() int?
    1.90 +      void validate() { if( size_t(idx) >= p->length() ) idx=-1; }
    1.91 +    };
    1.92 +
    1.93 +    class NodeIt {
    1.94 +      friend class DirPath;
    1.95 +
    1.96 +      int idx;
    1.97 +      const DirPath *p;
    1.98 +    public:
    1.99 +      NodeIt() {}
   1.100 +      NodeIt(Invalid) : idx(-1), p(0) {}
   1.101 +      NodeIt(const DirPath &_p, int _idx = 0) :
   1.102 +	idx(_idx), p(&_p) { validate(); }
   1.103 +
   1.104 +      bool valid() const { return idx!=-1; }
   1.105 +
   1.106 +      operator const GraphEdge& () const {
   1.107 +	if(idx >= p->length())
   1.108 +	  return p->to();
   1.109 +	else if(idx >= 0)
   1.110 +	  return p->gr->tail(p->edges[idx]);
   1.111 +	else
   1.112 +	  return INVALID;
   1.113 +      }
   1.114 +      NodeIt& operator++() { ++idx; validate(); return *this; }
   1.115 +
   1.116 +      bool operator==(const NodeIt& e) const { return idx==e.idx; }
   1.117 +      bool operator!=(const NodeIt& e) const { return idx!=e.idx; }
   1.118 +      bool operator<(const NodeIt& e) const { return idx<e.idx; }
   1.119 +
   1.120 +    private:
   1.121 +      void validate() { if( size_t(idx) > p->length() ) idx=-1; }
   1.122 +    };
   1.123 +
   1.124 +    friend class Builder;    
   1.125 +    class Builder {
   1.126 +      DirPath &P;
   1.127 +      Container d;
   1.128 +
   1.129 +    public:
   1.130 +      Builder(DirPath &_P) : P(_P) {}
   1.131 +
   1.132 +      bool pushFront(const GraphEdge& e) {
   1.133 +	if( empty() || P.gr->head(e)==from() ) {
   1.134 +	  d.push_back(e);
   1.135 +	  return true;
   1.136 +	}
   1.137 +	return false;
   1.138 +      }
   1.139 +      bool pushBack(const GraphEdge& e) {
   1.140 +	if( empty() || P.gr->tail(e)==to() ) {
   1.141 +	  P.edges.push_back(e);
   1.142 +	  return true;
   1.143 +	}
   1.144 +	return false;
   1.145 +      }
   1.146 +
   1.147 +      void commit() {
   1.148 +	if( !d.empty() ) {
   1.149 +	  P.edges.insert(P.edges.begin(), d.rbegin(), d.rend());
   1.150 +	  d.clear();
   1.151 +	}
   1.152 +      }
   1.153 +
   1.154 +      ~Builder() { commit(); }
   1.155 +
   1.156 +      // FIXME: Hmm, pontosan hogy is kene ezt csinalni?
   1.157 +      // Hogy kenyelmes egy ilyet hasznalni?
   1.158 +      void reserve(size_t r) {
   1.159 +	d.reserve(r);
   1.160 +	P.edges.reserve(P.length()+r);
   1.161 +      }
   1.162 +
   1.163 +    private:
   1.164 +      bool empty() { return d.empty() && P.empty(); }
   1.165 +
   1.166 +      GraphNode from() const {
   1.167 +	if( ! d.empty() )
   1.168 +	  return P.gr->tail(d[d.size()-1]);
   1.169 +	else if( ! P.empty() )
   1.170 +	  return P.gr->tail(P.edges[0]);
   1.171 +	else
   1.172 +	  return INVALID;
   1.173 +      }
   1.174 +      GraphNode to() const {
   1.175 +	if( ! P.empty() )
   1.176 +	  return P.gr->head(P.edges[P.length()-1]);
   1.177 +	else if( ! d.empty() )
   1.178 +	  return P.gr->head(d[0]);
   1.179 +	else
   1.180 +	  return INVALID;
   1.181 +      }
   1.182 +
   1.183 +    };
   1.184 +
   1.185 +  };
   1.186 +
   1.187 +
   1.188 +
   1.189 +
   1.190 +
   1.191 +
   1.192 +
   1.193 +
   1.194 +
   1.195 +
   1.196 +
   1.197 +  /**********************************************************************/
   1.198 +
   1.199 +
   1.200    /* Ennek az allocatorosdinak sokkal jobban utana kene nezni a hasznalata
   1.201       elott. Eleg bonyinak nez ki, ahogyan azokat az STL-ben hasznaljak. */
   1.202  
   1.203    template<typename Graph>
   1.204 -  class Path {
   1.205 +  class DynamicPath {
   1.206  
   1.207    public:
   1.208      typedef typename Graph::Edge GraphEdge;
   1.209 @@ -38,15 +225,15 @@
   1.210  
   1.211    public:
   1.212  
   1.213 -    Path(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {}
   1.214 +    DynamicPath(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {}
   1.215  
   1.216      /// Subpath defined by two nodes.
   1.217      /// Nodes may be in reversed order, then
   1.218      /// we contstruct the reversed path.
   1.219 -    Path(const Path &P, const NodeIt &a, const NodeIt &b);
   1.220 +    DynamicPath(const DynamicPath &P, const NodeIt &a, const NodeIt &b);
   1.221      /// Subpath defined by two edges. Contains edges in [a,b)
   1.222      /// It is an error if the two edges are not in order!
   1.223 -    Path(const Path &P, const EdgeIt &a, const EdgeIt &b);
   1.224 +    DynamicPath(const DynamicPath &P, const EdgeIt &a, const EdgeIt &b);
   1.225      
   1.226      size_t length() const { return edges.size(); }
   1.227      GraphNode from() const { return _first; }
   1.228 @@ -112,7 +299,7 @@
   1.229  
   1.230      /*** Iterator classes ***/
   1.231      class EdgeIt {
   1.232 -      friend class Path;
   1.233 +      friend class DynamicPath;
   1.234  
   1.235        typename Container::const_iterator it;
   1.236        bool forw;
   1.237 @@ -128,8 +315,7 @@
   1.238      };
   1.239  
   1.240      class NodeIt {
   1.241 -      friend class Path;
   1.242 -      friend class EdgeIt;
   1.243 +      friend class DynamicPath;
   1.244  
   1.245        size_t idx;
   1.246        bool tail;  // Is this node the tail of the edge with same idx?
   1.247 @@ -150,8 +336,8 @@
   1.248    };
   1.249  
   1.250    template<typename Gr>
   1.251 -  typename Path<Gr>::EdgeIt&
   1.252 -  Path<Gr>::next(Path::EdgeIt &e) const {
   1.253 +  typename DynamicPath<Gr>::EdgeIt&
   1.254 +  DynamicPath<Gr>::next(DynamicPath::EdgeIt &e) const {
   1.255      if( e.it == edges.end() ) 
   1.256        return e;
   1.257  
   1.258 @@ -169,7 +355,7 @@
   1.259    }
   1.260  
   1.261    template<typename Gr>
   1.262 -  typename Path<Gr>::NodeIt& Path<Gr>::next(NodeIt &n) const {
   1.263 +  typename DynamicPath<Gr>::NodeIt& DynamicPath<Gr>::next(NodeIt &n) const {
   1.264      if( n.idx >= length() ) {
   1.265        // FIXME: invalid
   1.266        n.idx = length()+1;
   1.267 @@ -191,7 +377,7 @@
   1.268    }
   1.269  
   1.270    template<typename Gr>
   1.271 -  bool Path<Gr>::edgeIncident(const GraphEdge &e, const GraphNode &a,
   1.272 +  bool DynamicPath<Gr>::edgeIncident(const GraphEdge &e, const GraphNode &a,
   1.273  			  GraphNode &b) {
   1.274      if( G.tail(e) == a ) {
   1.275        b=G.head(e);
   1.276 @@ -205,7 +391,7 @@
   1.277    }
   1.278  
   1.279    template<typename Gr>
   1.280 -  bool Path<Gr>::connectTwoEdges(const GraphEdge &e,
   1.281 +  bool DynamicPath<Gr>::connectTwoEdges(const GraphEdge &e,
   1.282  			     const GraphEdge &f) {
   1.283      if( edgeIncident(f, G.tail(e), _last) ) {
   1.284        _first = G.head(e);
   1.285 @@ -219,7 +405,7 @@
   1.286    }
   1.287  
   1.288    template<typename Gr>
   1.289 -  bool Path<Gr>::pushFront(const GraphEdge &e) {
   1.290 +  bool DynamicPath<Gr>::pushFront(const GraphEdge &e) {
   1.291      if( G.valid(_first) ) {
   1.292  	if( edgeIncident(e, _first, _first) ) {
   1.293  	  edges.push_front(e);
   1.294 @@ -237,7 +423,7 @@
   1.295    }
   1.296  
   1.297    template<typename Gr>
   1.298 -  bool Path<Gr>::pushBack(const GraphEdge &e) {
   1.299 +  bool DynamicPath<Gr>::pushBack(const GraphEdge &e) {
   1.300      if( G.valid(_last) ) {
   1.301  	if( edgeIncident(e, _last, _last) ) {
   1.302  	  edges.push_back(e);
   1.303 @@ -256,7 +442,7 @@
   1.304  
   1.305  
   1.306    template<typename Gr>
   1.307 -  bool Path<Gr>::setFrom(const GraphNode &n) {
   1.308 +  bool DynamicPath<Gr>::setFrom(const GraphNode &n) {
   1.309      if( G.valid(_first) ) {
   1.310        return _first == n;
   1.311      }
   1.312 @@ -276,7 +462,7 @@
   1.313    }
   1.314  
   1.315    template<typename Gr>
   1.316 -  bool Path<Gr>::setTo(const GraphNode &n) {
   1.317 +  bool DynamicPath<Gr>::setTo(const GraphNode &n) {
   1.318      if( G.valid(_last) ) {
   1.319        return _last == n;
   1.320      }
   1.321 @@ -297,8 +483,8 @@
   1.322  
   1.323  
   1.324    template<typename Gr>
   1.325 -  typename Path<Gr>::NodeIt
   1.326 -  Path<Gr>::tail(const EdgeIt& e) const {
   1.327 +  typename DynamicPath<Gr>::NodeIt
   1.328 +  DynamicPath<Gr>::tail(const EdgeIt& e) const {
   1.329      NodeIt n;
   1.330  
   1.331      if( e.it == edges.end() ) {
   1.332 @@ -314,8 +500,8 @@
   1.333    }
   1.334  
   1.335    template<typename Gr>
   1.336 -  typename Path<Gr>::NodeIt
   1.337 -  Path<Gr>::head(const EdgeIt& e) const {
   1.338 +  typename DynamicPath<Gr>::NodeIt
   1.339 +  DynamicPath<Gr>::head(const EdgeIt& e) const {
   1.340      if( e.it == edges.end()-1 ) {
   1.341        return _last;
   1.342      }
   1.343 @@ -326,8 +512,8 @@
   1.344    }
   1.345        
   1.346    template<typename Gr>
   1.347 -  typename Path<Gr>::GraphEdge
   1.348 -  Path<Gr>::graphEdge(const EdgeIt& e) const {
   1.349 +  typename DynamicPath<Gr>::GraphEdge
   1.350 +  DynamicPath<Gr>::graphEdge(const EdgeIt& e) const {
   1.351      if( e.it != edges.end() ) {
   1.352        return *e.it;
   1.353      }
   1.354 @@ -337,8 +523,8 @@
   1.355    }
   1.356    
   1.357    template<typename Gr>
   1.358 -  typename Path<Gr>::GraphNode
   1.359 -  Path<Gr>::graphNode(const NodeIt& n) const {
   1.360 +  typename DynamicPath<Gr>::GraphNode
   1.361 +  DynamicPath<Gr>::graphNode(const NodeIt& n) const {
   1.362      if( n.idx < length() ) {
   1.363        return n.tail ? G.tail(edges[n.idx]) : G.head(edges[n.idx]);
   1.364      }
   1.365 @@ -351,7 +537,8 @@
   1.366    }
   1.367  
   1.368    template<typename Gr>
   1.369 -  typename Path<Gr>::EdgeIt& Path<Gr>::nth(EdgeIt &e, size_t k) const {
   1.370 +  typename DynamicPath<Gr>::EdgeIt&
   1.371 +  DynamicPath<Gr>::nth(EdgeIt &e, size_t k) const {
   1.372      if( k<0 || k>=length() ) {
   1.373        // FIXME: invalid EdgeIt
   1.374        e.it = edges.end();
   1.375 @@ -371,7 +558,8 @@
   1.376    }
   1.377      
   1.378    template<typename Gr>
   1.379 -  typename Path<Gr>::NodeIt& Path<Gr>::nth(NodeIt &n, size_t k) const {
   1.380 +  typename DynamicPath<Gr>::NodeIt&
   1.381 +  DynamicPath<Gr>::nth(NodeIt &n, size_t k) const {
   1.382      if( k<0 || k>length() ) {
   1.383        // FIXME: invalid NodeIt
   1.384        n.idx = length()+1;
   1.385 @@ -391,7 +579,8 @@
   1.386  
   1.387  
   1.388    template<typename Gr>
   1.389 -  Path<Gr>::Path(const Path &P, const EdgeIt &a, const EdgeIt &b) :
   1.390 +  DynamicPath<Gr>::DynamicPath(const DynamicPath &P, const EdgeIt &a,
   1.391 +			       const EdgeIt &b) :
   1.392      G(P.G), edges(a.it, b.it)    // WARNING: if b.it < a.it this will blow up! 
   1.393    {
   1.394      if( G.valid(P._first) && a.it < P.edges.end() ) {
   1.395 @@ -406,8 +595,8 @@
   1.396    }
   1.397  
   1.398    template<typename Gr>
   1.399 -  Path<Gr>::Path(const Path &P, const NodeIt &a, const NodeIt &b) :
   1.400 -    G(P.G)
   1.401 +  DynamicPath<Gr>::DynamicPath(const DynamicPath &P, const NodeIt &a,
   1.402 +			       const NodeIt &b) : G(P.G)
   1.403    {
   1.404      if( !P.valid(a) || !P.valid(b) )
   1.405        return;
     2.1 --- a/src/work/klao/path_test.cc	Wed Apr 21 20:48:00 2004 +0000
     2.2 +++ b/src/work/klao/path_test.cc	Wed Apr 21 23:47:01 2004 +0000
     2.3 @@ -43,137 +43,206 @@
     2.4  
     2.5    bool rc;
     2.6  
     2.7 -  cout << "Ures path letrehozasa" << endl;
     2.8 -  typedef Path<ListGraph> LPath;
     2.9 -  LPath P(G);
    2.10 +  {
    2.11 +    cout << "DynamicPath tesztelese...\n";
    2.12  
    2.13 -  cout << "P.length() == " << P.length() << endl;
    2.14 -  check(P.length() == 0);
    2.15 +    cout << "Ures path letrehozasa" << endl;
    2.16 +    typedef DynamicPath<ListGraph> LPath;
    2.17 +    LPath P(G);
    2.18  
    2.19 -  cout << "P.from() valid? " << G.valid(P.from()) << endl;
    2.20 -  check(! G.valid(P.from()));
    2.21 +    cout << "P.length() == " << P.length() << endl;
    2.22 +    check(P.length() == 0);
    2.23  
    2.24 -  cout << "Hozzaadunk ket elet..." << endl;
    2.25 -  check(P.pushBack(e1));
    2.26 -  check(P.pushBack(e3));
    2.27 -  cout << "P.length() == " << P.length() << endl;
    2.28 -  check(P.length() == 2);
    2.29 +    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    2.30 +    check(! G.valid(P.from()));
    2.31  
    2.32 -  cout << "P.from() valid? " << G.valid(P.from()) << endl;
    2.33 -  check(G.valid(P.from()));
    2.34 +    cout << "Hozzaadunk ket elet..." << endl;
    2.35 +    check(P.pushBack(e1));
    2.36 +    check(P.pushBack(e3));
    2.37 +    cout << "P.length() == " << P.length() << endl;
    2.38 +    check(P.length() == 2);
    2.39 +
    2.40 +    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    2.41 +    check(G.valid(P.from()));
    2.42    
    2.43 -  cout << "P.from()==s ? " << (P.from()==s) << endl;
    2.44 -  check(P.from() == s);
    2.45 +    cout << "P.from()==s ? " << (P.from()==s) << endl;
    2.46 +    check(P.from() == s);
    2.47  
    2.48 -  cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
    2.49 -  rc = P.pushBack(e8);
    2.50 -  cout << "Sukerult: " << rc << endl;
    2.51 -  check(!rc);
    2.52 +    cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
    2.53 +    rc = P.pushBack(e8);
    2.54 +    cout << "Sukerult: " << rc << endl;
    2.55 +    check(!rc);
    2.56  
    2.57 -  cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
    2.58 -  check(P.pushBack(e6));
    2.59 -  check(P.pushBack(e8));
    2.60 -  check(P.pushBack(e10));
    2.61 +    cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
    2.62 +    check(P.pushBack(e6));
    2.63 +    check(P.pushBack(e8));
    2.64 +    check(P.pushBack(e10));
    2.65  
    2.66 -  cout << "P.length() == " << P.length() << endl;
    2.67 -  check(P.length() == 5);
    2.68 +    cout << "P.length() == " << P.length() << endl;
    2.69 +    check(P.length() == 5);
    2.70  
    2.71 -  cout << "P.from()==s ? " << (P.from()==s) << endl;
    2.72 -  check(P.from() == s);
    2.73 -  cout << "P.to()==t ? " << (P.to()==t) << endl;
    2.74 -  check(P.to() == t);
    2.75 +    cout << "P.from()==s ? " << (P.from()==s) << endl;
    2.76 +    check(P.from() == s);
    2.77 +    cout << "P.to()==t ? " << (P.to()==t) << endl;
    2.78 +    check(P.to() == t);
    2.79  
    2.80 -  cout << "Vegpont bellitasa: " << endl;
    2.81 -  rc = P.setTo(v2);
    2.82 -  cout << "Hibasra: " << rc << endl;
    2.83 -  check(!rc);
    2.84 -  rc = P.setTo(t);
    2.85 -  cout << "Helyesre: " << rc << endl;
    2.86 -  check(rc);
    2.87 +    cout << "Vegpont bellitasa: " << endl;
    2.88 +    rc = P.setTo(v2);
    2.89 +    cout << "Hibasra: " << rc << endl;
    2.90 +    check(!rc);
    2.91 +    rc = P.setTo(t);
    2.92 +    cout << "Helyesre: " << rc << endl;
    2.93 +    check(rc);
    2.94  
    2.95 -  cout << "Elek iranyitasanak ellenorzese." << endl;
    2.96 -  cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
    2.97 -  check(G.tail(e1)==s);
    2.98 +    cout << "Elek iranyitasanak ellenorzese." << endl;
    2.99 +    cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
   2.100 +    check(G.tail(e1)==s);
   2.101  
   2.102 -  cout << "Vegigiteralunk az eleken." << endl;
   2.103 -  typedef LPath::NodeIt NodeIt;
   2.104 -  typedef LPath::EdgeIt EdgeIt;
   2.105 -  EdgeIt e = P.first<EdgeIt>();
   2.106 -  int i=1;
   2.107 -  for(; P.valid(e); P.next(e), ++i) {
   2.108 -    cout << i << ". el: " << P.graphEdge(e)
   2.109 -	 << ", elore el? " << P.isForward(e) << endl;
   2.110 -    if(i>=3 && i<5) 
   2.111 -      check(!P.isForward(e));
   2.112 -    else
   2.113 -      check(P.isForward(e));
   2.114 +    cout << "Vegigiteralunk az eleken." << endl;
   2.115 +    typedef LPath::NodeIt NodeIt;
   2.116 +    typedef LPath::EdgeIt EdgeIt;
   2.117 +    EdgeIt e = P.first<EdgeIt>();
   2.118 +    int i=1;
   2.119 +    for(; P.valid(e); P.next(e), ++i) {
   2.120 +      cout << i << ". el: " << P.graphEdge(e)
   2.121 +	   << ", elore el? " << P.isForward(e) << endl;
   2.122 +      if(i>=3 && i<5) 
   2.123 +	check(!P.isForward(e));
   2.124 +      else
   2.125 +	check(P.isForward(e));
   2.126 +    }
   2.127 +
   2.128 +    {
   2.129 +      cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
   2.130 +      LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
   2.131 +
   2.132 +      cout << "P2.length() == " << P2.length() << endl;
   2.133 +      check(P2.length() == 2);
   2.134 +    
   2.135 +      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   2.136 +      check(P2.from() == v1);
   2.137 +      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.138 +      check(P2.to() == v3);
   2.139 +    }
   2.140 +    {
   2.141 +      cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
   2.142 +      LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
   2.143 +
   2.144 +      cout << "P2.length() == " << P2.length() << endl;
   2.145 +      check(P2.length() == 5);
   2.146 +    
   2.147 +      cout << "P2.from()==s ? " << (P2.from()==s) << endl;
   2.148 +      check(P2.from() == s);
   2.149 +      cout << "P2.to()==t ? " << (P2.to()==t) << endl;
   2.150 +      check(P2.to() == t);
   2.151 +    }
   2.152 +
   2.153 +    {
   2.154 +      cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
   2.155 +	   << endl;
   2.156 +      LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
   2.157 +
   2.158 +      cout << "P2.length() == " << P2.length() << endl;
   2.159 +      check(P2.length() == 2);
   2.160 +    
   2.161 +      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   2.162 +      check(P2.from() == v1);
   2.163 +      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.164 +      check(P2.to() == v3);
   2.165 +    }
   2.166 +    {
   2.167 +      cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
   2.168 +	   << endl;
   2.169 +      LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
   2.170 +
   2.171 +      cout << "P2.length() == " << P2.length() << endl;
   2.172 +      check(P2.length() == 0);
   2.173 +    
   2.174 +      cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
   2.175 +      check(P2.from() == v3);
   2.176 +      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.177 +      check(P2.to() == v3);
   2.178 +    }
   2.179 +    {
   2.180 +      cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
   2.181 +	   << endl;
   2.182 +      LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
   2.183 +
   2.184 +      cout << "P2.length() == " << P2.length() << endl;
   2.185 +      check(P2.length() == 5);
   2.186 +    
   2.187 +      cout << "P2.from()==t ? " << (P2.from()==t) << endl;
   2.188 +      check(P2.from() == t);
   2.189 +      cout << "P2.to()==s ? " << (P2.to()==s) << endl;
   2.190 +      check(P2.to() == s);
   2.191 +    }
   2.192 +
   2.193    }
   2.194  
   2.195    {
   2.196 -    cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
   2.197 -    LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
   2.198 +    cout << "\n\n\nDirPath tesztelese...\n";
   2.199  
   2.200 -    cout << "P2.length() == " << P2.length() << endl;
   2.201 -    check(P2.length() == 2);
   2.202 +
   2.203 +    cout << "Ures path letrehozasa" << endl;
   2.204 +    typedef DirPath<ListGraph> DPath;
   2.205 +    DPath P(G);
   2.206 +
   2.207 +    cout << "P.length() == " << P.length() << endl;
   2.208 +    check(P.length() == 0);
   2.209 +
   2.210 +    cout << "P.from() valid? " << G.valid(P.from()) << endl;
   2.211 +    check(! G.valid(P.from()));
   2.212 +
   2.213 +    {
   2.214 +      cout << "Builder objektum letrehozasa" << endl;
   2.215 +      DPath::Builder B(P);
   2.216 +
   2.217 +      cout << "Hozzaadunk az elejehez ket elet..." << endl;
   2.218 +      check(B.pushFront(e6));
   2.219 +      check(B.pushFront(e5));
   2.220 +      cout << "P.length() == " << P.length() << endl;
   2.221 +      check(P.length() == 0);
   2.222 +      
   2.223 +      cout << "Commitolunk..." << endl;
   2.224 +      B.commit();
   2.225 +
   2.226 +      cout << "P.length() == " << P.length() << endl;
   2.227 +      check(P.length() == 2);
   2.228 +      cout << "P.from() valid? " << G.valid(P.from()) << endl;
   2.229 +      check(G.valid(P.from()));
   2.230 +      cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
   2.231 +      check(P.from() == v1);
   2.232 +
   2.233 +      cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   2.234 +      check(!B.pushFront(e3));
   2.235      
   2.236 -    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   2.237 -    check(P2.from() == v1);
   2.238 -    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.239 -    check(P2.to() == v3);
   2.240 +      cout << "Hozzaadunk a vegehez ket elet..." << endl;
   2.241 +      check(B.pushBack(e7));
   2.242 +      check(B.pushBack(e8));
   2.243 +      cout << "P.length() == " << P.length() << endl;
   2.244 +      check(P.length() == 4);
   2.245 +
   2.246 +      cout << "Hozzaadunk az elejehez meg egy elet..." << endl;
   2.247 +      check(B.pushFront(e4));
   2.248 +      cout << "P.length() == " << P.length() << endl;
   2.249 +      check(P.length() == 4);
   2.250 +      
   2.251 +      cout << "Es megvarjuk, amig megszunik a Builder...\n";
   2.252 +    }
   2.253 +    cout << "P.length() == " << P.length() << endl;
   2.254 +    check(P.length() == 5);
   2.255 +    cout << "P.from()==v2 ? " << (P.from()==v2) << endl;
   2.256 +    check(P.from() == v2);
   2.257 +
   2.258 +    cout << "Vegigiteralunk az eleken." << endl;
   2.259 +    typedef DPath::NodeIt NodeIt;
   2.260 +    typedef DPath::EdgeIt EdgeIt;
   2.261 +    EdgeIt e;
   2.262 +    int i=1;
   2.263 +    for(P.first(e); P.valid(e); P.next(e), ++i) {
   2.264 +      cout << i << ". el: " << e << endl;
   2.265 +    }
   2.266    }
   2.267 -  {
   2.268 -    cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
   2.269 -    LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
   2.270 -
   2.271 -    cout << "P2.length() == " << P2.length() << endl;
   2.272 -    check(P2.length() == 5);
   2.273 -    
   2.274 -    cout << "P2.from()==s ? " << (P2.from()==s) << endl;
   2.275 -    check(P2.from() == s);
   2.276 -    cout << "P2.to()==t ? " << (P2.to()==t) << endl;
   2.277 -    check(P2.to() == t);
   2.278 -  }
   2.279 -
   2.280 -  {
   2.281 -    cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
   2.282 -	 << endl;
   2.283 -    LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
   2.284 -
   2.285 -    cout << "P2.length() == " << P2.length() << endl;
   2.286 -    check(P2.length() == 2);
   2.287 -    
   2.288 -    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   2.289 -    check(P2.from() == v1);
   2.290 -    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.291 -    check(P2.to() == v3);
   2.292 -  }
   2.293 -  {
   2.294 -    cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
   2.295 -	 << endl;
   2.296 -    LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
   2.297 -
   2.298 -    cout << "P2.length() == " << P2.length() << endl;
   2.299 -    check(P2.length() == 0);
   2.300 -    
   2.301 -    cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
   2.302 -    check(P2.from() == v3);
   2.303 -    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   2.304 -    check(P2.to() == v3);
   2.305 -  }
   2.306 -  {
   2.307 -    cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
   2.308 -	 << endl;
   2.309 -    LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
   2.310 -
   2.311 -    cout << "P2.length() == " << P2.length() << endl;
   2.312 -    check(P2.length() == 5);
   2.313 -    
   2.314 -    cout << "P2.from()==t ? " << (P2.from()==t) << endl;
   2.315 -    check(P2.from() == t);
   2.316 -    cout << "P2.to()==s ? " << (P2.to()==s) << endl;
   2.317 -    check(P2.to() == s);
   2.318 -  }
   2.319 -
   2.320  
   2.321    cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   2.322         << endl;