commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1235249 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java
Date Tue, 24 Jan 2012 13:32:59 GMT
Author: simonetripodi
Date: Tue Jan 24 13:32:58 2012
New Revision: 1235249

URL: http://svn.apache.org/viewvc?rev=1235249&view=rev
Log:
no needs to allocate a wrapper method to build the graph

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java?rev=1235249&r1=1235248&r2=1235249&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FordFulkerson.java
Tue Jan 24 13:32:58 2012
@@ -55,13 +55,34 @@ public final class FordFulkerson
      * @param orderedMonoid the ordered monoid needed for operations on edge weights
      * @return the maximum flow between source and target
      */
-    public static <V extends Vertex, W, WE extends WeightedEdge<W>, G extends DirectedGraph<V,
WE>> W findMaxFlow( G graph,
+    public static <V extends Vertex, W, WE extends WeightedEdge<W>, G extends DirectedGraph<V,
WE>> W findMaxFlow( final G graph,
                                                                                         
                          V source,
                                                                                         
                          V target,
-                                                                                        
                          OrderedMonoid<W> orderedMonoid )
+                                                                                        
                          final OrderedMonoid<W> orderedMonoid )
     {
         // create flow network
-        DirectedGraph<V, WE> flowNetwork = createFlowNetwork( graph, orderedMonoid
);
+        DirectedGraph<V, WE> flowNetwork = newDirectedMutableWeightedGraph( new AbstractGraphConnection<V,
WE>()
+        {
+            @SuppressWarnings( "unchecked" )
+            @Override
+            public void connect()
+            {
+                // vertices
+                for ( V vertex : graph.getVertices() )
+                {
+                    addVertex( vertex );
+                }
+                // edges
+                for ( WE edge : graph.getEdges() )
+                {
+                    VertexPair<V> edgeVertices = graph.getVertices( edge );
+                    V head = edgeVertices.getHead();
+                    V tail = edgeVertices.getTail();
+                    addEdge( edge ).from( head ).to( tail );
+                    addEdge( (WE) new BaseLabeledWeightedEdge<W>( "Inverse edge for
" + edge.toString(), orderedMonoid.zero() ) );
+                }
+            }
+        } );
 
         // create flow network handler
         FlowNetworkHandler<V, WE, W> flowNetworkHandler =
@@ -96,34 +117,4 @@ public final class FordFulkerson
         return findMaxFlow( graph, source, target, new IntegerWeight() );
     }
 
-    private static <V extends Vertex, WE extends WeightedEdge<W>, W, G extends DirectedGraph<V,
WE>> DirectedGraph<V, WE> createFlowNetwork( final G graph,
-                                                                                        
                                                    final OrderedMonoid<W> orderedMonoid
)
-    {
-        DirectedGraph<V, WE> flowNetwork =
-        newDirectedMutableWeightedGraph( new AbstractGraphConnection<V, WE>()
-        {
-            @SuppressWarnings( "unchecked" )
-            @Override
-            public void connect()
-            {
-                // vertices
-                for ( V vertex : graph.getVertices() )
-                {
-                    addVertex( vertex );
-                }
-                // edges
-                for ( WE edge : graph.getEdges() )
-                {
-                    VertexPair<V> edgeVertices = graph.getVertices( edge );
-                    V head = edgeVertices.getHead();
-                    V tail = edgeVertices.getTail();
-                    addEdge( edge ).from( head ).to( tail );
-                    addEdge( (WE) new BaseLabeledWeightedEdge<W>( "Inverse edge for
" + edge.toString(), orderedMonoid.zero() ) );
-                }
-            }
-        } );
-
-        return flowNetwork;
-    }
-
 }



Mime
View raw message