Index: src/hugo/smart_graph.h
===================================================================
--- src/hugo/smart_graph.h	(revision 753)
+++ src/hugo/smart_graph.h	(revision 774)
@@ -122,10 +122,4 @@
     Node head(Edge e) const { return edges[e.n].head; }
 
-    Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }
-    Node aNode(InEdgeIt e) const { return edges[e.n].head; }
-
-    Node bNode(OutEdgeIt e) const { return edges[e.n].head; }
-    Node bNode(InEdgeIt e) const { return edges[e.n].tail; }
-
     NodeIt& first(NodeIt& v) const { 
       v=NodeIt(*this); return v; }
@@ -137,39 +131,4 @@
       e=InEdgeIt(*this,v); return e; }
 
-//     template< typename It >
-//     It first() const { It e; first(e); return e; }
-
-//     template< typename It >
-//     It first(Node v) const { It e; first(e,v); return e; }
-
-    static bool valid(Edge e) { return e.n!=-1; }
-    static bool valid(Node n) { return n.n!=-1; }
-    
-    ///\deprecated Use
-    ///\code
-    ///  e=INVALID;
-    ///\endcode
-    ///instead.
-    static void setInvalid(Edge &e) { e.n=-1; }
-    ///\deprecated Use
-    ///\code
-    ///  e=INVALID;
-    ///\endcode
-    ///instead.
-    static void setInvalid(Node &n) { n.n=-1; }
-    
-    template <typename It> It getNext(It it) const
-    { It tmp(it); return next(tmp); }
-
-    NodeIt& next(NodeIt& it) const { 
-      it.n=(it.n+2)%(nodes.size()+1)-1; 
-      return it; 
-    }
-    OutEdgeIt& next(OutEdgeIt& it) const
-    { it.n=edges[it.n].next_out; return it; }
-    InEdgeIt& next(InEdgeIt& it) const
-    { it.n=edges[it.n].next_in; return it; }
-    EdgeIt& next(EdgeIt& it) const { --it.n; return it; }
-
     static int id(Node v) { return v.n; }
     static int id(Edge e) { return e.n; }
@@ -198,4 +157,20 @@
     }
 
+    /// Finds an edge between two nodes.
+
+    /// Finds an edge from node \c u to node \c v.
+    ///
+    /// If \c prev is \ref INVALID (this is the default value), then
+    /// It finds the first edge from \c u to \c v. Otherwise it looks for
+    /// the next edge from \c u to \c v after \c prev.
+    /// \return The found edge or INVALID if there is no such an edge.
+    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
+    {
+      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
+      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
+      prev.n=e;
+      return prev;
+    }
+    
     void clear() {nodes.clear();edges.clear();}
 
@@ -219,14 +194,22 @@
       bool operator!=(const Node i) const {return n!=i.n;}
       bool operator<(const Node i) const {return n<i.n;}
+      //      ///Validity check
+      //      operator bool() { return n!=-1; }
     };
     
     class NodeIt : public Node {
+      const SmartGraph *G;
       friend class SmartGraph;
     public:
       NodeIt() : Node() { }
+      NodeIt(const SmartGraph& _G,Node n) : Node(n), G(&_G) { }
       NodeIt(Invalid i) : Node(i) { }
-      NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { }
-      ///\todo Undocumented conversion Node -\> NodeIt.
-      NodeIt(const SmartGraph& G, const Node &n) : Node(n) { }
+      NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { }
+      NodeIt &operator++() {
+	n=(n+2)%(G->nodes.size()+1)-1; 
+	return *this; 
+      }
+//       ///Validity check
+//       operator bool() { return Node::operator bool(); }      
     };
 
@@ -258,11 +241,15 @@
       ///make class \c SymSmartGraph::SymEdgeMap friend of Edge
       int &idref() {return n;}
-      const int &idref() const {return n;}
-    };
+      const int &idref() const {return n;} 
+//       ///Validity check
+//       operator bool() { return n!=-1; }
+   };
     
     class EdgeIt : public Edge {
+      const SmartGraph *G;
       friend class SmartGraph;
     public:
-      EdgeIt(const SmartGraph& G) : Edge(G.edges.size()-1) { }
+      EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { }
+      EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
       EdgeIt (Invalid i) : Edge(i) { }
       EdgeIt() : Edge() { }
@@ -270,22 +257,36 @@
       ///make class \c SymSmartGraph::SymEdgeMap friend of Edge
       int &idref() {return n;}
+      EdgeIt &operator++() { --n; return *this; }
+//       ///Validity check
+//       operator bool() { return Edge::operator bool(); }      
     };
     
     class OutEdgeIt : public Edge {
+      const SmartGraph *G;
       friend class SmartGraph;
     public: 
       OutEdgeIt() : Edge() { }
+      OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
       OutEdgeIt (Invalid i) : Edge(i) { }
 
-      OutEdgeIt(const SmartGraph& G,const Node v)
-	: Edge(G.nodes[v.n].first_out) {}
+      OutEdgeIt(const SmartGraph& _G,const Node v)
+	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
+      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
+//       ///Validity check
+//       operator bool() { return Edge::operator bool(); }      
     };
     
     class InEdgeIt : public Edge {
+      const SmartGraph *G;
       friend class SmartGraph;
     public: 
       InEdgeIt() : Edge() { }
+      InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
       InEdgeIt (Invalid i) : Edge(i) { }
-      InEdgeIt(const SmartGraph& G,Node v) :Edge(G.nodes[v.n].first_in){}
+      InEdgeIt(const SmartGraph& _G,Node v)
+	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
+      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
+//       ///Validity check
+//       operator bool() { return Edge::operator bool(); }      
     };
 
