Search in sources :

Example 6 with PMap

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

the class ShortestPathTreeTest method testEdgeBasedWithFinitePositiveUTurnCost.

@Test
public void testEdgeBasedWithFinitePositiveUTurnCost() {
    TimeBasedUTurnCost turnCost = new TimeBasedUTurnCost(80000);
    FastestWeighting fastestWeighting = new FastestWeighting(carEncoder, new PMap(), turnCost);
    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);
    // Just like with forbidden U-turns, but last thing is I can get out of the dead-end
    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(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), () -> assertEquals(144800, 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 7 with PMap

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

the class ShortestPathTreeTest method testEdgeBasedWithSmallerUTurnCost.

@Test
public void testEdgeBasedWithSmallerUTurnCost() {
    TimeBasedUTurnCost turnCost = new TimeBasedUTurnCost(20000);
    FastestWeighting fastestWeighting = new FastestWeighting(carEncoder, new PMap(), turnCost);
    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);
    // Something in between
    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(50400, result.get(7).time), () -> assertEquals(50400, result.get(8).time), () -> assertEquals(54000, result.get(9).time), () -> assertEquals(55800, result.get(10).time), () -> assertEquals(56000, 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(72000, result.get(16).time), () -> assertEquals(81000, result.get(17).time), () -> assertEquals(84800, 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 8 with PMap

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

the class ShortestPathTreeTest method testSearchByDistance.

@Test
public void testSearchByDistance() {
    List<ShortestPathTree.IsoLabel> result = new ArrayList<>();
    ShortestPathTree instance = new ShortestPathTree(graph, new FastestWeighting(carEncoder, new PMap()), false, TraversalMode.NODE_BASED);
    instance.setDistanceLimit(110.0);
    instance.search(5, result::add);
    assertEquals(6, result.size());
    // We are searching by time, but terminating by distance.
    // Expected distance values are out of search order,
    // and we cannot terminate at 110 because we still need the 70's.
    // And we do not want the node at 120, even though it is within the space of the search.
    assertAll(() -> assertEquals(0.0, result.get(0).distance), () -> assertEquals(50.0, result.get(1).distance), () -> assertEquals(110.0, result.get(2).distance), () -> assertEquals(70.0, result.get(3).distance), () -> assertEquals(70.0, result.get(4).distance), () -> assertEquals(70.0, result.get(5).distance));
}
Also used : ArrayList(java.util.ArrayList) PMap(com.graphhopper.util.PMap) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 9 with PMap

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

the class ProfileResolverTest method defaultVehicle.

@Test
public void defaultVehicle() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("car,foot,bike"), Arrays.asList(new Profile("my_bike").setVehicle("bike"), new Profile("your_car").setVehicle("car")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // without specifying the vehicle we get an error, because there are multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // use vehicle to specify profile
    assertEquals("your_car", profileResolver.resolveProfile(new PMap().putObject("vehicle", "car")).getName());
    assertEquals("my_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike")).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)

Example 10 with PMap

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

the class ProfileResolverTest method missingProfiles.

@Test
public void missingProfiles() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("car,bike"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // there is a car encoder but no associated profile
    assertProfileNotFound(profileResolver, new PMap().putObject("vehicle", "car"));
    // if we do not specify a vehicle or weighting we even have multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // if we specify the weighting its clear which profile we want
    assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
    // setting the vehicle to bike is not enough
    assertMultiMatchError(profileResolver, new PMap().putObject("vehicle", "bike"), "There are multiple profiles matching your request");
    // if we set the weighting as well it works
    assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike").putObject("weighting", "fastest")).getName());
    assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike").putObject("weighting", "shortest")).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