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:06:20 UTC

svn commit: r1298195 - in /commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph: model/ shortestpath/

Author: simonetripodi
Date: Wed Mar  7 23:06:20 2012
New Revision: 1298195

URL: http://svn.apache.org/viewvc?rev=1298195&view=rev
Log:
plugged the edge mapper inside the weighter path

Modified:
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultHeuristicBuilder.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultPathSourceSelector.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultShortestPathAlgorithmSelector.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java Wed Mar  7 23:06:20 2012
@@ -21,6 +21,7 @@ package org.apache.commons.graph.model;
 
 import static java.lang.String.format;
 
+import org.apache.commons.graph.Mapper;
 import org.apache.commons.graph.WeightedPath;
 import org.apache.commons.graph.weight.Monoid;
 
@@ -42,14 +43,18 @@ public final class InMemoryWeightedPath<
      */
     private static final long serialVersionUID = 7937494144459068796L;
 
-    private W weight;
+    private final Monoid<W> weightOperations;
+
+    private final Mapper<WE, W> weightedEdges;
 
-    private Monoid<W> weightOperations;
+    private W weight;
 
-    public InMemoryWeightedPath( V start, V target, Monoid<W> weightOperations )
+    public InMemoryWeightedPath( V start, V target, Monoid<W> weightOperations, Mapper<WE, W> weightedEdges )
     {
         super( start, target );
         this.weightOperations = weightOperations;
+        this.weightedEdges = weightedEdges;
+
         this.weight = weightOperations.zero();
     }
 
@@ -80,7 +85,7 @@ public final class InMemoryWeightedPath<
      */
     private void increaseWeight( WE edge )
     {
-        // TODO weight = weightOperations.append( edge.getWeight(), weight );
+        weight = weightOperations.append( weightedEdges.map( edge ), weight );
     }
 
     /**

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultHeuristicBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultHeuristicBuilder.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultHeuristicBuilder.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultHeuristicBuilder.java Wed Mar  7 23:06:20 2012
@@ -79,7 +79,7 @@ final class DefaultHeuristicBuilder<V, W
         openSet.add( start );
 
         // The of navigated nodes
-        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations );
+        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations, weightedEdges );
 
         // extract the node in openset having the lowest f_score[] value
         while ( !openSet.isEmpty() )

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultPathSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultPathSourceSelector.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultPathSourceSelector.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultPathSourceSelector.java Wed Mar  7 23:06:20 2012
@@ -98,7 +98,7 @@ final class DefaultPathSourceSelector<V,
             {
                 if ( !source.equals( target ) )
                 {
-                    PredecessorsList<V, WE, W> predecessorsList = new PredecessorsList<V, WE, W>( graph, weightOperations );
+                    PredecessorsList<V, WE, W> predecessorsList = new PredecessorsList<V, WE, W>( graph, weightOperations, weightedEdges );
 
                     pathReconstruction( predecessorsList, source, target, next );
                     if ( !predecessorsList.isEmpty() )

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultShortestPathAlgorithmSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultShortestPathAlgorithmSelector.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultShortestPathAlgorithmSelector.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultShortestPathAlgorithmSelector.java Wed Mar  7 23:06:20 2012
@@ -75,7 +75,7 @@ final class DefaultShortestPathAlgorithm
 
         final Set<V> settledNodes = new HashSet<V>();
 
-        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations );
+        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations, weightedEdges );
 
         // extract the node with the shortest distance
         while ( !unsettledNodes.isEmpty() )

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java Wed Mar  7 23:06:20 2012
@@ -54,7 +54,7 @@ final class DefaultTargetSourceSelector<
         final ShortestDistances<V, W> shortestDistances = new ShortestDistances<V, W>( weightOperations );
         shortestDistances.setWeight( source, weightOperations.zero() );
 
-        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations );
+        final PredecessorsList<V, WE, W> predecessors = new PredecessorsList<V, WE, W>( graph, weightOperations, weightedEdges );
 
         for ( int i = 0; i < graph.getOrder(); i++ )
         {

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java?rev=1298195&r1=1298194&r2=1298195&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java Wed Mar  7 23:06:20 2012
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Mapper;
 import org.apache.commons.graph.WeightedPath;
 import org.apache.commons.graph.model.InMemoryWeightedPath;
 import org.apache.commons.graph.weight.Monoid;
@@ -42,12 +43,15 @@ public final class PredecessorsList<V, W
 
     private final Monoid<W> weightOperations;
 
+    private final Mapper<WE, W> weightedEdges;
+
     private final Map<V, V> predecessors = new HashMap<V, V>();
 
-    public PredecessorsList( Graph<V, WE> graph, Monoid<W> weightOperations )
+    public PredecessorsList( Graph<V, WE> graph, Monoid<W> weightOperations, Mapper<WE, W> weightedEdges )
     {
         this.graph = graph;
         this.weightOperations = weightOperations;
+        this.weightedEdges = weightedEdges;
     }
 
     /**
@@ -71,7 +75,7 @@ public final class PredecessorsList<V, W
      */
     public WeightedPath<V, WE, W> buildPath( V source, V target )
     {
-        InMemoryWeightedPath<V, WE, W> path = new InMemoryWeightedPath<V, WE, W>( source, target, weightOperations );
+        InMemoryWeightedPath<V, WE, W> path = new InMemoryWeightedPath<V, WE, W>( source, target, weightOperations, weightedEdges );
 
         V vertex = target;
         while ( !source.equals( vertex ) )