commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1220522 - in /commons/sandbox/graph/trunk/src: main/java/org/apache/commons/graph/ main/java/org/apache/commons/graph/export/ main/java/org/apache/commons/graph/model/ main/java/org/apache/commons/graph/shortestpath/ main/java/org/apache/c...
Date Sun, 18 Dec 2011 19:54:27 GMT
Author: simonetripodi
Date: Sun Dec 18 19:54:26 2011
New Revision: 1220522

URL: http://svn.apache.org/viewvc?rev=1220522&view=rev
Log:
[SANDBOX-345] Weighted as an interface with generic weight type - patch submitted by Claudio
Squarcella

Added:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java   (with
props)
Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/SpanningTree.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedEdge.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedGraph.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedPath.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/export/DotExporter.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableWeightedGraph.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/MutableSpanningTree.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableWeightedGraph.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AllVertexPairsShortestPath.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/BellmannFord.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/FloydWarshall.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Boruvka.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledWeightedEdge.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/SpanningTree.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/SpanningTree.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/SpanningTree.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/SpanningTree.java Sun
Dec 18 19:54:26 2011
@@ -26,7 +26,7 @@ package org.apache.commons.graph;
  * @param <V> the Graph vertices type
  * @param <WE> the Graph weighted edges type
  */
-public interface SpanningTree<V extends Vertex, WE extends WeightedEdge>
+public interface SpanningTree<V extends Vertex, WE extends WeightedEdge<Double>>
     extends UndirectedGraph<V, WE>
 {
 

Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java?rev=1220522&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java Sun Dec
18 19:54:26 2011
@@ -0,0 +1,38 @@
+package org.apache.commons.graph;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * A Weighted object has a property called weight, which usually denotes
+ * its relative importance within the domain of interest.
+ *
+ * @param <W> the type of weight
+ */
+public interface Weighted<W>
+{
+
+    /**
+     * Gets the weight of the {@code Weighted} object.
+     *
+     * @return the weight of the {@code Weighted} object.
+     */
+    public W getWeight();
+
+}

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Weighted.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedEdge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedEdge.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedEdge.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedEdge.java Sun
Dec 18 19:54:26 2011
@@ -20,18 +20,11 @@ package org.apache.commons.graph;
  */
 
 /**
- * A WeightedEdge is an {@link Edge} where a number (weight) is assigned to represent, for
example,
+ * A WeightedEdge is an {@link Edge} that is assigned a weight to represent, for example,
  * costs, lengths or capacities, etc. depending on the problem.
  */
-public interface WeightedEdge
-    extends Edge, Comparable<WeightedEdge>
+public interface WeightedEdge<W>
+    extends Edge, Weighted<W>, Comparable<WeightedEdge<W>>
 {
 
-    /**
-     * Gets the weight attribute of the WeightedEdge object
-     *
-     * @return the weight attribute of the WeightedEdge object
-     */
-    Double getWeight();
-
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedGraph.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedGraph.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedGraph.java
Sun Dec 18 19:54:26 2011
@@ -27,7 +27,7 @@ package org.apache.commons.graph;
  * @param <V> the Graph vertices type.
  * @param <WE> the Graph weighted edges type
  */
-public interface WeightedGraph<V extends Vertex, WE extends WeightedEdge>
+public interface WeightedGraph<V extends Vertex, WE extends WeightedEdge<W>, W>
     extends Graph<V, WE>
 {
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedPath.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedPath.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/WeightedPath.java Sun
Dec 18 19:54:26 2011
@@ -20,20 +20,14 @@ package org.apache.commons.graph;
  */
 
 /**
- * A {@code Path} where {@link Edge} are weighted.
+ * A {@code Path} whose {@link Edge}s are {@link Weighted}.
  *
  * @param <V> the Graph vertices type
  * @param <WE> the Graph weighted edges type
+ * @param <W> the weight type
  */
-public interface WeightedPath<V extends Vertex, WE extends WeightedEdge>
-    extends Path<V, WE>
+public interface WeightedPath<V extends Vertex, WE extends WeightedEdge<W>, W>
+    extends Path<V, WE>, Weighted<W>
 {
 
-    /**
-     * Gets the weight attribute of the {@code WeightedPath} object.
-     *
-     * @return the weight attribute of the {@code WeightedPath} object.
-     */
-    Double getWeight();
-
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/export/DotExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/export/DotExporter.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/export/DotExporter.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/export/DotExporter.java
Sun Dec 18 19:54:26 2011
@@ -19,8 +19,6 @@ package org.apache.commons.graph.export;
  * under the License.
  */
 
-import static java.lang.String.format;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -29,6 +27,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.util.Date;
+import java.util.Formatter;
 
 import org.apache.commons.graph.DirectedGraph;
 import org.apache.commons.graph.Edge;
@@ -190,42 +189,41 @@ public final class DotExporter
 
             for ( E edge : graph.getEdges() )
             {
-                String label = null;
+                VertexPair<V> vertexPair = graph.getVertices( edge );
+
+                Formatter formatter = new Formatter().format( "  %s %s %s",
+                                                              vertexPair.getHead().hashCode(),
+                                                              connector,
+                                                              vertexPair.getTail().hashCode()
);
+
+                boolean attributesFound = false;
 
                 if ( edge instanceof Labeled )
                 {
-                    if ( edge instanceof WeightedEdge )
-                    {
-                        label =
-                            format( "'%s' (w=%s)", ( (Labeled) edge ).getLabel(), ( (WeightedEdge)
edge ).getWeight() );
-                    }
-                    else
-                    {
-                        label = ( (Labeled) edge ).getLabel();
-                    }
+                    attributesFound = true;
+                    formatter.format( " [label=\"%s\"", ( (Labeled) edge ).getLabel() );
                 }
-                else if ( edge instanceof WeightedEdge )
+                if ( edge instanceof WeightedEdge )
                 {
-                    label = String.valueOf( ( (WeightedEdge) edge ).getWeight() );
-                }
+                    formatter.format( " " );
 
-                VertexPair<V> vertexPair = graph.getVertices( edge );
+                    if ( !attributesFound )
+                    {
+                        formatter.format( "[" );
+                        attributesFound = true;
+                    }
 
-                if ( label != null )
-                {
-                    printWriter.format( "  %s %s %s [label=\"%s\"];%n",
-                                        vertexPair.getHead().hashCode(),
-                                        connector,
-                                        vertexPair.getTail().hashCode(),
-                                        label );
+                    formatter.format( "weight=%s", ( (WeightedEdge<?>) edge ).getWeight()
);
                 }
-                else
+
+                if ( attributesFound )
                 {
-                    printWriter.format( "  %s %s %s",
-                                        vertexPair.getHead().hashCode(),
-                                        connector,
-                                        vertexPair.getTail().hashCode() );
+                    formatter.format( "]" );
                 }
+
+                formatter.format( "%n" );
+
+                printWriter.write( formatter.toString() );
             }
 
             printWriter.write( '}' );
@@ -242,5 +240,4 @@ public final class DotExporter
             }
         }
     }
-
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableWeightedGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableWeightedGraph.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableWeightedGraph.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableWeightedGraph.java
Sun Dec 18 19:54:26 2011
@@ -28,7 +28,7 @@ import org.apache.commons.graph.Weighted
  * @param <V> the Graph vertices type
  * @param <WE> the WeightedEdge edges type
  */
-public class DirectedMutableWeightedGraph<V extends Vertex, WE extends WeightedEdge>
+public class DirectedMutableWeightedGraph<V extends Vertex, WE extends WeightedEdge<Double>>
     extends DirectedMutableGraph<V, WE>
 {
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
Sun Dec 18 19:54:26 2011
@@ -32,9 +32,9 @@ import org.apache.commons.graph.Weighted
  * @param <V> the Graph vertices type
  * @param <WE> the Graph weighted edges type
  */
-public final class InMemoryWeightedPath<V extends Vertex, WE extends WeightedEdge>
+public final class InMemoryWeightedPath<V extends Vertex, WE extends WeightedEdge<Double>>
     extends InMemoryPath<V, WE>
-    implements WeightedPath<V, WE>
+    implements WeightedPath<V, WE, Double>
 {
 
     private Double weigth = 0D;
@@ -116,7 +116,7 @@ public final class InMemoryWeightedPath<
         }
 
         @SuppressWarnings( "unchecked" ) // test against any WeightedPath typed instance
-        InMemoryWeightedPath<Vertex, WeightedEdge> other = (InMemoryWeightedPath<Vertex,
WeightedEdge>) obj;
+        InMemoryWeightedPath<Vertex, WeightedEdge<Double>> other = (InMemoryWeightedPath<Vertex,
WeightedEdge<Double>>) obj;
         if ( !weigth.equals( other.getWeight() ) )
         {
             return false;

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/MutableSpanningTree.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/MutableSpanningTree.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/MutableSpanningTree.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/MutableSpanningTree.java
Sun Dec 18 19:54:26 2011
@@ -29,7 +29,7 @@ import org.apache.commons.graph.Weighted
  * @param <V> the Graph vertices type
  * @param <WE> the Graph weighted edges type
  */
-public final class MutableSpanningTree<V extends Vertex, WE extends WeightedEdge>
+public final class MutableSpanningTree<V extends Vertex, WE extends WeightedEdge<Double>>
     extends UndirectedMutableGraph<V, WE>
     implements SpanningTree<V, WE>
 {

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableWeightedGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableWeightedGraph.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableWeightedGraph.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableWeightedGraph.java
Sun Dec 18 19:54:26 2011
@@ -28,7 +28,7 @@ import org.apache.commons.graph.Weighted
  * @param <V> the Graph vertices type
  * @param <WE> the WeightedEdge edges type
  */
-public class UndirectedMutableWeightedGraph<V extends Vertex, WE extends WeightedEdge>
+public class UndirectedMutableWeightedGraph<V extends Vertex, WE extends WeightedEdge<Double>>
     extends UndirectedMutableGraph<V, WE>
 {
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
Sun Dec 18 19:54:26 2011
@@ -55,10 +55,10 @@ public final class AStar
      * @param heuristic the <i>h(x)</i> function
      * @return a path which describes the shortest path, if any, otherwise a {@link PathNotFoundException}
will be thrown
      */
-    public static <V extends Vertex, WE extends WeightedEdge> WeightedPath<V, WE>
findShortestPath( Graph<V, WE> graph,
-                                                                                        
           V start,
-                                                                                        
           V goal,
-                                                                                        
           Heuristic<V> heuristic )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>> WeightedPath<V,
WE, Double> findShortestPath( Graph<V, WE> graph,
+                                                                                        
                           V start,
+                                                                                        
                           V goal,
+                                                                                        
                           Heuristic<V> heuristic )
     {
         // Cost from start along best known path.
         final ShortestDistances<V> gScores = new ShortestDistances<V>();

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AllVertexPairsShortestPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AllVertexPairsShortestPath.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AllVertexPairsShortestPath.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AllVertexPairsShortestPath.java
Sun Dec 18 19:54:26 2011
@@ -33,10 +33,10 @@ import org.apache.commons.graph.Weighted
  * @param <V> the Graph vertices type
  * @param <E> the Graph edges type
  */
-public final class AllVertexPairsShortestPath<V extends Vertex, WE extends WeightedEdge>
+public final class AllVertexPairsShortestPath<V extends Vertex, WE extends WeightedEdge<Double>>
 {
 
-    private final Map<VertexPair<V>, WeightedPath<V, WE>> paths = new HashMap<VertexPair<V>,
WeightedPath<V, WE>>();
+    private final Map<VertexPair<V>, WeightedPath<V, WE, Double>> paths
= new HashMap<VertexPair<V>, WeightedPath<V, WE, Double>>();
 
     private final Map<VertexPair<V>, Double> shortestDistances = new HashMap<VertexPair<V>,
Double>();
 
@@ -53,7 +53,7 @@ public final class AllVertexPairsShortes
      * @param target
      * @param weightedPath
      */
-    void addShortestPath( V source, V target, WeightedPath<V, WE> weightedPath )
+    void addShortestPath( V source, V target, WeightedPath<V, WE, Double> weightedPath
)
     {
         if ( source == null )
         {
@@ -78,7 +78,7 @@ public final class AllVertexPairsShortes
      * @param target The target Vertex
      * @return Returns the shortest path between source and target
      */
-    public WeightedPath<V, WE> findShortestPath( V source, V target )
+    public WeightedPath<V, WE, Double> findShortestPath( V source, V target )
     {
         if ( source == null )
         {
@@ -89,7 +89,7 @@ public final class AllVertexPairsShortes
             throw new IllegalArgumentException( "Impossible to find the shortest path to
a null target" );
         }
 
-        WeightedPath<V, WE> path = paths.get( new VertexPair<V>( source, target
) );
+        WeightedPath<V, WE, Double> path = paths.get( new VertexPair<V>( source,
target ) );
 
         if ( path == null )
         {

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/BellmannFord.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/BellmannFord.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/BellmannFord.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/BellmannFord.java
Sun Dec 18 19:54:26 2011
@@ -49,8 +49,8 @@ public final class BellmannFord
      * @param target the shortest path target Vertex
      * @return a path which describes the shortest path, if any, otherwise a {@link PathNotFoundException}
will be thrown
      */
-    public static <V extends Vertex, WE extends WeightedEdge, G extends DirectedGraph<V,
WE>> AllVertexPairsShortestPath<V, WE> findShortestPath( G graph,
-                                                                                        
                                                         V source)
+    public static <V extends Vertex, WE extends WeightedEdge<Double>, G extends
DirectedGraph<V, WE>> AllVertexPairsShortestPath<V, WE> findShortestPath( G
graph,
+                                                                                        
                                                                 V source)
     {
         final ShortestDistances<V> shortestDistances = new ShortestDistances<V>();
         shortestDistances.setWeight( source, 0D );
@@ -100,7 +100,7 @@ public final class BellmannFord
         {
             if ( !source.equals( target ) )
             {
-                WeightedPath<V, WE> weightedPath = predecessors.buildPath( source,
target );
+                WeightedPath<V, WE, Double> weightedPath = predecessors.buildPath(
source, target );
                 allVertexPairsShortestPath.addShortestPath( source, target, weightedPath
);
             }
         }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
Sun Dec 18 19:54:26 2011
@@ -54,9 +54,9 @@ public final class Dijkstra
      * @return a path which describes the shortest path, if any,
      *         otherwise a {@link PathNotFoundException} will be thrown
      */
-    public static <V extends Vertex, WE extends WeightedEdge, G extends DirectedGraph<V,
WE>> WeightedPath<V, WE> findShortestPath( G graph,
-                                                                                        
                                           V source,
-                                                                                        
                                           V target )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>, G extends
DirectedGraph<V, WE>> WeightedPath<V, WE, Double> findShortestPath( G graph,
+                                                                                        
                                                           V source,
+                                                                                        
                                                           V target )
     {
         final ShortestDistances<V> shortestDistances = new ShortestDistances<V>();
         shortestDistances.setWeight( source, 0D );

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/FloydWarshall.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/FloydWarshall.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/FloydWarshall.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/FloydWarshall.java
Sun Dec 18 19:54:26 2011
@@ -50,7 +50,7 @@ public final class FloydWarshall
      * @param <WE> the Graph weighted edges type
      * @return a data structure which contains all vertex pairs shortest path.
      */
-    public static <V extends Vertex, WE extends WeightedEdge> AllVertexPairsShortestPath<V,
WE> findAllVertexPairsShortestPath( Graph<V, WE> graph )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>> AllVertexPairsShortestPath<V,
WE> findAllVertexPairsShortestPath( Graph<V, WE> graph )
     {
         AllVertexPairsShortestPath<V, WE> shortesPaths = new AllVertexPairsShortestPath<V,
WE>();
         Map<VertexPair<V>, V> next = new HashMap<VertexPair<V>, V>();
@@ -99,7 +99,7 @@ public final class FloydWarshall
                     pathReconstruction( predecessorsList, source, target, next, graph );
                     if ( !predecessorsList.isEmpty() )
                     {
-                        WeightedPath<V, WE> weightedPath = predecessorsList.buildPath(
source, target );
+                        WeightedPath<V, WE, Double> weightedPath = predecessorsList.buildPath(
source, target );
                         if ( weightedPath.getOrder() > 0 )
                         {
                             shortesPaths.addShortestPath( source, target, weightedPath );
@@ -112,10 +112,10 @@ public final class FloydWarshall
         return shortesPaths;
     }
 
-    private static <V extends Vertex, WE extends WeightedEdge> void pathReconstruction(
PredecessorsList<V, WE> path,
-                                                                                        V
source, V target,
-                                                                                        Map<VertexPair<V>,
V> next,
-                                                                                        Graph<V,
WE> graph )
+    private static <V extends Vertex, WE extends WeightedEdge<Double>> void pathReconstruction(
PredecessorsList<V, WE> path,
+                                                                                        
       V source, V target,
+                                                                                        
       Map<VertexPair<V>, V> next,
+                                                                                        
       Graph<V, WE> graph )
     {
         V k = next.get( new VertexPair<Vertex>( source, target ) );
         if ( k == null )

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PredecessorsList.java
Sun Dec 18 19:54:26 2011
@@ -36,7 +36,7 @@ import org.apache.commons.graph.model.In
  * @param <V> the Graph vertices type
  * @param <E> the Graph edges type
  */
-final class PredecessorsList<V extends Vertex, WE extends WeightedEdge>
+final class PredecessorsList<V extends Vertex, WE extends WeightedEdge<Double>>
 {
 
     private final Graph<V, WE> graph;
@@ -67,7 +67,7 @@ final class PredecessorsList<V extends V
      * @param cost the path cost
      * @return the weighted path related to source to target
      */
-    public WeightedPath<V, WE> buildPath( V source, V target )
+    public WeightedPath<V, WE, Double> buildPath( V source, V target )
     {
         InMemoryWeightedPath<V, WE> path = new InMemoryWeightedPath<V, WE>( source,
target );
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Boruvka.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Boruvka.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Boruvka.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Boruvka.java
Sun Dec 18 19:54:26 2011
@@ -38,7 +38,7 @@ public final class Boruvka
      * @param graph the Graph for which minimum spanning tree (or forest) has to be calculated.
      * @return  the minimum spanning tree (or forest) of the input Graph.
      */
-    public static <V extends Vertex, WE extends WeightedEdge> Graph<V, WE> minimumSpanningTree(
Graph<V, WE> graph )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>> Graph<V,
WE> minimumSpanningTree( Graph<V, WE> graph )
     {
         return null;
     }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
Sun Dec 18 19:54:26 2011
@@ -46,7 +46,7 @@ public final class Kruskal
      * @param graph the Graph for which minimum spanning tree (or forest) has to be calculated.
      * @return  the minimum spanning tree (or forest) of the input Graph.
      */
-    public static <V extends Vertex, WE extends WeightedEdge> SpanningTree<V, WE>
minimumSpanningTree( Graph<V, WE> graph )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>> SpanningTree<V,
WE> minimumSpanningTree( Graph<V, WE> graph )
     {
         final Set<V> settledNodes = new HashSet<V>();
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
Sun Dec 18 19:54:26 2011
@@ -44,7 +44,7 @@ public final class Prim
      * @param graph the Graph for which minimum spanning tree has to be calculated.
      * @return the minimum spanning tree of the input Graph.
      */
-    public static <V extends Vertex, WE extends WeightedEdge, G extends UndirectedGraph<V,
WE>> SpanningTree<V, WE> minimumSpanningTree( G graph )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>, G extends
UndirectedGraph<V, WE>> SpanningTree<V, WE> minimumSpanningTree( G graph )
     {
         return minimumSpanningTree( graph, graph.getVertices().iterator().next() );
     }
@@ -59,8 +59,8 @@ public final class Prim
      * @param source the Prim's Vertex source
      * @return the minimum spanning tree of the input Graph.
      */
-    public static <V extends Vertex, WE extends WeightedEdge, G extends UndirectedGraph<V,
WE>> SpanningTree<V, WE> minimumSpanningTree( G graph,
-                                                                                        
                                                V source )
+    public static <V extends Vertex, WE extends WeightedEdge<Double>, G extends
UndirectedGraph<V, WE>> SpanningTree<V, WE> minimumSpanningTree( G graph,
+                                                                                        
                                                        V source )
     {
         final ShortestEdges<V, WE> shortesEdges = new ShortestEdges<V, WE>( graph,
source );
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
Sun Dec 18 19:54:26 2011
@@ -39,7 +39,7 @@ import org.apache.commons.graph.model.Mu
  * @param <V> the Graph vertices type
  * @param <E> the Graph edges type
  */
-final class ShortestEdges<V extends Vertex, WE extends WeightedEdge>
+final class ShortestEdges<V extends Vertex, WE extends WeightedEdge<Double>>
     implements Comparator<V>
 {
 
@@ -91,7 +91,7 @@ final class ShortestEdges<V extends Vert
         return spanningTree;
     }
 
-    private static <V extends Vertex, WE extends WeightedEdge> void addEdgeIgnoringExceptions(
V vertex,
+    private static <V extends Vertex, WE extends WeightedEdge<Double>> void addEdgeIgnoringExceptions(
V vertex,
                                                                                         
      MutableSpanningTree<V, WE> spanningTree )
     {
         try

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledWeightedEdge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledWeightedEdge.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledWeightedEdge.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledWeightedEdge.java
Sun Dec 18 19:54:26 2011
@@ -28,7 +28,7 @@ import org.apache.commons.graph.Weighted
  */
 public class BaseLabeledWeightedEdge
     extends BaseLabeledEdge
-    implements WeightedEdge
+    implements WeightedEdge<Double>
 {
 
     private final Double weight;
@@ -46,7 +46,7 @@ public class BaseLabeledWeightedEdge
     /**
      * {@inheritDoc}
      */
-    public int compareTo( WeightedEdge other )
+    public int compareTo( WeightedEdge<Double> other )
     {
         return weight.compareTo( other.getWeight() );
     }

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
Sun Dec 18 19:54:26 2011
@@ -80,7 +80,7 @@ public final class BellmannFordTestCase
         AllVertexPairsShortestPath<BaseLabeledVertex, BaseLabeledWeightedEdge> allVertexPairsShortestPath
=
             findShortestPath( graph, one );
 
-        WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge> actual =
+        WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge, Double> actual =
             allVertexPairsShortestPath.findShortestPath( one, three );
         assertEquals( expected, actual );
     }

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java?rev=1220522&r1=1220521&r2=1220522&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
Sun Dec 18 19:54:26 2011
@@ -104,7 +104,7 @@ public class FloydWarshallTestCase
 
             // Verify shortest paths
 
-            WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge> wp = p.findShortestPath(
one, six );
+            WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge, Double> wp = p.findShortestPath(
one, six );
 
             // Expected
             InMemoryWeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge> expected
=
@@ -124,7 +124,7 @@ public class FloydWarshallTestCase
             assertEquals( 20D, p.getShortestDistance( one, five ) );
             assertEquals( Double.POSITIVE_INFINITY, p.getShortestDistance( five, one ) );
 
-            WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge> wp;
+            WeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge, Double> wp;
             // Verify shortest paths
             try
             {



Mime
View raw message