You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/03/08 00:46:31 UTC
svn commit: r1298228 - in
/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow:
DefaultMaxFlowAlgorithmSelector.java DefaultToTailBuilder.java
Author: simonetripodi
Date: Wed Mar 7 23:46:31 2012
New Revision: 1298228
URL: http://svn.apache.org/viewvc?rev=1298228&view=rev
Log:
completed the builder chain for Flow algorithms - note that there is a compilation issue due to conceptual changes!
Modified:
commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultToTailBuilder.java
Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java?rev=1298228&r1=1298227&r2=1298228&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java Wed Mar 7 23:46:31 2012
@@ -19,10 +19,12 @@ package org.apache.commons.graph.flow;
* under the License.
*/
+import static org.apache.commons.graph.CommonsGraph.newDirectedMutableGraph;
import static org.apache.commons.graph.CommonsGraph.visit;
import static org.apache.commons.graph.utils.Assertions.checkNotNull;
import org.apache.commons.graph.DirectedGraph;
+import org.apache.commons.graph.Mapper;
import org.apache.commons.graph.VertexPair;
import org.apache.commons.graph.builder.AbstractGraphConnection;
import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
@@ -42,13 +44,16 @@ final class DefaultMaxFlowAlgorithmSelec
private final G graph;
+ private final Mapper<WE, W> weightedEdges;
+
private final V source;
private final V target;
- public DefaultMaxFlowAlgorithmSelector( G graph, V source, V target )
+ public DefaultMaxFlowAlgorithmSelector( G graph, Mapper<WE, W> weightedEdges, V source, V target )
{
this.graph = graph;
+ this.weightedEdges = weightedEdges;
this.source = source;
this.target = target;
}
@@ -61,10 +66,10 @@ final class DefaultMaxFlowAlgorithmSelec
final WO checkedWeightOperations = checkNotNull( weightOperations, "Weight operations can not be null to find the max flow in the graph" );
// create flow network
- final DirectedGraph<V, WeightedEdge<W>> flowNetwork = newFlowNetwok( graph, checkedWeightOperations );
+ final DirectedGraph<V, WE> flowNetwork = newFlowNetwok( graph, checkedWeightOperations );
// create flow network handler
- final FlowNetworkHandler<V, W> flowNetworkHandler = new FlowNetworkHandler<V, W>( flowNetwork, source, target, checkedWeightOperations );
+ final FlowNetworkHandler<V, WE, W> flowNetworkHandler = new FlowNetworkHandler<V, WE, W>( flowNetwork, source, target, checkedWeightOperations, weightedEdges );
// perform depth first search
visit( flowNetwork ).from( source ).applyingDepthFirstSearch( flowNetworkHandler );
@@ -88,10 +93,10 @@ final class DefaultMaxFlowAlgorithmSelec
final WO checkedWeightOperations = checkNotNull( weightOperations, "Weight operations can not be null to find the max flow in the graph" );
// create flow network
- final DirectedGraph<V, WeightedEdge<W>> flowNetwork = newFlowNetwok( graph, checkedWeightOperations );
+ final DirectedGraph<V, WE> flowNetwork = newFlowNetwok( graph, checkedWeightOperations );
// create flow network handler
- final FlowNetworkHandler<V, W> flowNetworkHandler = new FlowNetworkHandler<V, W>( flowNetwork, source, target, checkedWeightOperations );
+ final FlowNetworkHandler<V, WE, W> flowNetworkHandler = new FlowNetworkHandler<V, WE, W>( flowNetwork, source, target, checkedWeightOperations, weightedEdges );
// perform breadth first search
visit( flowNetwork ).from( source ).applyingBreadthFirstSearch( flowNetworkHandler );
@@ -107,9 +112,9 @@ final class DefaultMaxFlowAlgorithmSelec
return flowNetworkHandler.onCompleted();
}
- private <WO extends OrderedMonoid<W>> DirectedGraph<V, WeightedEdge<W>> newFlowNetwok( final G graph, final WO weightOperations )
+ private <WO extends OrderedMonoid<W>> DirectedGraph<V, WE> newFlowNetwok( final G graph, final WO weightOperations )
{
- return newDirectedMutableWeightedGraph( new AbstractGraphConnection<V, WeightedEdge<W>>()
+ return newDirectedMutableGraph( new AbstractGraphConnection<V, WE>()
{
@Override
public void connect()
@@ -130,6 +135,7 @@ final class DefaultMaxFlowAlgorithmSelec
if ( graph.getEdge( tail, head ) == null )
{
+ // FIXME!!!
// complete the flow network with a zero-capacity inverse edge
addEdge( new BaseLabeledWeightedEdge<W>( "Inverse edge for " + edge, weightOperations.zero() ) )
.from( tail ).to( head );
Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultToTailBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultToTailBuilder.java?rev=1298228&r1=1298227&r2=1298228&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultToTailBuilder.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/flow/DefaultToTailBuilder.java Wed Mar 7 23:46:31 2012
@@ -52,7 +52,7 @@ final class DefaultToTailBuilder<V, WE,
public MaxFlowAlgorithmSelector<V, WE, W, G> to( V tail )
{
tail = checkNotNull( tail, "tail vertex has to be specifies when looking for the max flow" );
- return new DefaultMaxFlowAlgorithmSelector<V, WE, W, G>( graph, head, tail );
+ return new DefaultMaxFlowAlgorithmSelector<V, WE, W, G>( graph, weightedEdges, head, tail );
}
}