[Lemon-commits] [lemon_svn] alpar: r1660 - in hugo/trunk/src: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:46:50 CET 2006


Author: alpar
Date: Mon Mar 21 12:40:08 2005
New Revision: 1660

Modified:
   hugo/trunk/src/lemon/dfs.h
   hugo/trunk/src/test/dfs_test.cc

Log:
Several serious bugs fixed

Modified: hugo/trunk/src/lemon/dfs.h
==============================================================================
--- hugo/trunk/src/lemon/dfs.h	(original)
+++ hugo/trunk/src/lemon/dfs.h	Mon Mar 21 12:40:08 2005
@@ -525,7 +525,8 @@
 	_pred->set(m,e);
 	_reached->set(m,true);
 	//	  _pred_node->set(m,G->source(e));
-	_stack[++_stack_head] = OutEdgeIt(*G, m);
+	++_stack_head;
+	_stack[_stack_head] = OutEdgeIt(*G, m);
 	_dist->set(m,_stack_head);
       }
       else {
@@ -587,7 +588,8 @@
     ///
     void start(Node dest)
     {
-      while ( !emptyQueue() && _queue[_queue_tail]!=dest ) processNextEdge();
+      while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest ) 
+	processNextEdge();
     }
     
     ///Executes the algorithm until a condition is met.
@@ -597,12 +599,14 @@
     ///\pre init() must be called and at least one node should be added
     ///with addSource() before using this function.
     ///
-    ///\param nm must be a bool (or convertible) node map. The algorithm
-    ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
+    ///\param nm must be a bool (or convertible) edge map. The algorithm
+    ///will stop when it reaches a edge \c v with <tt>nm[v]==true</tt>.
+    ///\warning Contrary to \ref Dfs and \ref Dijkstra, \c mn is an edge map,
+    ///not a node map.
     template<class NM>
       void start(const NM &nm)
       {
-	while ( !emptyQueue() && !nm[_queue[_queue_tail]] ) processNextEdge();
+	while ( !emptyQueue() && !nm[_stack[_stack_head]] ) processNextEdge();
       }
     
     ///Runs %DFS algorithm from node \c s.
@@ -643,7 +647,7 @@
       init();
       addSource(s);
       start(t);
-      return reached(t)?_curr_dist-1+(_queue_tail==_queue_next_dist):0;
+      return reached(t)?_stack_head+1:0;
     }
     
     ///@}

Modified: hugo/trunk/src/test/dfs_test.cc
==============================================================================
--- hugo/trunk/src/test/dfs_test.cc	(original)
+++ hugo/trunk/src/test/dfs_test.cc	Mon Mar 21 12:40:08 2005
@@ -109,7 +109,8 @@
       Node u=G.source(e);
       check(u==dfs_test.predNode(v),"Wrong tree.");
       check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
-	    "Wrong distance." << dfs_test.dist(v) << " " <<dfs_test.dist(u) );
+	    "Wrong distance. (" << dfs_test.dist(u) << "->" 
+	    <<dfs_test.dist(v) << ')');
     }
   }
 }



More information about the Lemon-commits mailing list