Skip to content

Commit

Permalink
trying to fix GraphHopper routing for 9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Sep 9, 2024
1 parent e792ec0 commit d22774e
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.graphhopper.GHResponse;
import com.graphhopper.ResponsePath;
import com.graphhopper.config.Profile;
import com.graphhopper.json.Statement;
import com.graphhopper.util.CustomModel;
import com.graphhopper.util.PointList;
import com.graphhopper.util.exceptions.DetailedIllegalArgumentException;
Expand All @@ -44,7 +43,11 @@
import java.util.*;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.graphhopper.json.Statement.If;
import static com.graphhopper.json.Statement.Op.LIMIT;
import static com.graphhopper.json.Statement.Op.MULTIPLY;
import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
Expand Down Expand Up @@ -159,15 +162,15 @@ protected void second(int second) {
request.setProfile(travelMode.getName());
CustomModel customModel = new CustomModel();
if (travelRestrictions.isAvoidBridges())
customModel.addToPriority(Statement.If("road_environment == BRIDGE", MULTIPLY, "0"));
customModel.addToPriority(If("road_environment == BRIDGE", MULTIPLY, "0"));
if (travelRestrictions.isAvoidFerries())
customModel.addToPriority(Statement.If("road_environment == FERRY", MULTIPLY, "0"));
customModel.addToPriority(If("road_environment == FERRY", MULTIPLY, "0"));
if (travelRestrictions.isAvoidMotorways())
customModel.addToPriority(Statement.If("road_class == MOTORWAY", MULTIPLY, "0"));
customModel.addToPriority(If("road_class == MOTORWAY", MULTIPLY, "0"));
// if (travelRestrictions.isAvoidToll())
// customModel.addToPriority(Statement.If("toll == all", MULTIPLY, "0"));
if (travelRestrictions.isAvoidTunnels())
customModel.addToPriority(Statement.If("road_environment == TUNNEL", MULTIPLY, "0"));
customModel.addToPriority(If("road_environment == TUNNEL", MULTIPLY, "0"));
request.setCustomModel(customModel);
GHResponse response = hopper.route(request);
if (response.hasErrors()) {
Expand Down Expand Up @@ -265,11 +268,18 @@ private com.graphhopper.GraphHopper createHopper() {
List<Profile> profiles = getAvailableTravelModes().stream()
.map(mode -> new Profile(mode.getName())
.setName(mode.getName())
// could set .setTurnCosts(true)
.setCustomModel(new CustomModel()
.addToPriority(If("!" + mode.getName() + "_access", MULTIPLY, "0"))
.addToSpeed(If("true", LIMIT, mode.getName() + "_average_speed")))
)
.toList();

String modePriorityAndSpeed = getAvailableTravelModes().stream()
.flatMap(mode -> Stream.of(mode.getName() + "_access", mode.getName() + "_average_speed"))
.collect(Collectors.joining(","));

return new com.graphhopper.GraphHopper()
.setEncodedValuesString("road_class,road_environment,toll," + modePriorityAndSpeed)
.setProfiles(profiles);
}

Expand Down

0 comments on commit d22774e

Please sign in to comment.