Search in sources :

Example 36 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class AlternativeRouteCHTest method testCalcAlternatives.

@Test
public void testCalcAlternatives() {
    GraphHopperStorage g = createTestGraph(em);
    PMap hints = new PMap();
    hints.putObject("alternative_route.max_weight_factor", 2.3);
    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(3, pathInfos.size());
// 4 -> 11 -> 12 is shorter than 4 -> 10 -> 12 (11 is an admissible via node), BUT
// 4 -> 11 -> 12 -> 10 is 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 37 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class PriorityRoutingTest method testMaxPriority.

@Test
void testMaxPriority() {
    BikeFlagEncoder encoder = new BikeFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 48.0, 11.0);
    na.setNode(1, 48.1, 11.1);
    na.setNode(2, 48.2, 11.2);
    na.setNode(3, 48.3, 11.3);
    na.setNode(4, 48.1, 11.0);
    na.setNode(5, 48.2, 11.1);
    // 0 - 1 - 2 - 3
    // \- 4 - 5 -/
    double dist1 = 0;
    dist1 += maxSpeedEdge(em, graph, 0, 1, encoder, 1.0).getDistance();
    dist1 += maxSpeedEdge(em, graph, 1, 2, encoder, 1.0).getDistance();
    dist1 += maxSpeedEdge(em, graph, 2, 3, encoder, 1.0).getDistance();
    final double maxPrio = PriorityCode.getFactor(PriorityCode.BEST.getValue());
    double dist2 = 0;
    dist2 += maxSpeedEdge(em, graph, 0, 4, encoder, maxPrio).getDistance();
    dist2 += maxSpeedEdge(em, graph, 4, 5, encoder, maxPrio).getDistance();
    dist2 += maxSpeedEdge(em, graph, 5, 3, encoder, maxPrio).getDistance();
    // the routes 0-1-2-3 and 0-4-5-3 have similar distances (and use max speed everywhere)
    // ... but the shorter route 0-1-2-3 has smaller priority
    assertEquals(40101, dist1, 1);
    assertEquals(43005, dist2, 1);
    // A* and Dijkstra should yield the same path (the max priority must be taken into account by weighting.getMinWeight)
    {
        PriorityWeighting weighting = new PriorityWeighting(encoder, new PMap(), TurnCostProvider.NO_TURN_COST_PROVIDER);
        Path pathDijkstra = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        Path pathAStar = new AStar(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        assertEquals(pathDijkstra.calcNodes(), pathAStar.calcNodes());
        assertEquals(IntArrayList.from(0, 4, 5, 3), pathAStar.calcNodes());
    }
    {
        CustomModel customModel = new CustomModel();
        CustomWeighting weighting = CustomModelParser.createWeighting(encoder, em, TurnCostProvider.NO_TURN_COST_PROVIDER, customModel);
        Path pathDijkstra = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        Path pathAStar = new AStar(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        assertEquals(pathDijkstra.calcNodes(), pathAStar.calcNodes());
        assertEquals(IntArrayList.from(0, 4, 5, 3), pathAStar.calcNodes());
    }
    {
        CustomModel customModel = new CustomModel();
        // now we even increase the priority in the custom model, which also needs to be accounted for in weighting.getMinWeight
        customModel.addToPriority(Statement.If("road_class == MOTORWAY", Statement.Op.MULTIPLY, 3));
        CustomWeighting weighting = CustomModelParser.createWeighting(encoder, em, TurnCostProvider.NO_TURN_COST_PROVIDER, customModel);
        Path pathDijkstra = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        Path pathAStar = new AStar(graph, weighting, TraversalMode.NODE_BASED).calcPath(0, 3);
        assertEquals(pathDijkstra.calcNodes(), pathAStar.calcNodes());
        assertEquals(IntArrayList.from(0, 4, 5, 3), pathAStar.calcNodes());
    }
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) PMap(com.graphhopper.util.PMap) CustomModel(com.graphhopper.util.CustomModel) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) CustomWeighting(com.graphhopper.routing.weighting.custom.CustomWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) PriorityWeighting(com.graphhopper.routing.weighting.PriorityWeighting) Test(org.junit.jupiter.api.Test)

Example 38 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class DijkstraBidirectionCHTest method createCHAlgo.

private RoutingAlgorithm createCHAlgo(RoutingCHGraph chGraph, boolean withSOD) {
    PMap opts = new PMap();
    if (!withSOD) {
        opts.putObject("stall_on_demand", false);
    }
    opts.putObject(ALGORITHM, DIJKSTRA_BI);
    return new CHRoutingAlgorithmFactory(chGraph).createAlgo(opts);
}
Also used : PMap(com.graphhopper.util.PMap) CHRoutingAlgorithmFactory(com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)

Example 39 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class AlternativeRouteEdgeCHTest method testCalcAlternatives.

@Test
public void testCalcAlternatives() {
    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(5, 10);
    assertEquals(2, pathInfos.size());
    assertEquals(IntArrayList.from(5, 6, 7, 8, 4, 10), pathInfos.get(0).path.calcNodes());
    assertEquals(IntArrayList.from(5, 1, 9, 2, 3, 4, 10), pathInfos.get(1).path.calcNodes());
// 3 -> 4 -> 11 is forbidden
// 6 -> 3 -> 4 is forbidden
}
Also used : PMap(com.graphhopper.util.PMap) Test(org.junit.jupiter.api.Test)

Example 40 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class ProfileResolverTest method defaultWeighting.

@Test
public void defaultWeighting() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("bike,car,foot"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // without specifying the weighting we get an error, because there are multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // use weighting to specify profile
    assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
    assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "fastest")).getName());
}
Also used : PMap(com.graphhopper.util.PMap) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) CHProfileSelectorTest(com.graphhopper.routing.ch.CHProfileSelectorTest) LMProfileSelectorTest(com.graphhopper.routing.lm.LMProfileSelectorTest)

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