File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
main/java/org/javanetworkanalyzer
test/java/org/javanetworkanalyzer/alg Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -210,11 +210,17 @@ public int compare(V v1, V v2) {
210210 * limited by the given radius. The shortest path "tree" we return may
211211 * contain multiple shortest paths.
212212 *
213+ * Note: {@link GraphSearchAlgorithm#reconstructTraversalGraph()} should not
214+ * be used when limiting by radius as it will include edges to vertices with
215+ * a distance greater than the radius.
216+ *
213217 * @param radius The radius to limit by
214218 * @return The SPT/traversal graph from the last start node {@link #calculate}
215219 * was called on
216220 */
217- public TraversalGraph <V , E > reconstructTraversalGraphLimitedByRadius (double radius ) {
221+ // TODO: Make {@link GraphSearchAlgorithm#reconstructTraversalGraph()} call
222+ // this method with an argument of Double.POSITIVE_INFINITY.
223+ public TraversalGraph <V , E > reconstructTraversalGraph (double radius ) {
218224
219225 if (currentStartNode == null ) {
220226 throw new IllegalStateException ("You must call #calculate before " +
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public class VDijkstra<V extends VDijkstra, E>
4444 * Length of a shortest path starting from a certain source leading to this
4545 * node (Dijkstra).
4646 */
47- private double distance ;
47+ private double distance = DEFAULT_DISTANCE ;
4848
4949 /**
5050 * Constructor: Sets the id.
Original file line number Diff line number Diff line change @@ -49,6 +49,23 @@ public class DijkstraCormenTest {
4949 private VDijkstra v5 ;
5050 private static final double TOLERANCE = 0.0 ;
5151
52+ @ Test
53+ public void testWDLimitedByRadius () throws NoSuchMethodException {
54+ dijkstra = new Dijkstra <VDijkstra , Edge >(graph );
55+ final double radius = 12.0 ;
56+ dijkstra .calculate (v3 , radius );
57+ assertEquals (11 , v1 .getDistance (), TOLERANCE );
58+ assertTrue (v2 .getDistance () > radius );
59+ assertEquals (0 , v3 .getDistance (), TOLERANCE );
60+ assertTrue (v2 .getDistance () > radius );
61+ assertEquals (4 , v5 .getDistance (), TOLERANCE );
62+ sPT = dijkstra .reconstructTraversalGraph (radius );
63+ assertTrue (sPT .getRoot ().equals (v3 ));
64+ assertTrue (sPT .edgeSet ().size () == 2 );
65+ assertTrue (sPT .containsEdge (v3 , v5 ));
66+ assertTrue (sPT .containsEdge (v5 , v1 ));
67+ }
68+
5269 @ Test
5370 public void testWD () throws NoSuchMethodException {
5471
You can’t perform that action at this time.
0 commit comments