use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class LMAlgoFactoryDecorator method addWeighting.
public LMAlgoFactoryDecorator addWeighting(String weighting) {
String[] str = weighting.split("\\|");
double value = -1;
if (str.length > 1) {
PMap map = new PMap(weighting);
value = map.getDouble("maximum", -1);
}
weightingsAsStrings.add(str[0]);
maximumWeights.put(str[0], value);
return this;
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class AlternativeRouteCHTest method testRelaxMaximumStretch.
@Test
public void testRelaxMaximumStretch() {
GraphHopperStorage g = createTestGraph(em);
PMap hints = new PMap();
hints.putObject("alternative_route.max_weight_factor", 4);
hints.putObject("alternative_route.local_optimality_factor", 0.5);
hints.putObject("alternative_route.max_paths", 4);
RoutingCHGraph routingCHGraph = prepareCH(g);
AlternativeRouteCH altDijkstra = new AlternativeRouteCH(routingCHGraph, hints);
List<AlternativeRouteCH.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 10);
assertEquals(4, pathInfos.size());
// 4 -> 11 -> 12 is shorter than 4 -> 10 -> 12 (11 is an admissible via node), AND
// 4 -> 11 -> 12 -> 10 is not too long compared to 4 -> 10
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCHTest method testCalcOtherAlternatives.
@Test
public void testCalcOtherAlternatives() {
GraphHopperStorage g = createTestGraph(em);
PMap hints = new PMap();
hints.putObject("alternative_route.max_weight_factor", 4);
hints.putObject("alternative_route.local_optimality_factor", 0.5);
hints.putObject("alternative_route.max_paths", 4);
RoutingCHGraph routingCHGraph = prepareCH(g);
AlternativeRouteEdgeCH altDijkstra = new AlternativeRouteEdgeCH(routingCHGraph, hints);
List<AlternativeRouteEdgeCH.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(10, 5);
assertEquals(2, pathInfos.size());
assertEquals(IntArrayList.from(10, 4, 3, 6, 5), pathInfos.get(0).path.calcNodes());
assertEquals(IntArrayList.from(10, 12, 11, 4, 3, 6, 5), pathInfos.get(1).path.calcNodes());
// The shortest path works (no restrictions on the way back
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class ShortestPathTreeTest method testSPTAndIsochrone25Seconds.
@Test
public void testSPTAndIsochrone25Seconds() {
List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
ShortestPathTree instance = new ShortestPathTree(graph, new FastestWeighting(carEncoder, new PMap()), false, TraversalMode.NODE_BASED);
instance.setTimeLimit(25_000);
instance.search(0, result::add);
assertEquals(3, result.size());
assertAll(() -> assertEquals(0, result.get(0).time), () -> assertEquals(0, result.get(0).node), () -> assertEquals(9000, result.get(1).time), () -> assertEquals(4, result.get(1).node), () -> assertEquals(18000, result.get(2).time), () -> assertEquals(6, result.get(2).node));
Collection<ShortestPathTree.IsoLabel> isochroneEdges = instance.getIsochroneEdges();
assertArrayEquals(new int[] { 1, 7 }, isochroneEdges.stream().mapToInt(l -> l.node).sorted().toArray());
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class ShortestPathTreeTest method testEdgeBasedWithForbiddenUTurns.
@Test
public void testEdgeBasedWithForbiddenUTurns() {
FastestWeighting fastestWeighting = new FastestWeighting(carEncoder, new PMap(), FORBIDDEN_UTURNS);
List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
ShortestPathTree instance = new ShortestPathTree(graph, fastestWeighting, false, TraversalMode.EDGE_BASED);
instance.setTimeLimit(Double.MAX_VALUE);
instance.search(0, result::add);
// Every directed edge of the graph, plus the origin, minus one edge for the dead end, are traversed.
assertEquals(countDirectedEdges(graph) + 1 - 1, result.size());
assertAll(() -> assertEquals(0, result.get(0).time), () -> assertEquals(9000, result.get(1).time), () -> assertEquals(18000, result.get(2).time), () -> assertEquals(25200, result.get(3).time), () -> assertEquals(27000, result.get(4).time), () -> assertEquals(34200, result.get(5).time), () -> assertEquals(36000, result.get(6).time), () -> assertEquals(50400, result.get(7).time), () -> assertEquals(50400, result.get(8).time), () -> assertEquals(54000, result.get(9).time), () -> assertEquals(55800, result.get(10).time), () -> assertEquals(60300, result.get(11).time), () -> assertEquals(61200, result.get(12).time), () -> assertEquals(61200, result.get(13).time), () -> assertEquals(61200, result.get(14).time), () -> assertEquals(72000, result.get(15).time), () -> assertEquals(81000, result.get(16).time), () -> assertEquals(90000, result.get(17).time), () -> assertEquals(97200, result.get(18).time), () -> assertEquals(126000, result.get(19).time));
}
Aggregations