Search in sources :

Example 21 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class LMPreparationHandler method setLMProfiles.

/**
 * Enables the use of landmarks to reduce query times.
 */
public LMPreparationHandler setLMProfiles(Collection<LMProfile> lmProfiles) {
    this.lmProfiles.clear();
    this.maximumWeights.clear();
    for (LMProfile profile : lmProfiles) {
        if (profile.usesOtherPreparation())
            continue;
        maximumWeights.put(profile.getProfile(), profile.getMaximumLMWeight());
    }
    this.lmProfiles.addAll(lmProfiles);
    return this;
}
Also used : LMProfile(com.graphhopper.config.LMProfile)

Example 22 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class LMProfileSelectorTest method multipleProfiles.

@Test
public void multipleProfiles() {
    List<Profile> profiles = Arrays.asList(fastCar, fastBike);
    List<LMProfile> lmProfiles = Arrays.asList(new LMProfile("fast_car"), new LMProfile("fast_bike"));
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, null, null);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", "fastest", null, null);
    assertProfileFound(profiles.get(1), profiles, lmProfiles, "bike", null, null, null);
    assertProfileFound(profiles.get(1), profiles, lmProfiles, "bike", "fastest", null, null);
    // not specific enough
    String error = assertLMProfileSelectionError(MULTIPLE_MATCHES_ERROR, profiles, lmProfiles, null, "fastest", null, null);
    assertTrue(error.contains("requested:  fastest|*|turn_costs=*"), error);
    assertTrue(error.contains("matched:   [fastest|car|turn_costs=false, fastest|bike|turn_costs=false]"), error);
    assertTrue(error.contains("available: [fastest|car|turn_costs=false, fastest|bike|turn_costs=false]"), error);
    assertLMProfileSelectionError(NO_MATCH_ERROR, profiles, lmProfiles, null, "shortest", null, null);
    // u_turn_costs is set, but lm should not really care
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, null, 54);
    assertProfileFound(profiles.get(0), profiles, lmProfiles, "car", null, false, 64);
}
Also used : LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 23 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class LMProfileSelectorTest method assertProfileFound.

private void assertProfileFound(Profile expectedProfile, List<Profile> profiles, List<LMProfile> lmProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
    PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
    try {
        Profile selectedProfile = new ProfileResolver(encodingManager, profiles, Collections.<CHProfile>emptyList(), lmProfiles).selectProfileLM(hintsMap);
        assertEquals(expectedProfile, selectedProfile);
    } catch (IllegalArgumentException e) {
        fail("no profile found\nexpected: " + expectedProfile + "\nerror: " + e.getMessage());
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) ProfileResolver(com.graphhopper.routing.ProfileResolver) PMap(com.graphhopper.util.PMap) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 24 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class CHProfileSelectorTest method assertProfileFound.

private void assertProfileFound(Profile expectedProfile, List<Profile> profiles, List<CHProfile> chProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
    PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
    try {
        Profile selectedProfile = new ProfileResolver(encodingManager, profiles, chProfiles, Collections.<LMProfile>emptyList()).selectProfileCH(hintsMap);
        assertEquals(expectedProfile, selectedProfile);
    } catch (IllegalArgumentException e) {
        fail("no profile found\nexpected: " + expectedProfile + "\nerror: " + e.getMessage());
    }
}
Also used : ProfileResolver(com.graphhopper.routing.ProfileResolver) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 25 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopperStorageLMTest method testLoad.

@Test
public void testLoad() {
    String defaultGraphLoc = "./target/ghstorage_lm";
    Helper.removeDir(new File(defaultGraphLoc));
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carFlagEncoder).add(Subnetwork.create("my_profile")).build();
    GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(defaultGraphLoc, true).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(0, 1).setDistance(1));
    updateDistancesFor(graph, 0, 0.00, 0.00);
    updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_0_1));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(1, 2).setDistance(1));
    updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_1_2));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    // does lm preparation
    hopper.importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
    hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    // just loads the LM data
    hopper.importOrLoad();
    assertEquals(1, em.fetchEdgeEncoders().size());
    assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) LMProfile(com.graphhopper.config.LMProfile) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Aggregations

LMProfile (com.graphhopper.config.LMProfile)48 Profile (com.graphhopper.config.Profile)41 CHProfile (com.graphhopper.config.CHProfile)33 Test (org.junit.jupiter.api.Test)24 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)15 PMap (com.graphhopper.util.PMap)12 GraphHopper (com.graphhopper.GraphHopper)10 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)6 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 File (java.io.File)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 Gpx (com.graphhopper.jackson.Gpx)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 MapMatching (com.graphhopper.matching.MapMatching)3 MatchResult (com.graphhopper.matching.MatchResult)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3