You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/03/01 19:30:53 UTC

svn commit: r1295725 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java

Author: tn
Date: Thu Mar  1 18:30:53 2012
New Revision: 1295725

URL: http://svn.apache.org/viewvc?rev=1295725&view=rev
Log:
do not visit multiple edges to the same vertex if it has been already visited.

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java?rev=1295725&r1=1295724&r2=1295725&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java Thu Mar  1 18:30:53 2012
@@ -126,23 +126,32 @@ final class DefaultVisitAlgorithmsSelect
 
             if ( e != null )
             {
-                if ( !handler.discoverEdge( prevHead, e, v ) )
+                // if the vertex was already visited, do not discover
+                // another edge leading to the same vertex
+                if ( visitedVertices.contains( v ) ) 
                 {
                     skipVertex = true;
-                }
-
-                if ( handler.finishEdge( prevHead, e, v ) )
+                } 
+                else 
                 {
-                    skipVertex = true;
-                    visitingGraph = false;
+                    if ( !handler.discoverEdge( prevHead, e, v ) )
+                    {
+                        skipVertex = true;
+                    }
+
+                    if ( handler.finishEdge( prevHead, e, v ) )
+                    {
+                        skipVertex = true;
+                        visitingGraph = false;
+                    }
                 }
             }
 
             // only mark the current vertex as visited, if the
-            // edge leading to should be expanded
+            // edge leading to it should be expanded
             if ( !skipVertex )
             {
-                visitedVertices.add( v );                
+                visitedVertices.add( v );
             }
 
             if ( !skipVertex && handler.discoverVertex( v ) )