Search in sources :

Example 1 with PMap

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;
}
Also used : PMap(com.graphhopper.util.PMap)

Example 2 with PMap

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
}
Also used : PMap(com.graphhopper.util.PMap) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 3 with PMap

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
}
Also used : PMap(com.graphhopper.util.PMap) Test(org.junit.jupiter.api.Test)

Example 4 with PMap

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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Collection(java.util.Collection) PMap(com.graphhopper.util.PMap) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) GHUtility(com.graphhopper.util.GHUtility) EncodingManager(com.graphhopper.routing.util.EncodingManager) ArrayList(java.util.ArrayList) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test) TurnCostProvider(com.graphhopper.routing.weighting.TurnCostProvider) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) TraversalMode(com.graphhopper.routing.util.TraversalMode) Assertions(org.junit.jupiter.api.Assertions) Graph(com.graphhopper.storage.Graph) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) ArrayList(java.util.ArrayList) PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 5 with PMap

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));
}
Also used : ArrayList(java.util.ArrayList) PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Aggregations

PMap (com.graphhopper.util.PMap)50 Test (org.junit.jupiter.api.Test)27 LMProfile (com.graphhopper.config.LMProfile)12 Profile (com.graphhopper.config.Profile)12 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)12 CHProfile (com.graphhopper.config.CHProfile)10 ArrayList (java.util.ArrayList)10 GraphHopper (com.graphhopper.GraphHopper)6 MapMatching (com.graphhopper.matching.MapMatching)5 MatchResult (com.graphhopper.matching.MatchResult)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)5 CHRoutingAlgorithmFactory (com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)5 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)5 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Gpx (com.graphhopper.jackson.Gpx)4 ReaderWay (com.graphhopper.reader.ReaderWay)4 ProfileResolver (com.graphhopper.routing.ProfileResolver)4 Weighting (com.graphhopper.routing.weighting.Weighting)4 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)4