Search in sources :

Example 31 with PMap

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

the class MiniGraphUI method main.

public static void main(String[] strs) {
    PMap args = PMap.read(strs);
    args.putObject("datareader.file", args.getString("datareader.file", "core/files/monaco.osm.gz"));
    args.putObject("graph.location", args.getString("graph.location", "tools/target/mini-graph-ui-gh"));
    args.putObject("graph.flag_encoders", args.getString("graph.flag_encoders", "car"));
    GraphHopperConfig ghConfig = new GraphHopperConfig(args);
    ghConfig.setProfiles(Arrays.asList(new Profile("profile").setVehicle("car").setWeighting("fastest")));
    ghConfig.setCHProfiles(Arrays.asList(new CHProfile("profile")));
    ghConfig.setLMProfiles(Arrays.asList(new LMProfile("profile")));
    GraphHopper hopper = new GraphHopper().init(ghConfig).importOrLoad();
    boolean debug = args.getBool("minigraphui.debug", false);
    boolean useCH = args.getBool("minigraphui.useCH", false);
    new MiniGraphUI(hopper, debug, useCH).visualize();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GraphHopperConfig(com.graphhopper.GraphHopperConfig)

Example 32 with PMap

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

the class DefaultWeightingFactory method createWeighting.

@Override
public Weighting createWeighting(Profile profile, PMap requestHints, boolean disableTurnCosts) {
    // Merge profile hints with request hints, the request hints take precedence.
    // Note that so far we do not check if overwriting the profile hints actually works with the preparation
    // for LM/CH. Later we should also limit the number of parameters that can be used to modify the profile.
    // todo: since we are not dealing with block_area here yet we cannot really apply any merging rules
    // for it, see discussion here: https://github.com/graphhopper/graphhopper/pull/1958#discussion_r395462901
    PMap hints = new PMap();
    hints.putAll(profile.getHints());
    hints.putAll(requestHints);
    FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle());
    TurnCostProvider turnCostProvider;
    if (profile.isTurnCosts() && !disableTurnCosts) {
        if (!encoder.supportsTurnCosts())
            throw new IllegalArgumentException("Encoder " + encoder + " does not support turn costs");
        int uTurnCosts = hints.getInt(Parameters.Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS);
        turnCostProvider = new DefaultTurnCostProvider(encoder, ghStorage.getTurnCostStorage(), uTurnCosts);
    } else {
        turnCostProvider = NO_TURN_COST_PROVIDER;
    }
    String weightingStr = toLowerCase(profile.getWeighting());
    if (weightingStr.isEmpty())
        throw new IllegalArgumentException("You have to specify a weighting");
    Weighting weighting = null;
    if (CustomWeighting.NAME.equalsIgnoreCase(weightingStr)) {
        if (!(profile instanceof CustomProfile))
            throw new IllegalArgumentException("custom weighting requires a CustomProfile but was profile=" + profile.getName());
        CustomModel queryCustomModel = requestHints.getObject(CustomModel.KEY, null);
        CustomProfile customProfile = (CustomProfile) profile;
        if (queryCustomModel != null)
            queryCustomModel.checkLMConstraints(customProfile.getCustomModel());
        queryCustomModel = CustomModel.merge(customProfile.getCustomModel(), queryCustomModel);
        weighting = CustomModelParser.createWeighting(encoder, encodingManager, turnCostProvider, queryCustomModel);
    } else if ("shortest".equalsIgnoreCase(weightingStr)) {
        weighting = new ShortestWeighting(encoder, turnCostProvider);
    } else if ("fastest".equalsIgnoreCase(weightingStr)) {
        if (encoder.supports(PriorityWeighting.class))
            weighting = new PriorityWeighting(encoder, hints, turnCostProvider);
        else
            weighting = new FastestWeighting(encoder, hints, turnCostProvider);
    } else if ("curvature".equalsIgnoreCase(weightingStr)) {
        if (encoder.supports(CurvatureWeighting.class))
            weighting = new CurvatureWeighting(encoder, hints, turnCostProvider);
    } else if ("short_fastest".equalsIgnoreCase(weightingStr)) {
        weighting = new ShortFastestWeighting(encoder, hints, turnCostProvider);
    }
    if (weighting == null)
        throw new IllegalArgumentException("Weighting '" + weightingStr + "' not supported");
    return weighting;
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) PMap(com.graphhopper.util.PMap) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) CustomModel(com.graphhopper.util.CustomModel) CustomWeighting(com.graphhopper.routing.weighting.custom.CustomWeighting)

Example 33 with PMap

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

the class LowLevelAPIExample method useContractionHierarchiesToMakeQueriesFaster.

public static void useContractionHierarchiesToMakeQueriesFaster() {
    // Creating and saving the graph
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    Weighting weighting = new FastestWeighting(encoder);
    CHConfig chConfig = CHConfig.nodeBased("my_profile", weighting);
    GraphHopperStorage graph = new GraphBuilder(em).setRAM(graphLocation, true).create();
    graph.flush();
    // Set node coordinates and build location index
    NodeAccess na = graph.getNodeAccess();
    graph.edge(0, 1).set(encoder.getAccessEnc(), true).set(encoder.getAverageSpeedEnc(), 10).setDistance(1020);
    na.setNode(0, 15.15, 20.20);
    na.setNode(1, 15.25, 20.21);
    // Prepare the graph for fast querying ...
    graph.freeze();
    PrepareContractionHierarchies pch = PrepareContractionHierarchies.fromGraphHopperStorage(graph, chConfig);
    PrepareContractionHierarchies.Result pchRes = pch.doWork();
    RoutingCHGraph chGraph = graph.createCHGraph(pchRes.getCHStorage(), pchRes.getCHConfig());
    // create location index
    LocationIndexTree index = new LocationIndexTree(graph, graph.getDirectory());
    index.prepareIndex();
    // calculate a path with location index
    Snap fromSnap = index.findClosest(15.15, 20.20, EdgeFilter.ALL_EDGES);
    Snap toSnap = index.findClosest(15.25, 20.21, EdgeFilter.ALL_EDGES);
    QueryGraph queryGraph = QueryGraph.create(graph, fromSnap, toSnap);
    BidirRoutingAlgorithm algo = new CHRoutingAlgorithmFactory(chGraph, queryGraph).createAlgo(new PMap());
    Path path = algo.calcPath(fromSnap.getClosestNode(), toSnap.getClosestNode());
    assert Helper.round(path.getDistance(), -2) == 1000;
}
Also used : Path(com.graphhopper.routing.Path) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) PMap(com.graphhopper.util.PMap) Snap(com.graphhopper.storage.index.Snap) BidirRoutingAlgorithm(com.graphhopper.routing.BidirRoutingAlgorithm) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CHRoutingAlgorithmFactory(com.graphhopper.routing.ch.CHRoutingAlgorithmFactory) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 34 with PMap

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

the class EncodingManager method parseEncoderString.

static FlagEncoder parseEncoderString(FlagEncoderFactory factory, String encoderString) {
    if (!encoderString.equals(toLowerCase(encoderString)))
        throw new IllegalArgumentException("An upper case name for the FlagEncoder is not allowed: " + encoderString);
    encoderString = encoderString.trim();
    if (encoderString.isEmpty())
        throw new IllegalArgumentException("FlagEncoder cannot be empty. " + encoderString);
    String entryVal = "";
    if (encoderString.contains("|")) {
        entryVal = encoderString;
        encoderString = encoderString.split("\\|")[0];
    }
    PMap configuration = new PMap(entryVal);
    return factory.createFlagEncoder(encoderString, configuration);
}
Also used : PMap(com.graphhopper.util.PMap)

Example 35 with PMap

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

the class EncodingManager method parseEncodedValueString.

static EncodedValue parseEncodedValueString(EncodedValueFactory factory, String encodedValueString) {
    if (!encodedValueString.equals(toLowerCase(encodedValueString)))
        throw new IllegalArgumentException("Use lower case for EncodedValues: " + encodedValueString);
    encodedValueString = encodedValueString.trim();
    if (encodedValueString.isEmpty())
        throw new IllegalArgumentException("EncodedValue cannot be empty. " + encodedValueString);
    EncodedValue evObject = factory.create(encodedValueString);
    PMap map = new PMap(encodedValueString);
    if (!map.has("version"))
        throw new IllegalArgumentException("EncodedValue must have a version specified but it was " + encodedValueString);
    return evObject;
}
Also used : PMap(com.graphhopper.util.PMap)

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