Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G-MAP mobility profile-based routing [Review only - DO NOT MERGE] #197

Draft
wants to merge 120 commits into
base: ibi-dev-2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
2446026
Sketch out possible solution to get Gmap data into StreetEdge
leonardehrenfried Dec 18, 2023
e83a379
feat(BuildConfig): Add support for specifying a mobility profile CSV.
binh-dam-ibigroup Dec 26, 2023
f2a0c32
feat(MobilityProfileParser): Add class to parse mobility profile CSV.
binh-dam-ibigroup Dec 26, 2023
fc1a60a
refactor(MobilityProfile): Extract enum of known mobility profiles.
binh-dam-ibigroup Dec 27, 2023
50982d4
refactor: Fix other type errors
binh-dam-ibigroup Dec 27, 2023
10f2b58
improvement(OsmModule): List unused mobility profile costs.
binh-dam-ibigroup Dec 27, 2023
939b1bf
refactor(StreetEdgeBuilder): Initialize costs to empty map.
binh-dam-ibigroup Dec 28, 2023
e4cfd24
refactor(MobilityProfile): Add various JS docs, update graphql schema.
binh-dam-ibigroup Dec 28, 2023
e200909
fix(schema.graphqls): Fix syntax
binh-dam-ibigroup Dec 28, 2023
80b7c5e
refactor(RouteRequest): Propagate mobilityProfile plan query param.
binh-dam-ibigroup Dec 28, 2023
922bac7
refactor(VehicleRentalUpdater): Revert changes
binh-dam-ibigroup Dec 28, 2023
077aa0e
Merge branch 'dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Dec 28, 2023
219dfca
Merge branch 'dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Jan 12, 2024
64d521f
refactor(OsmModule): Apply refactor suggestions.
binh-dam-ibigroup Jan 12, 2024
8c4e90b
refactor(schema.graphqls): Remove MobilityProfile enum.
binh-dam-ibigroup Jan 12, 2024
a7ca124
refactor: Apply prettier formatting
binh-dam-ibigroup Jan 12, 2024
37ab3ec
Merge branch 'dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Jan 19, 2024
db44c89
fix(profileCost): Revert to use HashMap instead of EnumMap.
binh-dam-ibigroup Jan 22, 2024
fd07c16
Merge branch 'dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Jan 23, 2024
cdb152d
refactor(MobilityProfileParser): Adjust CSV headers and improve loggi…
binh-dam-ibigroup Jan 24, 2024
ad406f4
refactor(MobilityProfileParser): Move logging rows to parser class.
binh-dam-ibigroup Jan 25, 2024
5de0059
improvement(OsmModule): Check reverse key for cost profile existence.
binh-dam-ibigroup Jan 26, 2024
6a71d34
fix(RouteRequest): Initialize with mobility profile 'None'.
binh-dam-ibigroup Jan 29, 2024
9691d98
improvement(OsmModule): Add indication of cost profile use between 2 …
binh-dam-ibigroup Jan 31, 2024
53751c8
improvement(OsmModule): Print OSM node ids in edge names for testing.
binh-dam-ibigroup Feb 1, 2024
1d1acef
feat(MobilityProfileRouting): Add default speeds per profile, use in …
binh-dam-ibigroup Feb 5, 2024
7776c97
style: Apply prettier
binh-dam-ibigroup Feb 5, 2024
85d68f9
fix(StreetEdge): Fix condition for returning default time.
binh-dam-ibigroup Feb 5, 2024
3aedec0
refactor(OsmModule): Accommodate for null mobility profile test cases.
binh-dam-ibigroup Feb 5, 2024
8d4ca02
fix(OsmModule): Accommodate null mobility profile data.
binh-dam-ibigroup Feb 5, 2024
246a786
style(OsmModule): Apply prettier
binh-dam-ibigroup Feb 5, 2024
072f384
refactor(MobilityProfile): Accommodate fixed enum typos.
binh-dam-ibigroup Feb 20, 2024
454d7ac
improvement(MobilityProfileParser): Process mobility profile csv rows…
binh-dam-ibigroup Feb 20, 2024
41a5077
refactor(GraphBuilder): Add comment for using OTP-built-in store
binh-dam-ibigroup Mar 5, 2024
e55654a
improvement(MobilityProfileRouting): Forbid ped routing on non-footways.
binh-dam-ibigroup Mar 5, 2024
ecdb0e9
improvement(StreetEdge): Apply mobility profiles or penalties on walk…
binh-dam-ibigroup Mar 5, 2024
aa07003
fix(StreetEdge): Use impedances as weight, use computed travel time o…
binh-dam-ibigroup Mar 7, 2024
9c8cc4c
improvement(TemporaryPartialStreetEdge): Use distance-prorated profil…
binh-dam-ibigroup Mar 7, 2024
4aa8875
refactor(StreetEdge): Remove implied iswalking condition
binh-dam-ibigroup Mar 7, 2024
b222617
refactor(MobilityProfileParser): Map costs by way id/from/to info/
binh-dam-ibigroup Mar 11, 2024
0bc93b9
refactor(MobilityProfileData): Add from and to nodes to data structure
binh-dam-ibigroup Mar 11, 2024
ed33ba1
fix(MobilityProfileRouting): Map mobility profile data using way id
binh-dam-ibigroup Mar 12, 2024
5d1bb62
fix(StreetEdge): Copy mobility costs when splitting street edges
binh-dam-ibigroup Mar 14, 2024
fbddde0
refactor: Print additional edge information.
binh-dam-ibigroup Mar 27, 2024
18fedb9
Merge branch 'dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Mar 28, 2024
3fcbd9d
style: Apply prettier
binh-dam-ibigroup Mar 28, 2024
8a10dac
refactor(GraphBuilderDataSources): Add missing import
binh-dam-ibigroup Mar 28, 2024
fc51a61
docs(BuildConfiguration): Update documentation
binh-dam-ibigroup Mar 28, 2024
26ec7f0
test(speedtest): Update test results
binh-dam-ibigroup Mar 28, 2024
1aa614c
test(StreetEdgeWheelchairCostTest): Assume high cost for any untabula…
binh-dam-ibigroup Mar 28, 2024
a03c4fe
test(StreetEdgeCost): Use default high cost in more places.
binh-dam-ibigroup Mar 28, 2024
8d1bb28
test(travelSearch): Add back test results
binh-dam-ibigroup Mar 28, 2024
99ae5a2
test(StreetEdge*Cost): Revert tests
binh-dam-ibigroup Mar 28, 2024
0fabe23
refactor(StreetEdge): Revert to upstream time calcs if mobility profi…
binh-dam-ibigroup Mar 28, 2024
a6868ea
refactor(MobilityProfile): Default to null profile instead of NONE.
binh-dam-ibigroup Mar 28, 2024
d420d65
refactor(TemporaryPartialStreetEdge): Set mobility debug name only if…
binh-dam-ibigroup Mar 28, 2024
c142afb
refactor(OsmModule): Assign mobility debug names if profile costs ava…
binh-dam-ibigroup Mar 28, 2024
9e33f86
Merge branch 'ibi-dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Mar 29, 2024
6c5e3ee
improvement(OsmModule): Implement two-way mobility costs.
binh-dam-ibigroup Apr 10, 2024
00c0402
style(OsmModule): Apply prettier
binh-dam-ibigroup Apr 11, 2024
5cc3a4b
refactor(MobilityProfileParser): Use EnumMap
binh-dam-ibigroup Apr 11, 2024
160c140
refactor(MobilityProfileRouting): Fix temporal unit in comment.
binh-dam-ibigroup Apr 16, 2024
ccfea07
fix(StreetEdge): Convert mobility weights to seconds. Update comments.
binh-dam-ibigroup Apr 16, 2024
808c850
style(StreetEdge): Remove unused statement, apply prettier
binh-dam-ibigroup Apr 17, 2024
bdec742
refactor(OSMWay): Move isFootway method to OSMWay.
binh-dam-ibigroup Apr 19, 2024
1f407cd
improvement(OsmModule): Tag crosswalks with cross-street names.
binh-dam-ibigroup Apr 19, 2024
30968ef
refactor(StreetEdgeBuilder): Remove unused import
binh-dam-ibigroup Apr 19, 2024
48937a4
improvement(OsmModule): Move sidewalk id outside of parenthesis
binh-dam-ibigroup Apr 19, 2024
06c85fc
improvement(OSMWay): Add criteria for footway, service road, marked c…
binh-dam-ibigroup Apr 22, 2024
e6a6dbe
refactor(StreetEdge): Assume mobility profile impedances in seconds
binh-dam-ibigroup Apr 22, 2024
a86b1cf
improvement(StatesToWalkStepsMapper): Collapse short 'continue' steps…
binh-dam-ibigroup Apr 23, 2024
13ff3d7
refactor(StatesToWalkStepsMapper): Move comments regarding overwritin…
binh-dam-ibigroup Apr 23, 2024
1288768
improvement(StatesToWalkStepsMapper): Avoid reusing crossing names in…
binh-dam-ibigroup Apr 23, 2024
d80e2be
improvement(OsmModule): Expand crosswalk support to slip lanes, servi…
binh-dam-ibigroup Apr 23, 2024
c051357
style: Apply prettier
binh-dam-ibigroup Apr 23, 2024
2218a9f
Merge branch 'ibi-dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Apr 23, 2024
c23fc28
refactor(StatesToWalkStepsMapper): Don't recombine streets without mo…
binh-dam-ibigroup Apr 23, 2024
957a724
refactor(OsmModule): Rename "crosswalk" to "crossing".
binh-dam-ibigroup Apr 25, 2024
6df682f
Merge branch 'dev' into gmap-mobility-profile
binh-dam-ibigroup May 20, 2024
da79421
refactor(OsmModule): Extract logic for finding intersecting street, a…
binh-dam-ibigroup May 24, 2024
353a534
refactor(OsmModule): Extract logic for filtering streets, add tests.
binh-dam-ibigroup May 24, 2024
c6efe6c
refactor(OsmModule): Add JavaDoc to extracted methods.
binh-dam-ibigroup May 24, 2024
1db49ee
refactor(OsmModule): Add logic for finding continued ways.
binh-dam-ibigroup May 24, 2024
22618bd
fix(OsmWay): Adjust marked crossing logic and tests.
binh-dam-ibigroup May 30, 2024
b9bcf36
perf(OsmModule): Cache last intersection for prev OSMWay.
binh-dam-ibigroup May 30, 2024
23e79fb
refactor(OsmModule): Extract methods for crossing name and nearest cr…
binh-dam-ibigroup Jun 3, 2024
618fcb4
refactor(OsmModule): Add other missing pieces.
binh-dam-ibigroup Jun 3, 2024
49ba592
fix(StatesToWalkStepsMapper): Keep instr when xing and cont on other …
binh-dam-ibigroup Jun 3, 2024
9be135b
style: Apply prettier
binh-dam-ibigroup Jun 3, 2024
faaa7ca
fix(StreetEdge): Check non-empty profileCode map.
binh-dam-ibigroup Jul 17, 2024
a4143a9
fix(MobilityProfileRouting): Allow pedestrian routing on transit plat…
binh-dam-ibigroup Jul 31, 2024
f78e192
style(MobilityProfileRouting): Apply prettier.
binh-dam-ibigroup Jul 31, 2024
f77c33f
feat(OsmImpedanceUpdater): Add basic diff logic between two impedance…
binh-dam-ibigroup Aug 6, 2024
aeb0362
feat(OsmImpedanceUpdater): Implement interval polling and diffing of …
binh-dam-ibigroup Aug 6, 2024
8f6343d
refactor(OsmImpedanceUpdater): Include from/to nodes in change compar…
binh-dam-ibigroup Aug 7, 2024
85f20cb
refactor(GraphBuilder): Remove impedance data source.
binh-dam-ibigroup Aug 7, 2024
a7e555c
refactor(StreetEdge): Store original OSM way ID.
binh-dam-ibigroup Aug 7, 2024
0778883
refactor(StreetEdge): store profileKey for fast retrieval.
binh-dam-ibigroup Aug 8, 2024
5a3fdd7
refactor(OsmImpedanceUpdater): Tweak log messages.
binh-dam-ibigroup Aug 8, 2024
a6f4ee1
style: Apply prettier.
binh-dam-ibigroup Aug 8, 2024
b667766
refactor(OsmModule): Remove debug stuff.
binh-dam-ibigroup Aug 8, 2024
0f3da14
refactor(KryoBuilder): Remove mobility profile persistence.
binh-dam-ibigroup Aug 8, 2024
5b56661
refactor(OsmModule): Remove unused code.
binh-dam-ibigroup Aug 8, 2024
1c84582
refactor(StreetEdge): Update profileKey comment.
binh-dam-ibigroup Aug 14, 2024
5128679
refactor(OsmModule): Remove build-time permission restrictions.
binh-dam-ibigroup Aug 14, 2024
26a2efb
refactor(StreetEdge): Check for non-null profileCosts.
binh-dam-ibigroup Aug 14, 2024
7e02c22
style(StatesToWalkStepsMapper): Apply prettier.
binh-dam-ibigroup Aug 14, 2024
92a0c04
refactor(StreetEdge): Extract method to check non-null/empty profile …
binh-dam-ibigroup Aug 14, 2024
5dc0635
refactor(OsmImpedanceUpdater): Improve logs and comments.
binh-dam-ibigroup Aug 15, 2024
5ad796d
refactor(OsmModule): Improve logs.
binh-dam-ibigroup Aug 15, 2024
d6ce9c5
refactor(StatesToWalkStepMapper): Reuse hasProfileCost check.
binh-dam-ibigroup Aug 15, 2024
1c47d27
refactor(StreetEdge): Propagate profile info when splitting edges.
binh-dam-ibigroup Aug 15, 2024
d1496be
refactor(ImpedanceUpdateHandler): Apply impedances to edges with Spli…
binh-dam-ibigroup Aug 15, 2024
371ee42
feat(OsmModule): Add build option to prevent ped routing on roads.
binh-dam-ibigroup Aug 16, 2024
c38712b
Merge branch 'ibi-dev-2.x' into gmap-mobility-profile
binh-dam-ibigroup Nov 19, 2024
a8aae89
refactor: migrate types and imports.
binh-dam-ibigroup Nov 19, 2024
76719d8
refactor(OsmImpedanceUpdater): Close HTTP resource factory after poll…
binh-dam-ibigroup Nov 19, 2024
334a52c
refactor(MobilityProfileRoutingTest): Migrate types.
binh-dam-ibigroup Nov 19, 2024
42ce24f
refactor(OsmModuleTest): Migrate types.
binh-dam-ibigroup Nov 19, 2024
1533663
docs(BuildConfiguration): Update snapshot.
binh-dam-ibigroup Nov 19, 2024
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
@@ -0,0 +1,49 @@
package org.opentripplanner.ext.mobilityprofile;

/**
* Enumeration for the mobility profiles, and their associated column names for CSV parsing.
*/
public enum MobilityProfile {
NONE("None"),
SOME("Some"),
DEVICE("Device"),
WCHAIRM("WChairM"),
WCHAIRE("WChairE"),
MSCOOTER("MScooter"),
VISION("Vision"),
VISIONPLUS("Vision+"),
SOME_VISION("Some-Vision"),
DEVICE_VISION("Device-Vision"),
WCHAIRM_VISION("WChairM-Vision"),
WCHAIRE_VISION("WChairE-Vision"),
MSCOOTER_VISION("MScooter-Vision"),
SOME_VISIONPLUS("Some-Vision+"),
DEVICE_VISIONPLUS("Device-Vision+"),
WCHAIRM_VISIONPLUS("WChairM-Vision+"),
WCHAIRE_VISIONPLUS("WChairE-Vision+"),
MSCOOTER_VISIONPLUS("MScooter-Vision+");

private final String text;

MobilityProfile(String text) {
this.text = text;
}

public String getText() {
return text;
}

@Override
public String toString() {
return text;
}

public static MobilityProfile fromString(String value) {
for (MobilityProfile p : MobilityProfile.values()) {
if (p.text.equals(value)) {
return p;
}
}
throw new RuntimeException(String.format("Invalid mobility profile '%s'", value));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.opentripplanner.ext.mobilityprofile;

import com.csvreader.CsvReader;
import com.google.common.collect.ImmutableTable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.Map;
import org.opentripplanner.street.model.vertex.VertexLabel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Helper class that processes CSV files containing profile-based OSM costs.
*/
public class MobilityProfileParser {

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

private MobilityProfileParser() {}

/**
* Process rows from the given CSV stream and build a table indexed by both the
* upstream/downstream nodes, where each value is a map of costs by mobility profile.
*/
public static ImmutableTable<String, String, Map<MobilityProfile, Float>> parseData(InputStream is) {
try {
var reader = new CsvReader(is, StandardCharsets.UTF_8);
reader.setDelimiter(',');
reader.readHeaders();

ImmutableTable.Builder<String, String, Map<MobilityProfile, Float>> tableBuilder = ImmutableTable.builder();
int lineNumber = 1;
while (reader.readRecord()) {
parseRow(lineNumber, reader, tableBuilder);
lineNumber++;
}

return tableBuilder.build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static void parseRow(
int lineNumber,
CsvReader reader,
ImmutableTable.Builder<String, String, Map<MobilityProfile, Float>> tableBuilder
) throws IOException {
try {
long fromNode = Long.parseLong(reader.get("Upstream Node"), 10);
long toNode = Long.parseLong(reader.get("Downstream Node"), 10);

var weightMap = new EnumMap<MobilityProfile, Float>(MobilityProfile.class);
for (var profile : MobilityProfile.values()) {
weightMap.put(profile, Float.parseFloat(reader.get(profile.getText())));
}

tableBuilder.put(
VertexLabel.osm(fromNode).toString(),
VertexLabel.osm(toNode).toString(),
weightMap
);
} catch (NumberFormatException | NullPointerException e) {
LOG.warn(
"Skipping mobility profile data at line {}: missing/invalid data",
lineNumber
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static RouteRequest toRouteRequest(
context.transitService().getTimeZone()
);

callWith.argument("wheelchair", request::setWheelchair);
binh-dam-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
callWith.argument("wheelchair", request::setWheelchair);
callWith.argument("numItineraries", request::setNumItineraries);
callWith.argument("searchWindow", (Long m) -> request.setSearchWindow(Duration.ofSeconds(m)));
Expand Down Expand Up @@ -251,6 +252,7 @@ public static RouteRequest toRouteRequest(
"locale",
(String v) -> request.setLocale(GraphQLUtils.getLocale(environment, v))
);
callWith.argument("mobilityProfile", request::setMobilityProfileFromString);
return request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import static org.opentripplanner.datastore.api.FileType.OSM;

import jakarta.inject.Inject;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.ext.mobilityprofile.MobilityProfileParser;
import org.opentripplanner.ext.emissions.EmissionsDataModel;
import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository;
import org.opentripplanner.framework.application.OTPFeature;
Expand All @@ -20,6 +24,7 @@
import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary;
import org.opentripplanner.graph_builder.model.GraphBuilderModule;
import org.opentripplanner.graph_builder.module.configure.DaggerGraphBuilderFactory;
import org.opentripplanner.graph_builder.module.osm.OsmModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository;
import org.opentripplanner.standalone.config.BuildConfig;
Expand Down Expand Up @@ -96,7 +101,17 @@ public static GraphBuilder create(
graphBuilder.hasTransitData = hasTransitData;

if (hasOsm) {
graphBuilder.addModule(factory.osmModule());
Optional<DataSource> mobilityDataSource = dataSources.mobilityProfileDataSource();
OsmModule osmModule = factory.osmModule();
if (mobilityDataSource.isPresent()) {
// Parse stuff from the mobility profile CSV
try (var inputStream = mobilityDataSource.get().asInputStream()) {
osmModule.setMobilityProfileData(MobilityProfileParser.parseData(inputStream));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
graphBuilder.addModule(osmModule);
}

if (hasGtfs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public Optional<DataSource> stopConsolidationDataSource() {
});
}

/**
* Returns the optional data source for the mobility profile routing costs.
*/
public Optional<DataSource> mobilityProfileDataSource() {
return Optional
.ofNullable(buildConfig.mobilityProfileFile)
.map(fileName -> {
var f = baseDirectory.toPath().resolve(fileName).toFile();
return new FileDataSource(f, FileType.CONFIG);
});
}

/**
* Match the URI provided in the configuration with the URI of a datasource,
* either by comparing directly the two URIs or by first prepending the OTP base directory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.graph_builder.module.osm;

import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Iterables;
import gnu.trove.iterator.TLongIterator;
import java.util.ArrayList;
Expand All @@ -10,6 +11,7 @@
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.ext.mobilityprofile.MobilityProfile;
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.framework.geometry.SphericalDistanceLibrary;
import org.opentripplanner.framework.i18n.I18NString;
Expand Down Expand Up @@ -55,6 +57,8 @@ public class OsmModule implements GraphBuilderModule {
private final SafetyValueNormalizer normalizer;
private final VertexGenerator vertexGenerator;
private final OsmDatabase osmdb;
private ImmutableTable<String, String, Map<MobilityProfile, Float>> mobilityProfileData;
private HashMap<String, Boolean> mappedMobilityProfileEntries;
binh-dam-ibigroup marked this conversation as resolved.
Show resolved Hide resolved

OsmModule(
Collection<OsmProvider> providers,
Expand Down Expand Up @@ -107,6 +111,10 @@ public Map<Vertex, Double> elevationDataOutput() {
return elevationData;
}

public void setMobilityProfileData(ImmutableTable<String, String, Map<MobilityProfile, Float>> mobilityProfileData) {
this.mobilityProfileData = mobilityProfileData;
}

private record StreetEdgePair(StreetEdge main, StreetEdge back) {}

private void build() {
Expand Down Expand Up @@ -142,6 +150,8 @@ private void build() {
// figure out which nodes that are actually intersections
vertexGenerator.initIntersectionNodes();

mappedMobilityProfileEntries = new HashMap<>();

buildBasicGraph();
buildWalkableAreas(!params.areaVisibility());
validateBarriers();
Expand Down Expand Up @@ -171,6 +181,31 @@ private void build() {
params.edgeNamer().postprocess();

normalizer.applySafetyFactors();

listUnusedMobilityCosts();
}

/**
* Lists unused entries from the mobility profile data.
*/
private void listUnusedMobilityCosts() {
var unusedEntries = new ArrayList<String>();

for (var cell : mobilityProfileData.cellSet()) {
String key = getNodeKey(cell.getRowKey(), cell.getColumnKey());
Boolean exists = mappedMobilityProfileEntries.get(key);
if (exists == null || !exists) {
unusedEntries.add(key);
}
}

if (!unusedEntries.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (var entry : unusedEntries) {
sb.append(String.format("%n- %s", entry));
}
LOG.warn("{} mobility profile entries were not used:{}", unusedEntries.size(), sb);
}
}

/**
Expand Down Expand Up @@ -537,6 +572,24 @@ private StreetEdge getEdgeForStreet(
.withStairs(way.isSteps())
.withWheelchairAccessible(way.isWheelchairAccessible());

// Lookup costs by mobility profile, if any were defined.
String startId = startEndpoint.getLabel().toString();
String endId = endEndpoint.getLabel().toString();
var edgeMobilityCostMap = mobilityProfileData.get(
startId,
endId
);
if (edgeMobilityCostMap != null) {
seb.withProfileCosts(edgeMobilityCostMap);
LOG.info(
"Applied mobility profile costs between nodes {}-{}",
startId,
endId
);
// Keep tab of node pairs for which mobility profile costs have been mapped.
mappedMobilityProfileEntries.put(getNodeKey(startId, endId), true);
}

if (!way.hasTag("name") && !way.hasTag("ref")) {
seb.withBogusName(true);
}
Expand All @@ -551,4 +604,8 @@ private StreetEdge getEdgeForStreet(

return street;
}

private static String getNodeKey(String startId, String endId) {
return String.format("%s=>%s", startId, endId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Locale;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.opentripplanner.ext.mobilityprofile.MobilityProfile;
import org.opentripplanner.framework.collection.ListSection;
import org.opentripplanner.framework.time.DateUtils;
import org.opentripplanner.framework.tostring.ToStringBuilder;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class RouteRequest implements Cloneable, Serializable {

private boolean wheelchair = false;

private MobilityProfile mobilityProfile;

/* CONSTRUCTORS */

/** Constructor for options; modes defaults to walk and transit */
Expand Down Expand Up @@ -127,6 +130,21 @@ public void setWheelchair(boolean wheelchair) {
this.wheelchair = wheelchair;
}

/**
* Applicable mobility profile for street routing
*/
public MobilityProfile mobilityProfile() {
return mobilityProfile;
}

public void setMobilityProfile(MobilityProfile profile) {
this.mobilityProfile = profile;
}

public void setMobilityProfileFromString(String profile) {
this.mobilityProfile = MobilityProfile.fromString(profile);
}

/**
* The epoch date/time in seconds that the trip should depart (or arrive, for requests where
* arriveBy is true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public class BuildConfig implements OtpDataStoreConfig {
public final ZoneId transitModelTimeZone;

public final String stopConsolidationFile;
public final String mobilityProfileFile;

/**
* Set all parameters from the given Jackson JSON tree, applying defaults. Supplying
Expand Down Expand Up @@ -611,6 +612,15 @@ that we support remote input files (cloud storage or arbitrary URLs) not all dat
)
.asString(null);

mobilityProfileFile =
root
.of("mobilityProfileFile")
.since(V2_5)
.summary(
"Name of the CSV-formatted file in the build directory which contains the routing costs by mobility profile."
)
.asString(null);

osmDefaults = OsmConfig.mapOsmDefaults(root, "osmDefaults");
osm = OsmConfig.mapOsmConfig(root, "osm", osmDefaults);
demDefaults = DemConfig.mapDemDefaultsConfig(root, "demDefaults");
Expand Down
Loading
Loading