Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d467f91
remove safety normalizing and update heuristic to handle reluctance a…
miklcct Aug 1, 2025
f68d4f1
exaggerate SAFEST_STREET routing
miklcct Aug 1, 2025
174700d
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Aug 22, 2025
adf5571
change the log level to debug when processing walk / bike safety for …
miklcct Sep 1, 2025
d875561
rename the methods from set to init and add init-once check
miklcct Sep 1, 2025
6f57ae8
improve weight heuristic
miklcct Sep 1, 2025
d2b259a
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Sep 1, 2025
1dd473b
extract variable
miklcct Sep 1, 2025
ac0930b
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Sep 1, 2025
9fdf06c
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Sep 1, 2025
8fa7336
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Sep 30, 2025
5a12491
add Javadoc to explain the best safety value
miklcct Oct 1, 2025
9b88a48
rename SafetyValueNormalizer to SafetyValueApplier
miklcct Oct 1, 2025
920a442
extract OsmModule.initStreetLimitationParameters()
miklcct Oct 1, 2025
c0be77e
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Oct 9, 2025
8d2095d
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Oct 10, 2025
c167514
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Oct 16, 2025
9b738fd
add documentation on safety
miklcct Oct 16, 2025
e77bb99
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Nov 4, 2025
7343ad2
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Nov 4, 2025
deea1aa
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Nov 11, 2025
e586a60
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Nov 11, 2025
b85e107
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Nov 11, 2025
5b89e9a
remove unused variable
miklcct Nov 11, 2025
d2dc100
Merge branch 'dev-2.x' into remove-safety-normalizer
miklcct Nov 26, 2025
3274de5
Merge branch 'remove-safety-normalizer' into safest-street
miklcct Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public GraphPath<State, Edge, Vertex> route(
new StreetRequest(StreetMode.CAR),
fromVertices,
toVertices,
streetLimitationParametersService.maxCarSpeed()
streetLimitationParametersService
);
} catch (Exception e) {
LOG.warn("Routing failed from {} to {}: {}", from, to, e.getMessage());
Expand Down Expand Up @@ -180,12 +180,12 @@ private GraphPath<State, Edge, Vertex> carpoolRouting(
StreetRequest streetRequest,
Set<Vertex> fromVertices,
Set<Vertex> toVertices,
float maxCarSpeed
StreetLimitationParametersService streetLimitationParametersService
) {
var preferences = request.preferences().street();

var streetSearch = StreetSearchBuilder.of()
.withHeuristic(new EuclideanRemainingWeightHeuristic(maxCarSpeed))
.withHeuristic(new EuclideanRemainingWeightHeuristic(streetLimitationParametersService))
.withSkipEdgeStrategy(
new DurationSkipEdgeStrategy(preferences.maxDirectDuration().valueOf(streetRequest.mode()))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class OsmModule implements GraphBuilderModule {

private final DataImportIssueStore issueStore;
private final OsmProcessingParameters params;
private final SafetyValueNormalizer normalizer;
private final SafetyValueApplier safetyValueApplier;

OsmModule(
Collection<OsmProvider> providers,
Expand All @@ -90,7 +90,7 @@ public class OsmModule implements GraphBuilderModule {
this.streetRepository = streetRepository;
this.issueStore = issueStore;
this.params = params;
this.normalizer = new SafetyValueNormalizer(graph, issueStore);
this.safetyValueApplier = new SafetyValueApplier(graph);
}

public static OsmModuleBuilder of(
Expand Down Expand Up @@ -152,7 +152,12 @@ public void buildGraph() {
build(osmdb, vertexGenerator);
graph.hasStreets = true;
streetRepository.setStreetModelDetails(
new StreetModelDetails(getMaxCarSpeed(), params.maxAreaNodes())
new StreetModelDetails(
getMaxCarSpeed(),
params.maxAreaNodes(),
safetyValueApplier.getBestBikeSafety(),
safetyValueApplier.getBestWalkSafety()
)
);
vertexGenerator.createDifferentLevelsSharingBarrierIssues();
}
Expand Down Expand Up @@ -238,8 +243,6 @@ private void build(OsmDatabase osmdb, VertexGenerator vertexGenerator) {
TurnRestrictionUnifier.unifyTurnRestrictions(osmdb, issueStore, osmInfoGraphBuildRepository);

params.edgeNamer().finalizeNames();

normalizer.applySafetyFactors();
}

/**
Expand Down Expand Up @@ -289,7 +292,7 @@ private void buildWalkableAreas(
osmInfoGraphBuildRepository,
vertexGenerator,
params.edgeNamer(),
normalizer,
safetyValueApplier,
issueStore,
params.maxAreaNodes(),
params.platformEntriesLinking(),
Expand Down Expand Up @@ -482,7 +485,7 @@ private void buildBasicGraph(OsmDatabase osmdb, VertexGenerator vertexGenerator)

StreetEdge street = streets.main();
StreetEdge backStreet = streets.back();
normalizer.applyWayProperties(
safetyValueApplier.applyWayProperties(
street,
backStreet,
wayData.forward(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.opentripplanner.graph_builder.module.osm;

import java.util.Set;
import javax.annotation.Nullable;
import org.opentripplanner.osm.model.OsmEntity;
import org.opentripplanner.osm.tagmapping.OsmTagMapper;
import org.opentripplanner.osm.wayproperty.WayProperties;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.note.StreetNoteAndMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Collects the minimum bike & walk safety values while applying them to the graph.
* <p>
* The heuristic function needs to know the minimum values so it never overestimates
* the remaining cost of the path and won't prune out optimal paths.
* <p>
* Further reading: <a href="https://github.com/opentripplanner/OpenTripPlanner/issues/4442">Issue 4442</a>
* <a href="https://github.com/opentripplanner/OpenTripPlanner/issues/6775">Issue 6775</a>
*/
class SafetyValueApplier {

private static final Logger LOG = LoggerFactory.getLogger(SafetyValueApplier.class);

private final Graph graph;

/**
* The bike safety factor of the safest street
*/
private float bestBikeSafety = 1.0f;
/**
* The walk safety factor of the safest street
*/
private float bestWalkSafety = 1.0f;

SafetyValueApplier(Graph graph) {
this.graph = graph;
}

/**
* Get the best bike safety in the whole graph.
*
* @return The bike safety of the safest way in the graph, i.e. the way with the lowest bike
* safety value.
*/
public float getBestBikeSafety() {
return bestBikeSafety;
}

/**
* Get the best walk safety in the whole graph.
*
* @return The walk safety of the safest way in the graph, i.e. the way with the lowest walk
* safety value.
*/
public float getBestWalkSafety() {
return bestWalkSafety;
}

void applyWayProperties(
@Nullable StreetEdge street,
@Nullable StreetEdge backStreet,
WayProperties forwardWayData,
WayProperties backwardWayData,
OsmEntity way
) {
OsmTagMapper tagMapperForWay = way.getOsmProvider().getOsmTagMapper();

Set<StreetNoteAndMatcher> notes = way.getOsmProvider().getWayPropertySet().getNoteForWay(way);

boolean motorVehicleNoThrough =
tagMapperForWay.isMotorVehicleThroughTrafficExplicitlyDisallowed(way);
boolean bicycleNoThrough = tagMapperForWay.isBicycleThroughTrafficExplicitlyDisallowed(way);
boolean walkNoThrough = tagMapperForWay.isWalkThroughTrafficExplicitlyDisallowed(way);

if (street != null) {
float bicycleSafety = (float) forwardWayData.bicycleSafety();
street.setBicycleSafetyFactor(bicycleSafety);
if (bicycleSafety < bestBikeSafety) {
bestBikeSafety = bicycleSafety;
LOG.debug(
"minimum bike safety reduced to {} for street {} forward",
bestBikeSafety,
street
);
}
float walkSafety = (float) forwardWayData.walkSafety();
street.setWalkSafetyFactor(walkSafety);
if (walkSafety < bestWalkSafety) {
bestWalkSafety = walkSafety;
LOG.debug(
"minimum walk safety reduced to {} for street {} forward",
bestWalkSafety,
street
);
}
if (notes != null) {
for (var it : notes) {
graph.streetNotesService.addStaticNote(street, it.note(), it.matcher());
}
}
street.setMotorVehicleNoThruTraffic(motorVehicleNoThrough);
street.setBicycleNoThruTraffic(bicycleNoThrough);
street.setWalkNoThruTraffic(walkNoThrough);
}

if (backStreet != null) {
float bicycleSafety = (float) backwardWayData.bicycleSafety();
if (bicycleSafety < bestBikeSafety) {
bestBikeSafety = bicycleSafety;
LOG.debug(
"minimum bike safety reduced to {} for street {} backward",
bestBikeSafety,
backStreet
);
}
backStreet.setBicycleSafetyFactor(bicycleSafety);
float walkSafety = (float) backwardWayData.walkSafety();
if (walkSafety < bestWalkSafety) {
bestWalkSafety = walkSafety;
LOG.debug(
"minimum walk safety reduced to {} for street {} backward",
bestWalkSafety,
backStreet
);
}
backStreet.setWalkSafetyFactor((float) walkSafety);
if (notes != null) {
for (var it : notes) {
graph.streetNotesService.addStaticNote(backStreet, it.note(), it.matcher());
}
}
backStreet.setMotorVehicleNoThruTraffic(motorVehicleNoThrough);
backStreet.setBicycleNoThruTraffic(bicycleNoThrough);
backStreet.setWalkNoThruTraffic(walkNoThrough);
}
}
}

This file was deleted.

Loading
Loading