diff --git a/src/main/java/com/bmwcarit/barefoot/topology/Dijkstra.java b/src/main/java/com/bmwcarit/barefoot/topology/Dijkstra.java index 4eebacd9..96111781 100755 --- a/src/main/java/com/bmwcarit/barefoot/topology/Dijkstra.java +++ b/src/main/java/com/bmwcarit/barefoot/topology/Dijkstra.java @@ -122,7 +122,7 @@ public int compareTo(Mark other) { logger.trace("initialize target {} with edge {} and fraction {}", target, target.edge().id(), target.fraction()); - if (!targetEdges.containsKey(target)) { + if (!targetEdges.containsKey(target.edge())) { targetEdges.put(target.edge(), new HashSet<>(Arrays.asList(target))); } else { targetEdges.get(target.edge()).add(target); diff --git a/src/test/java/com/bmwcarit/barefoot/topology/DijkstraTest.java b/src/test/java/com/bmwcarit/barefoot/topology/DijkstraTest.java index 3ee2527d..a3422adb 100644 --- a/src/test/java/com/bmwcarit/barefoot/topology/DijkstraTest.java +++ b/src/test/java/com/bmwcarit/barefoot/topology/DijkstraTest.java @@ -373,6 +373,40 @@ public void testShortestPath() { assertNull(route); } + { + // (0.7, 100) + 50 + 100 + (0.1, 200) = 240 + // (0.7, 100) + 50 + 100 + (0.8, 200) = 380 + + Set> sources = new HashSet<>(); + sources.add(new Point<>(map.get(0), 0.3)); + sources.add(new Point<>(map.get(1), 0.7)); + + Set> targets = new HashSet<>(); + targets.add(new Point<>(map.get(14), 0.1)); + targets.add(new Point<>(map.get(14), 0.8)); + + Map, Tuple, List>> routes = + router.route(sources, targets, new Weight(), null, null); + + Map> paths = new HashMap<>(); + paths.put(14L, new LinkedList<>(Arrays.asList(0L, 4L, 8L, 14L))); + + assertEquals(2, routes.size()); + + for (Entry, Tuple, List>> pair : routes.entrySet()) { + List route = pair.getValue().two(); + List path = paths.get(pair.getKey().edge().id()); + + assertNotNull(route); + assertEquals(path.get(0).longValue(), pair.getValue().one().edge().id()); + assertEquals(path.size(), route.size()); + + int i = 0; + for (Road road : route) { + assertEquals((long) path.get(i++), road.id()); + } + } + } } } }