commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1295725 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
Date Thu, 01 Mar 2012 18:30:53 GMT
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 ) )



Mime
View raw message