Search in sources :

Example 6 with Profile

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

the class InfoResource method getInfo.

@GET
public Info getInfo() {
    final Info info = new Info();
    info.bbox = new Envelope(storage.getBounds().minLon, storage.getBounds().maxLon, storage.getBounds().minLat, storage.getBounds().maxLat);
    for (Profile p : config.getProfiles()) {
        Info.ProfileData profileData = new Info.ProfileData(p.getName(), p.getVehicle());
        info.profiles.add(profileData);
    }
    if (config.has("gtfs.file"))
        info.profiles.add(new Info.ProfileData("pt", "pt"));
    info.elevation = hasElevation;
    List<String> encoderNames = Arrays.asList(storage.getEncodingManager().toString().split(","));
    info.supported_vehicles = new ArrayList<>(encoderNames);
    if (config.has("gtfs.file")) {
        info.supported_vehicles.add("pt");
    }
    info.import_date = storage.getProperties().get("datareader.import.date");
    info.data_date = storage.getProperties().get("datareader.data.date");
    List<EncodedValue> evList = storage.getEncodingManager().getEncodedValues();
    info.encoded_values = new LinkedHashMap<>();
    for (EncodedValue encodedValue : evList) {
        List<Object> possibleValueList = new ArrayList<>();
        if (encodedValue.getName().contains("turn_costs")) {
        // skip
        } else if (encodedValue instanceof EnumEncodedValue) {
            for (Enum o : ((EnumEncodedValue) encodedValue).getValues()) {
                possibleValueList.add(o.name());
            }
        } else if (encodedValue instanceof BooleanEncodedValue) {
            possibleValueList.add("true");
            possibleValueList.add("false");
        } else if (encodedValue instanceof DecimalEncodedValue || encodedValue instanceof IntEncodedValue) {
            possibleValueList.add(">number");
            possibleValueList.add("<number");
        } else {
            // we only add enum, boolean and numeric encoded values to the list
            continue;
        }
        info.encoded_values.put(encodedValue.getName(), possibleValueList);
    }
    return info;
}
Also used : Envelope(org.locationtech.jts.geom.Envelope) Profile(com.graphhopper.config.Profile) GET(javax.ws.rs.GET)

Example 7 with Profile

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

the class HeadingRoutingTest method createRouter.

private Router createRouter(GraphHopperStorage graph) {
    LocationIndexTree locationIndex = new LocationIndexTree(graph, new RAMDirectory());
    locationIndex.prepareIndex();
    Map<String, Profile> profilesByName = new HashMap<>();
    profilesByName.put("profile", new Profile("profile").setVehicle("car").setWeighting("fastest"));
    return new Router(graph, locationIndex, profilesByName, new PathDetailsBuilderFactory(), new TranslationMap().doImport(), new RouterConfig(), new DefaultWeightingFactory(graph, graph.getEncodingManager()), Collections.emptyMap(), Collections.emptyMap());
}
Also used : PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) TranslationMap(com.graphhopper.util.TranslationMap) Profile(com.graphhopper.config.Profile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Example 8 with Profile

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

the class GraphHopperOSMTest method testQueryLocationIndexWithBBox.

@Test
public void testQueryLocationIndexWithBBox() {
    final GraphHopper gh = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest")).setStoreOnFlush(true).setGraphHopperLocation(ghLoc).setOSMFile("../core/files/monaco.osm.gz");
    gh.importOrLoad();
    final NodeAccess na = gh.getGraphHopperStorage().getNodeAccess();
    final Collection<Integer> indexNodeList = new TreeSet<>();
    LocationIndexTree index = (LocationIndexTree) gh.getLocationIndex();
    final EdgeExplorer edgeExplorer = gh.getGraphHopperStorage().createEdgeExplorer();
    final BBox bbox = new BBox(7.422, 7.429, 43.729, 43.734);
    index.query(bbox, edgeId -> {
        EdgeIteratorState edge = gh.getGraphHopperStorage().getEdgeIteratorStateForKey(edgeId * 2);
        for (int i = 0; i < 2; i++) {
            int nodeId = i == 0 ? edge.getBaseNode() : edge.getAdjNode();
            double lat = na.getLat(nodeId);
            double lon = na.getLon(nodeId);
            if (bbox.contains(lat, lon))
                indexNodeList.add(nodeId);
        }
    });
    assertEquals(57, indexNodeList.size());
    for (int nodeId : indexNodeList) {
        if (!bbox.contains(na.getLat(nodeId), na.getLon(nodeId)))
            fail("bbox " + bbox + " should contain " + nodeId);
    }
    final Collection<Integer> bfsNodeList = new TreeSet<>();
    new BreadthFirstSearch() {

        @Override
        protected GHBitSet createBitSet() {
            return new GHBitSetImpl(gh.getGraphHopperStorage().getNodes());
        }

        @Override
        protected boolean goFurther(int nodeId) {
            double lat = na.getLat(nodeId);
            double lon = na.getLon(nodeId);
            if (bbox.contains(lat, lon))
                bfsNodeList.add(nodeId);
            return true;
        }
    }.start(edgeExplorer, index.findClosest(43.731, 7.425, EdgeFilter.ALL_EDGES).getClosestNode());
    assertTrue(indexNodeList.size() >= bfsNodeList.size(), "index size: " + indexNodeList.size() + ", bfs size: " + bfsNodeList.size());
    assertTrue(indexNodeList.containsAll(bfsNodeList), "index size: " + indexNodeList.size() + ", bfs size: " + bfsNodeList.size());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHBitSet(com.graphhopper.coll.GHBitSet) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) BBox(com.graphhopper.util.shapes.BBox) Test(org.junit.jupiter.api.Test)

Example 9 with Profile

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

the class GraphHopperOSMTest method testFootAndCar.

@Test
public void testFootAndCar() {
    final String profile1 = "profile1";
    final String profile2 = "profile2";
    final String vehicle1 = "car";
    final String vehicle2 = "foot";
    final String weighting = "fastest";
    // now all ways are imported
    instance = new GraphHopper().setProfiles(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting)).setStoreOnFlush(false).setGraphHopperLocation(ghLoc).setOSMFile(testOsm8);
    instance.importOrLoad();
    // This test is arguably a bit unfair: It expects the LocationIndex
    // to find a foot edge that is many tiles away.
    // Previously, it worked, but only because of the way the LocationIndex would traverse the Graph
    // (it would also go into CAR edges to find WALK edges).
    // Now it doesn't work like that anymore, so I set this parameter so the test doesn't fail.
    ((LocationIndexTree) instance.getLocationIndex()).setMaxRegionSearch(300);
    assertEquals(5, instance.getGraphHopperStorage().getNodes());
    assertEquals(8, instance.getGraphHopperStorage().getEdges());
    // A to D
    GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setProfile(profile1));
    assertFalse(grsp.hasErrors(), grsp.getErrors().toString());
    ResponsePath rsp = grsp.getBest();
    assertEquals(2, rsp.getPoints().size());
    // => found A and D
    assertEquals(50, rsp.getPoints().getLon(0), 1e-3);
    assertEquals(11.1, rsp.getPoints().getLat(0), 1e-3);
    assertEquals(51, rsp.getPoints().getLon(1), 1e-3);
    assertEquals(11.3, rsp.getPoints().getLat(1), 1e-3);
    // A to D not allowed for foot. But the location index will choose a node close to D accessible to FOOT
    grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setProfile(profile2));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(2, rsp.getPoints().size());
    // => found a point on edge A-B
    assertEquals(11.680, rsp.getPoints().getLat(1), 1e-3);
    assertEquals(50.644, rsp.getPoints().getLon(1), 1e-3);
    // A to E only for foot
    grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setProfile(profile2));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(2, rsp.getPoints().size());
    // A D E for car
    grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setProfile(profile1));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(3, rsp.getPoints().size());
}
Also used : CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.jupiter.api.Test)

Example 10 with Profile

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

the class GraphHopperOSMTest method testMultipleCHPreparationsInParallel.

@Test
public void testMultipleCHPreparationsInParallel() {
    HashMap<String, Integer> shortcutCountMap = new HashMap<>();
    // try all parallelization modes
    for (int threadCount = 1; threadCount < 6; threadCount++) {
        GraphHopper hopper = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile("car_profile").setVehicle("car").setWeighting("fastest"), new Profile("moto_profile").setVehicle("motorcycle").setWeighting("fastest"), new Profile("mtb_profile").setVehicle("mtb").setWeighting("fastest"), new Profile("bike_profile").setVehicle("racingbike").setWeighting("fastest"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest")).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car_profile"), new CHProfile("moto_profile"), new CHProfile("mtb_profile"), new CHProfile("bike_profile"), new CHProfile("foot_profile")).setPreparationThreads(threadCount);
        hopper.importOrLoad();
        assertEquals(5, hopper.getCHGraphs().size());
        for (Map.Entry<String, RoutingCHGraph> chGraph : hopper.getCHGraphs().entrySet()) {
            String name = chGraph.getKey();
            Integer shortcutCount = shortcutCountMap.get(name);
            if (shortcutCount == null)
                shortcutCountMap.put(name, chGraph.getValue().getShortcuts());
            else
                assertEquals((long) shortcutCount, chGraph.getValue().getShortcuts());
            String keyError = Parameters.CH.PREPARE + "error." + name;
            String valueError = hopper.getGraphHopperStorage().getProperties().get(keyError);
            assertTrue(valueError.isEmpty(), "Properties for " + name + " should NOT contain error " + valueError + " [" + threadCount + "]");
            String key = Parameters.CH.PREPARE + "date." + name;
            String value = hopper.getGraphHopperStorage().getProperties().get(key);
            assertFalse(value.isEmpty(), "Properties for " + name + " did NOT contain finish date [" + threadCount + "]");
        }
        hopper.close();
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Aggregations

Profile (com.graphhopper.config.Profile)203 LMProfile (com.graphhopper.config.LMProfile)167 CHProfile (com.graphhopper.config.CHProfile)164 Test (org.junit.jupiter.api.Test)138 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)84 GraphHopper (com.graphhopper.GraphHopper)54 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)54 GHPoint (com.graphhopper.util.shapes.GHPoint)35 ArrayList (java.util.ArrayList)29 File (java.io.File)25 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)19 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)19 PMap (com.graphhopper.util.PMap)14 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)11 BeforeAll (org.junit.jupiter.api.BeforeAll)10 Weighting (com.graphhopper.routing.weighting.Weighting)9 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)8 TranslationMap (com.graphhopper.util.TranslationMap)7 Snap (com.graphhopper.storage.index.Snap)6 GHRequest (com.graphhopper.GHRequest)5