[Lemon-commits] [lemon_svn] klao: r323 - hugo/trunk/src/work/klao
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:38:45 CET 2006
Author: klao
Date: Sun Mar 21 18:09:16 2004
New Revision: 323
Modified:
hugo/trunk/src/work/klao/path.h
hugo/trunk/src/work/klao/path_test.cc
Log:
Reszutas konstruktorok
Modified: hugo/trunk/src/work/klao/path.h
==============================================================================
--- hugo/trunk/src/work/klao/path.h (original)
+++ hugo/trunk/src/work/klao/path.h Sun Mar 21 18:09:16 2004
@@ -10,6 +10,7 @@
#define HUGO_PATH_H
#include <deque>
+#include <algorithm>
#include <invalid.h>
@@ -39,10 +40,13 @@
Path(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {}
- /// Subpath defined by two nodes
- Path(Path const& P, NodeIt a, NodeIt b) { FIXME; }
- /// Subpath defined by tow edges. Contains edges in [a,b)
- Path(Path const& P, EdgeIt a, EdgeIt b) { FIXME; }
+ /// Subpath defined by two nodes.
+ /// Nodes may be in reversed order, then
+ /// we contstruct the reversed path.
+ Path(const Path &P, const NodeIt &a, const NodeIt &b);
+ /// Subpath defined by two edges. Contains edges in [a,b)
+ /// It is an error if the two edges are not in order!
+ Path(const Path &P, const EdgeIt &a, const EdgeIt &b);
size_t length() const { return edges.size(); }
GraphNode from() const { return _first; }
@@ -71,6 +75,11 @@
bool isForward(const EdgeIt &e) const { return e.forw; }
+ /// index of a node on the path. Returns length+2 for the invalid NodeIt
+ int index(const NodeIt &n) const { return n.idx; }
+ /// index of an edge on the path. Returns length+1 for the invalid EdgeIt
+ int index(const EdgeIt &e) const { return e.it - edges.begin(); }
+
EdgeIt& next(EdgeIt &e) const;
NodeIt& next(NodeIt &n) const;
template <typename It>
@@ -122,7 +131,7 @@
friend class Path;
friend class EdgeIt;
- int idx;
+ size_t idx;
bool tail; // Is this node the tail of the edge with same idx?
public:
@@ -301,6 +310,7 @@
n.idx = e.it-edges.begin();
n.tail = e.forw;
+ return n;
}
template<typename Gr>
@@ -377,6 +387,43 @@
return n;
}
+ // Reszut konstruktorok:
+
+
+ template<typename Gr>
+ Path<Gr>::Path(const Path &P, const EdgeIt &a, const EdgeIt &b) :
+ G(P.G), edges(a.it, b.it) // WARNING: if b.it < a.it this will blow up!
+ {
+ if( G.valid(P._first) && a.it < P.edges.end() ) {
+ _first = ( a.forw ? G.tail(*a.it) : G.head(*a.it) );
+ if( b.it < P.edges.end() ) {
+ _last = ( b.forw ? G.tail(*b.it) : G.head(*b.it) );
+ }
+ else {
+ _last = P._last;
+ }
+ }
+ }
+
+
+ template<typename Gr>
+ Path<Gr>::Path(const Path &P, const NodeIt &a, const NodeIt &b) :
+ G(P.G)
+ {
+ if( !P.valid(a) || !P.valid(b) )
+ return;
+
+ int ai = a.idx, bi = b.idx;
+ if( bi<ai )
+ swap(ai,bi);
+
+ edges.resize(bi-ai);
+ copy(P.edges.begin()+ai, P.edges.begin()+bi, edges.begin());
+
+ _first = P.graphNode(a);
+ _last = P.graphNode(b);
+ }
+
} // namespace hugo
Modified: hugo/trunk/src/work/klao/path_test.cc
==============================================================================
--- hugo/trunk/src/work/klao/path_test.cc (original)
+++ hugo/trunk/src/work/klao/path_test.cc Sun Mar 21 18:09:16 2004
@@ -109,6 +109,70 @@
check(P.isForward(e));
}
+ {
+ cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
+ LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
+
+ cout << "P2.length() == " << P2.length() << endl;
+ check(P2.length() == 2);
+
+ cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
+ check(P2.from() == v1);
+ cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
+ check(P2.to() == v3);
+ }
+ {
+ cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
+ LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
+
+ cout << "P2.length() == " << P2.length() << endl;
+ check(P2.length() == 5);
+
+ cout << "P2.from()==s ? " << (P2.from()==s) << endl;
+ check(P2.from() == s);
+ cout << "P2.to()==t ? " << (P2.to()==t) << endl;
+ check(P2.to() == t);
+ }
+
+ {
+ cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
+ << endl;
+ LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
+
+ cout << "P2.length() == " << P2.length() << endl;
+ check(P2.length() == 2);
+
+ cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
+ check(P2.from() == v1);
+ cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
+ check(P2.to() == v3);
+ }
+ {
+ cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
+ << endl;
+ LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
+
+ cout << "P2.length() == " << P2.length() << endl;
+ check(P2.length() == 0);
+
+ cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
+ check(P2.from() == v3);
+ cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
+ check(P2.to() == v3);
+ }
+ {
+ cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
+ << endl;
+ LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
+
+ cout << "P2.length() == " << P2.length() << endl;
+ check(P2.length() == 5);
+
+ cout << "P2.from()==t ? " << (P2.from()==t) << endl;
+ check(P2.from() == t);
+ cout << "P2.to()==s ? " << (P2.to()==s) << endl;
+ check(P2.to() == s);
+ }
cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
More information about the Lemon-commits
mailing list