Search in sources :

Example 46 with PMap

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

the class TrafficChangeWithNodeOrderingReusingTest method checkCorrectness.

private static void checkCorrectness(GraphHopperStorage ghStorage, CHConfig chConfig, long seed, long numQueries) {
    LOGGER.info("checking correctness");
    RoutingCHGraph chGraph = ghStorage.createCHGraph(ghStorage.createCHStorage(chConfig), chConfig);
    Random rnd = new Random(seed);
    int numFails = 0;
    for (int i = 0; i < numQueries; ++i) {
        Dijkstra dijkstra = new Dijkstra(ghStorage, chConfig.getWeighting(), TraversalMode.NODE_BASED);
        RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(chGraph).createAlgo(new PMap());
        int from = rnd.nextInt(ghStorage.getNodes());
        int to = rnd.nextInt(ghStorage.getNodes());
        double dijkstraWeight = dijkstra.calcPath(from, to).getWeight();
        double chWeight = chAlgo.calcPath(from, to).getWeight();
        double error = Math.abs(dijkstraWeight - chWeight);
        if (error > 1) {
            System.out.println("failure from " + from + " to " + to + " dijkstra: " + dijkstraWeight + " ch: " + chWeight);
            numFails++;
        }
    }
    LOGGER.info("number of failed queries: " + numFails);
    assertEquals(0, numFails);
}
Also used : Random(java.util.Random) PMap(com.graphhopper.util.PMap) CHRoutingAlgorithmFactory(com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)

Example 47 with PMap

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

the class MapMatching2Test method testIssue127.

@Test
public void testIssue127() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    // query with two identical points
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-127.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(0, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 48 with PMap

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

the class ShortestPathTreeTest method testNoTimeLimit.

@Test
public void testNoTimeLimit() {
    List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
    ShortestPathTree instance = new ShortestPathTree(graph, new FastestWeighting(carEncoder, new PMap()), false, TraversalMode.NODE_BASED);
    instance.setTimeLimit(Double.MAX_VALUE);
    instance.search(0, result::add);
    assertEquals(9, 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), () -> assertEquals(25200, result.get(3).time), () -> assertEquals(1, result.get(3).node), () -> assertEquals(27000, result.get(4).time), () -> assertEquals(7, result.get(4).node), () -> assertEquals(36000, result.get(5).time), () -> assertEquals(5, result.get(5).node), () -> assertEquals(54000, result.get(6).time), () -> assertEquals(2, result.get(6).node), () -> assertEquals(55800, result.get(7).time), () -> assertEquals(3, result.get(7).node), () -> assertEquals(60300, result.get(8).time), () -> assertEquals(8, result.get(8).node));
}
Also used : ArrayList(java.util.ArrayList) PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 49 with PMap

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

the class ShortestPathTreeTest method testEdgeBasedWithFreeUTurns.

@Test
public void testEdgeBasedWithFreeUTurns() {
    List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
    ShortestPathTree instance = new ShortestPathTree(graph, new FastestWeighting(carEncoder, new PMap()), false, TraversalMode.EDGE_BASED);
    instance.setTimeLimit(Double.MAX_VALUE);
    instance.search(0, result::add);
    // The origin, and every end of every directed edge, are traversed.
    assertEquals(countDirectedEdges(graph) + 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(36000, result.get(7).time), () -> assertEquals(50400, result.get(8).time), () -> assertEquals(50400, result.get(9).time), () -> assertEquals(54000, result.get(10).time), () -> assertEquals(55800, result.get(11).time), () -> assertEquals(60300, result.get(12).time), () -> assertEquals(61200, result.get(13).time), () -> assertEquals(61200, result.get(14).time), () -> assertEquals(61200, result.get(15).time), () -> assertEquals(64800, result.get(16).time), () -> assertEquals(72000, result.get(17).time), () -> assertEquals(81000, result.get(18).time), () -> assertEquals(97200, result.get(19).time), () -> assertEquals(126000, result.get(20).time));
}
Also used : ArrayList(java.util.ArrayList) PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 50 with PMap

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

the class ShortestPathTreeTest method testSPT26Seconds.

@Test
public void testSPT26Seconds() {
    List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
    ShortestPathTree instance = new ShortestPathTree(graph, new FastestWeighting(carEncoder, new PMap()), false, TraversalMode.NODE_BASED);
    instance.setTimeLimit(26_000);
    instance.search(0, result::add);
    assertEquals(4, 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));
}
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