Skip to content

Commit

Permalink
Move IntersectionTraversalCalculator into StreetPreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesj committed Sep 13, 2022
1 parent 054c341 commit 7e2d1fa
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.SimpleIntersectionTraversalCalculator;

/**
* OSM way properties for the Atlanta, Georgia, USA area.
* The differences compared to the default
Expand All @@ -19,8 +16,6 @@

public class AtlantaWayPropertySetSource implements WayPropertySetSource {

private static final DrivingDirection drivingDirection = DrivingDirection.RIGHT_HAND_TRAFFIC;

@Override
public void populateProperties(WayPropertySet props) {
// Replace existing matching properties as the logic is that the first statement registered takes precedence over later statements
Expand All @@ -30,14 +25,4 @@ public void populateProperties(WayPropertySet props) {
// Read the rest from the default set
new DefaultWayPropertySetSource().populateProperties(props);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new SimpleIntersectionTraversalCalculator(drivingDirection);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.opentripplanner.graph_builder.module.osm;

import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection.RIGHT_HAND_TRAFFIC;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.BICYCLE_AND_CAR;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.CAR;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.NONE;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.SimpleIntersectionTraversalCalculator;
import org.opentripplanner.routing.services.notes.StreetNotesService;

/**
Expand Down Expand Up @@ -48,7 +45,6 @@ public class DefaultWayPropertySetSource implements WayPropertySetSource {
private final WayProperties pedestrianWayProperties = withModes(PEDESTRIAN).build();
private final WayProperties pedestrianAndBicycleWayProperties = withModes(PEDESTRIAN_AND_BICYCLE)
.build();
private final DrivingDirection drivingDirection = RIGHT_HAND_TRAFFIC;

/* Populate properties on existing WayPropertySet */
public void populateProperties(WayPropertySet props) {
Expand Down Expand Up @@ -626,16 +622,6 @@ public void populateProperties(WayPropertySet props) {
props.setSlopeOverride(new OSMSpecifier("tunnel=*"), true);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new SimpleIntersectionTraversalCalculator(drivingDirection);
}

public void populateNotesAndNames(WayPropertySet props) {
/* and the notes */
// TODO: The curly brackets in the string below mean that the CreativeNamer should substitute in OSM tag values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.opentripplanner.graph_builder.module.osm;

import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection.RIGHT_HAND_TRAFFIC;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.CAR;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.NONE;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.SimpleIntersectionTraversalCalculator;

/**
* OSM way properties for Finnish roads. FinlandWayPropertySetSource is derived from
* NorwayPropertySetSource by seime
Expand All @@ -25,8 +21,6 @@
*/
public class FinlandWayPropertySetSource implements WayPropertySetSource {

private final DrivingDirection drivingDirection = RIGHT_HAND_TRAFFIC;

@Override
public void populateProperties(WayPropertySet props) {
props.setProperties("highway=living_street", withModes(ALL).bicycleSafety(0.9).walkSafety(0.9));
Expand Down Expand Up @@ -97,14 +91,4 @@ public void populateProperties(WayPropertySet props) {
// Read the rest from the default set
new DefaultWayPropertySetSource().populateProperties(props);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new SimpleIntersectionTraversalCalculator(drivingDirection);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.opentripplanner.graph_builder.module.osm;

import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection.RIGHT_HAND_TRAFFIC;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.BICYCLE_AND_CAR;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.SimpleIntersectionTraversalCalculator;

/**
* OSM way properties for German roads. Speed limits where adjusted to German regulation and some
* bike safety settings tweaked, especially including tracktype's grade and preference of bicycle
Expand All @@ -20,8 +16,6 @@
*/
public class GermanyWayPropertySetSource implements WayPropertySetSource {

private final DrivingDirection drivingDirection = RIGHT_HAND_TRAFFIC;

@Override
public void populateProperties(WayPropertySet props) {
// Replace existing matching properties as the logic is that the first statement registered takes precedence over later statements
Expand Down Expand Up @@ -93,14 +87,4 @@ public void populateProperties(WayPropertySet props) {
// Read the rest from the default set
new DefaultWayPropertySetSource().populateProperties(props);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new SimpleIntersectionTraversalCalculator(drivingDirection);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opentripplanner.graph_builder.module.osm;

import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection.RIGHT_HAND_TRAFFIC;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.BICYCLE;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.BICYCLE_AND_CAR;
Expand All @@ -10,9 +9,6 @@
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.NorwayIntersectionTraversalCalculator;

/**
* OSM way properties for Norwegian roads. The main difference compared to the default property set
* is that most of the highway=trunk roads also allows walking and biking, where as some does not.
Expand All @@ -24,8 +20,6 @@
*/
public class NorwayWayPropertySetSource implements WayPropertySetSource {

private final DrivingDirection drivingDirection = RIGHT_HAND_TRAFFIC;

@Override
public void populateProperties(WayPropertySet props) {
var very_high_traffic = 8;
Expand Down Expand Up @@ -736,14 +730,4 @@ but assumed to be much safer than the default profile (Except when the speedli
props.setSlopeOverride(new OSMSpecifier("location=underground"), true);
props.setSlopeOverride(new OSMSpecifier("indoor=yes"), true);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new NorwayIntersectionTraversalCalculator(drivingDirection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,8 @@ public void buildGraph() {
osmdb.postLoad();

LOG.info(
"Using OSM way configuration from {}. Setting driving direction of the graph to {}.",
wayPropertySetSource.getClass().getSimpleName(),
wayPropertySetSource.drivingDirection()
);
graph.setDrivingDirection(wayPropertySetSource.drivingDirection());
graph.setIntersectionTraversalCostModel(
wayPropertySetSource.getIntersectionTraversalCostModel()
"Using OSM way configuration from {}.",
wayPropertySetSource.getClass().getSimpleName()
);

LOG.info("Building street graph from OSM");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package org.opentripplanner.graph_builder.module.osm;

import static org.opentripplanner.graph_builder.module.osm.WayPropertiesBuilder.withModes;
import static org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection.LEFT_HAND_TRAFFIC;
import static org.opentripplanner.routing.edgetype.StreetTraversalPermission.ALL;

import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.core.intersection_model.SimpleIntersectionTraversalCalculator;

/**
* OSM way properties for UK roads. The main differences compared to the default property set are:
* 1. In the UK there is no real distinction between trunk highways and primary highways, other than
Expand All @@ -25,8 +21,6 @@
*/
public class UKWayPropertySetSource implements WayPropertySetSource {

private final DrivingDirection drivingDirection = LEFT_HAND_TRAFFIC;

@Override
public void populateProperties(WayPropertySet props) {
// Replace existing matching properties as the logic is that the first statement registered takes precedence over later statements
Expand Down Expand Up @@ -78,14 +72,4 @@ public void populateProperties(WayPropertySet props) {
// Read the rest from the default set
new DefaultWayPropertySetSource().populateProperties(props);
}

@Override
public DrivingDirection drivingDirection() {
return drivingDirection;
}

@Override
public IntersectionTraversalCalculator getIntersectionTraversalCostModel() {
return new SimpleIntersectionTraversalCalculator(drivingDirection);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opentripplanner.graph_builder.module.osm;

import org.opentripplanner.openstreetmap.model.OSMWithTags;
import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;

/**
* Interface for populating a {@link WayPropertySet} that determine how OSM streets can be traversed
Expand Down Expand Up @@ -40,10 +39,6 @@ static WayPropertySetSource fromConfig(String type) {

void populateProperties(WayPropertySet wayPropertySet);

DrivingDirection drivingDirection();

IntersectionTraversalCalculator getIntersectionTraversalCostModel();

default boolean doesTagValueDisallowThroughTraffic(String tagValue) {
return (
"destination".equals(tagValue) ||
Expand Down Expand Up @@ -92,17 +87,4 @@ default boolean isWalkNoThroughTrafficExplicitlyDisallowed(OSMWithTags way) {
String foot = way.getTag("foot");
return isGeneralNoThroughTraffic(way) || doesTagValueDisallowThroughTraffic(foot);
}

enum DrivingDirection {
/**
* Specifies that cars go on the right hand side of the road. This is true for the US mainland
* Europe.
*/
RIGHT_HAND_TRAFFIC,
/**
* Specifies that cars go on the left hand side of the road. This is true for the UK, Japan and
* Australia.
*/
LEFT_HAND_TRAFFIC,
}
}
12 changes: 0 additions & 12 deletions src/main/java/org/opentripplanner/routing/RoutingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import java.util.List;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.opentripplanner.graph_builder.module.osm.WayPropertySetSource.DrivingDirection;
import org.opentripplanner.routing.algorithm.RoutingWorker;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.response.RoutingResponse;
import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.edgetype.StreetEdge;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph;
Expand Down Expand Up @@ -136,16 +134,6 @@ public VehicleParkingService getVehicleParkingService() {
return this.graph.getVehicleParkingService();
}

/** {@link Graph#getDrivingDirection()} */
public DrivingDirection getDrivingDirection() {
return this.graph.getDrivingDirection();
}

/** {@link Graph#getIntersectionTraversalModel()} */
public IntersectionTraversalCalculator getIntersectionTraversalModel() {
return this.graph.getIntersectionTraversalModel();
}

/** {@link GraphFinder#findClosestStops(double, double, double)} */
public List<NearbyStop> findClosestStops(double lat, double lon, double radiusMeters) {
return this.graphFinder.findClosestStops(lat, lon, radiusMeters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.opentripplanner.routing.algorithm.astar.strategies.SearchTerminationStrategy;
import org.opentripplanner.routing.algorithm.astar.strategies.SkipEdgeStrategy;
import org.opentripplanner.routing.algorithm.astar.strategies.TrivialRemainingWeightHeuristic;
import org.opentripplanner.routing.api.request.preference.StreetPreferences;
import org.opentripplanner.routing.core.RoutingContext;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.core.intersection_model.IntersectionTraversalCalculator;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.spt.DominanceFunction;
import org.opentripplanner.routing.spt.GraphPath;
Expand All @@ -28,6 +30,7 @@ public class AStarBuilder {
private Duration timeout;
private Edge originBackEdge;
private Collection<State> initialStates;
private IntersectionTraversalCalculator intersectionTraversalCalculator;

public AStarBuilder(
RemainingWeightHeuristic remainingWeightHeuristic,
Expand Down Expand Up @@ -82,6 +85,13 @@ public AStarBuilder setTimeout(Duration timeout) {
return this;
}

public AStarBuilder setIntersectionTraversalCalculator(
IntersectionTraversalCalculator intersectionTraversalCalculator
) {
this.intersectionTraversalCalculator = intersectionTraversalCalculator;
return this;
}

public AStarBuilder setOriginBackEdge(Edge originBackEdge) {
this.originBackEdge = originBackEdge;
return this;
Expand Down Expand Up @@ -115,6 +125,19 @@ private AStar build() {
}
}

if (intersectionTraversalCalculator == null) {
final StreetPreferences streetPreferences = routingContext.opt.preferences().street();
intersectionTraversalCalculator =
IntersectionTraversalCalculator.fromConfig(
streetPreferences.intersectionTraversalCalculator(),
streetPreferences.drivingDirection()
);
}

for (var state : initialStates) {
state.stateData.intersectionTraversalCalculator = intersectionTraversalCalculator;
}

return new AStar(
heuristic,
skipEdgeStrategy,
Expand Down
Loading

0 comments on commit 7e2d1fa

Please sign in to comment.