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/01/26 15:49:25 UTC
svn commit: r1236207 - in
/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph: ./
shortestpath/
Author: simonetripodi
Date: Thu Jan 26 14:49:25 2012
New Revision: 1236207
URL: http://svn.apache.org/viewvc?rev=1236207&view=rev
Log:
started adding shortest path fluent APIs
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/HeuristicBuilder.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PathSourceSelector.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestPathAlgorithmSelector.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/TargetSourceSelector.java
Modified:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java?rev=1236207&r1=1236206&r2=1236207&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java Thu Jan 26 14:49:25 2012
@@ -36,6 +36,7 @@ import org.apache.commons.graph.model.Un
import org.apache.commons.graph.model.UndirectedMutableWeightedGraph;
import org.apache.commons.graph.scc.DefaultSccAlgorithmSelector;
import org.apache.commons.graph.scc.SccAlgorithmSelector;
+import org.apache.commons.graph.shortestpath.PathSourceSelector;
import org.apache.commons.graph.spanning.DefaultSpanningTreeSourceSelector;
import org.apache.commons.graph.spanning.SpanningTreeSourceSelector;
import org.apache.commons.graph.visit.DefaultVisitSourceSelector;
@@ -92,6 +93,21 @@ public final class CommonsGraph<V extend
}
/**
+ *
+ *
+ * @param <V>
+ * @param <W>
+ * @param <WE>
+ * @param <G>
+ * @param graph
+ */
+ public static <V extends Vertex, W, WE extends WeightedEdge<W>, G extends Graph<V, WE>> PathSourceSelector<V, W, WE, G> findShortesPath( G graph )
+ {
+ graph = checkNotNull( graph, "Minimum spanning tree can not be calculated on null graph" );
+ return null;
+ }
+
+ /**
* Calculates the input graph Strongly Connected Component.
*
* @param <V> the Graph vertices type.
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/HeuristicBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/HeuristicBuilder.java?rev=1236207&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/HeuristicBuilder.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/HeuristicBuilder.java Thu Jan 26 14:49:25 2012
@@ -0,0 +1,45 @@
+package org.apache.commons.graph.shortestpath;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.WeightedPath;
+
+/**
+ *
+ * @param <V>
+ * @param <W>
+ * @param <WE>
+ * @param <G>
+ */
+public interface HeuristicBuilder<V extends Vertex, W, WE extends WeightedEdge<W>, G extends Graph<V, WE>>
+{
+
+ /**
+ *
+ * @param heuristic
+ * @param <H>
+ * @return
+ */
+ <H extends Heuristic<V, W>> WeightedPath<V, WE, W> withEuristic( H heuristic );
+
+}
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PathSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PathSourceSelector.java?rev=1236207&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PathSourceSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/PathSourceSelector.java Thu Jan 26 14:49:25 2012
@@ -0,0 +1,54 @@
+package org.apache.commons.graph.shortestpath;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.weight.OrderedMonoid;
+
+/**
+ *
+ *
+ * @param <V>
+ * @param <W>
+ * @param <WE>
+ * @param <G>
+ */
+public interface PathSourceSelector<V extends Vertex, W, WE extends WeightedEdge<W>, G extends Graph<V, WE>>
+{
+
+ /**
+ * Calculates all vertices shortest paths using the FloydWarshall's algorithm.
+ *
+ * @param <OM>
+ * @param orderedMonoid the ordered monoid needed to handle operations on weights
+ * @return a data structure which contains all vertex pairs shortest path.
+ */
+ <OM extends OrderedMonoid<W>> AllVertexPairsShortestPath<V, WE, W> applyingFloydWarshall( OM orderedMonoid );
+
+ /**
+ * Specifies the shortest path source.
+ *
+ * @param source
+ */
+ TargetSourceSelector<V, W, WE, G> from( V source );
+
+}
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestPathAlgorithmSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestPathAlgorithmSelector.java?rev=1236207&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestPathAlgorithmSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestPathAlgorithmSelector.java Thu Jan 26 14:49:25 2012
@@ -0,0 +1,57 @@
+package org.apache.commons.graph.shortestpath;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.WeightedPath;
+import org.apache.commons.graph.weight.OrderedMonoid;
+
+/**
+ *
+ *
+ * @param <V>
+ * @param <W>
+ * @param <WE>
+ * @param <G>
+ */
+public interface ShortestPathAlgorithmSelector<V extends Vertex, W, WE extends WeightedEdge<W>, G extends Graph<V, WE>>
+{
+
+ /**
+ * Calculates the shortest path using the A* algorithm.
+ *
+ * @param <OM>
+ * @param orderedMonoid the ordered monoid needed to handle operations on weights
+ * @return
+ */
+ <OM extends OrderedMonoid<W>> HeuristicBuilder<V, W, WE, G> applyingAStar( OM orderedMonoid );
+
+ /**
+ * Calculates the shortest path using the Dijkstra's algorithm.
+ *
+ * @param <OM>
+ * @param orderedMonoid the ordered monoid needed to handle operations on weights
+ * @return a path which describes the shortest path, if any, otherwise a {@link PathNotFoundException} will be thrown
+ */
+ <OM extends OrderedMonoid<W>> WeightedPath<V, WE, W> applyingDijkstra( OM orderedMonoid );
+
+}
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/TargetSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/TargetSourceSelector.java?rev=1236207&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/TargetSourceSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/TargetSourceSelector.java Thu Jan 26 14:49:25 2012
@@ -0,0 +1,54 @@
+package org.apache.commons.graph.shortestpath;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.weight.OrderedMonoid;
+
+/**
+ *
+ *
+ * @param <V>
+ * @param <W>
+ * @param <WE>
+ * @param <G>
+ */
+public interface TargetSourceSelector<V extends Vertex, W, WE extends WeightedEdge<W>, G extends Graph<V, WE>>
+{
+
+ /**
+ * Calculates the shortest path using the BellmannFord's algorithm.
+ *
+ * @param <OM>
+ * @param orderedMonoid the ordered monoid needed to handle operations on weights
+ * @return a data structure which contains all vertex pairs shortest path.
+ */
+ <OM extends OrderedMonoid<W>> AllVertexPairsShortestPath<V, WE, W> applyingBelmannFord( OM orderedMonoid );
+
+ /**
+ * Specifies the shortest path source.
+ *
+ * @param target
+ */
+ void to( V target );
+
+}