Skip to content

Commit

Permalink
Merge remote-tracking branch 'hsl/mode-specific-maxstopcount' into au…
Browse files Browse the repository at this point in the history
…bin-test
  • Loading branch information
miklcct committed Jan 15, 2025
2 parents 22fa145 + 5c85096 commit bef1c2d
Show file tree
Hide file tree
Showing 25 changed files with 477 additions and 175 deletions.
8 changes: 4 additions & 4 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs</artifactId>
<version>4.3.0</version>
<version>5.0.0</version>
</dependency>
<!-- Processing is used for the debug GUI (though we could probably use just Java2D) -->
<dependency>
Expand All @@ -312,9 +312,9 @@
</dependency>
<!-- OpenStreetMap protobuf (PBF) definitions and parser -->
<dependency>
<groupId>org.openstreetmap.osmosis</groupId>
<artifactId>osmosis-osm-binary</artifactId>
<version>0.48.3</version>
<groupId>org.openstreetmap.pbf</groupId>
<artifactId>osmpbf</artifactId>
<version>1.6.0</version>
</dependency>
<!-- Command line parameter parsing -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions application/src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="/img/otp-logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OTP Debug</title>
<script type="module" crossorigin src="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-02T15:56/assets/index-DODY0n0n.js"></script>
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-02T15:56/assets/index-BDL0-veX.css">
<script type="module" crossorigin src="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-11T19:23/assets/index-D--h-dOg.js"></script>
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-11T19:23/assets/index-BDL0-veX.css">
</head>
<body>
<div id="root"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.opentripplanner.apis.transmodel.model.EnumTypes.MULTI_MODAL_MODE;
import static org.opentripplanner.apis.transmodel.model.EnumTypes.TRANSPORT_MODE;
import static org.opentripplanner.apis.transmodel.model.scalars.DateTimeScalarFactory.createMillisecondsSinceEpochAsDateTimeStringScalar;
import static org.opentripplanner.apis.transmodel.support.GqlUtil.toListNullSafe;
import static org.opentripplanner.model.projectinfo.OtpProjectInfo.projectInfo;

import graphql.Scalars;
Expand Down Expand Up @@ -1310,11 +1311,11 @@ private GraphQLSchema create() {
);
var privateCodes = FilterValues.ofEmptyIsEverything(
"privateCodes",
environment.<List<String>>getArgument("privateCodes")
toListNullSafe(environment.<List<String>>getArgument("privateCodes"))
);
var activeServiceDates = FilterValues.ofEmptyIsEverything(
"activeDates",
environment.<List<LocalDate>>getArgument("activeDates")
toListNullSafe(environment.<List<LocalDate>>getArgument("activeDates"))
);

TripRequest tripRequest = TripRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import graphql.schema.GraphQLInputObjectField;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLNonNull;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import javax.annotation.Nullable;
import org.opentripplanner.apis.transmodel.TransmodelRequestContext;
import org.opentripplanner.apis.transmodel.mapping.TransitIdMapper;
import org.opentripplanner.framework.graphql.GraphQLUtils;
Expand All @@ -18,7 +21,7 @@

/**
* Provide some of the commonly used "chain" of methods. Like all ids should be created the same
* wayThis
* way.
*/
public class GqlUtil {

Expand Down Expand Up @@ -96,4 +99,15 @@ public static Locale getLocale(DataFetchingEnvironment environment) {
? GraphQLUtils.getLocale(environment, lang)
: GraphQLUtils.getLocale(environment);
}

/**
* Null-safe handling of a collection of type T. Returns an empty list if the collection is null.
* Null elements are filtered out.
*/
public static <T> List<T> toListNullSafe(@Nullable Collection<T> args) {
if (args == null) {
return List.of();
}
return args.stream().filter(Objects::nonNull).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.onebusaway.csv_entities.EntityHandler;
import org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl;
import org.onebusaway.gtfs.model.Agency;
import org.onebusaway.gtfs.model.Area;
import org.onebusaway.gtfs.model.FareAttribute;
import org.onebusaway.gtfs.model.FareLegRule;
import org.onebusaway.gtfs.model.FareMedium;
Expand All @@ -27,7 +28,7 @@
import org.onebusaway.gtfs.model.ServiceCalendarDate;
import org.onebusaway.gtfs.model.ShapePoint;
import org.onebusaway.gtfs.model.Stop;
import org.onebusaway.gtfs.model.StopArea;
import org.onebusaway.gtfs.model.StopAreaElement;
import org.onebusaway.gtfs.model.Trip;
import org.onebusaway.gtfs.serialization.GtfsReader;
import org.onebusaway.gtfs.services.GenericMutableDao;
Expand Down Expand Up @@ -66,7 +67,8 @@ public class GtfsModule implements GraphBuilderModule {
FareTransferRule.class,
RiderCategory.class,
FareMedium.class,
StopArea.class
StopAreaElement.class,
Area.class
);

private static final Logger LOG = LoggerFactory.getLogger(GtfsModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
getDistanceFromCoordinates(
List.of(transitLegCoordinates.getFirst(), transitLegCoordinates.getLast())
);
this.transitAlerts.addAll(builder.alerts());
}

public ZoneId getZoneId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.TripOnServiceDate;
import org.opentripplanner.transit.model.timetable.TripTimes;
Expand All @@ -23,6 +26,7 @@ public class ScheduledTransitLegBuilder<B extends ScheduledTransitLegBuilder<B>>
private ConstrainedTransfer transferToNextLeg;
private int generalizedCost;
private Float accessibilityScore;
private Set<TransitAlert> alerts = new HashSet<>();

public ScheduledTransitLegBuilder() {}

Expand All @@ -40,6 +44,7 @@ public ScheduledTransitLegBuilder(ScheduledTransitLeg original) {
generalizedCost = original.getGeneralizedCost();
accessibilityScore = original.accessibilityScore();
zoneId = original.getZoneId();
alerts = original.getTransitAlerts();
}

public B withTripTimes(TripTimes tripTimes) {
Expand Down Expand Up @@ -159,6 +164,10 @@ public Float accessibilityScore() {
return accessibilityScore;
}

public Set<TransitAlert> alerts() {
return alerts;
}

public ScheduledTransitLeg build() {
return new ScheduledTransitLeg(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.opentripplanner.osm;

import crosby.binary.BinaryParser;
import crosby.binary.Osmformat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.openstreetmap.osmosis.osmbinary.BinaryParser;
import org.openstreetmap.osmosis.osmbinary.Osmformat;
import org.opentripplanner.graph_builder.module.osm.OsmDatabase;
import org.opentripplanner.osm.model.OsmMemberType;
import org.opentripplanner.osm.model.OsmNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.opentripplanner.osm;

import crosby.binary.file.BlockInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.ZoneId;
import org.openstreetmap.osmosis.osmbinary.file.BlockInputStream;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.datastore.api.FileType;
import org.opentripplanner.datastore.file.FileDataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opentripplanner.routing.algorithm.transferoptimization.configure.TransferOptimizationServiceConfigurator;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.StreetMode;
import org.opentripplanner.routing.api.request.preference.AccessEgressPreferences;
import org.opentripplanner.routing.api.request.request.StreetRequest;
import org.opentripplanner.routing.api.response.InputField;
import org.opentripplanner.routing.api.response.RoutingError;
Expand Down Expand Up @@ -239,6 +240,7 @@ private Collection<? extends RoutingAccessEgress> fetchEgress() {

private Collection<? extends RoutingAccessEgress> fetchAccessEgresses(AccessEgressType type) {
var streetRequest = type.isAccess() ? request.journey().access() : request.journey().egress();
StreetMode mode = streetRequest.mode();

// Prepare access/egress lists
RouteRequest accessRequest = request.clone();
Expand All @@ -252,13 +254,15 @@ private Collection<? extends RoutingAccessEgress> fetchAccessEgresses(AccessEgre
});
}

Duration durationLimit = accessRequest
AccessEgressPreferences accessEgressPreferences = accessRequest
.preferences()
.street()
.accessEgress()
.maxDuration()
.valueOf(streetRequest.mode());
int stopCountLimit = accessRequest.preferences().street().accessEgress().maxStopCount();
.accessEgress();

Duration durationLimit = accessEgressPreferences.maxDuration().valueOf(mode);
int stopCountLimit = accessEgressPreferences
.maxStopCountForMode()
.getOrDefault(mode, accessEgressPreferences.defaultMaxStopCount());

var nearbyStops = AccessEgressRouter.findAccessEgresses(
accessRequest,
Expand All @@ -275,7 +279,7 @@ private Collection<? extends RoutingAccessEgress> fetchAccessEgresses(AccessEgre
var results = new ArrayList<>(accessEgresses);

// Special handling of flex accesses
if (OTPFeature.FlexRouting.isOn() && streetRequest.mode() == StreetMode.FLEXIBLE) {
if (OTPFeature.FlexRouting.isOn() && mode == StreetMode.FLEXIBLE) {
var flexAccessList = FlexAccessEgressRouter.routeAccessEgress(
accessRequest,
temporaryVerticesContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.Serializable;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
Expand All @@ -27,18 +28,21 @@ public final class AccessEgressPreferences implements Serializable {

private final TimeAndCostPenaltyForEnum<StreetMode> penalty;
private final DurationForEnum<StreetMode> maxDuration;
private final int maxStopCount;
private final int defaultMaxStopCount;
private final Map<StreetMode, Integer> maxStopCountForMode;

private AccessEgressPreferences() {
this.maxDuration = durationForStreetModeOf(ofMinutes(45));
this.penalty = DEFAULT_TIME_AND_COST;
this.maxStopCount = 500;
this.defaultMaxStopCount = 500;
this.maxStopCountForMode = Map.of();
}

private AccessEgressPreferences(Builder builder) {
this.maxDuration = builder.maxDuration;
this.penalty = builder.penalty;
this.maxStopCount = builder.maxStopCount;
this.defaultMaxStopCount = builder.defaultMaxStopCount;
this.maxStopCountForMode = Collections.unmodifiableMap(builder.maxStopCountForMode);
}

public static Builder of() {
Expand All @@ -57,8 +61,12 @@ public DurationForEnum<StreetMode> maxDuration() {
return maxDuration;
}

public int maxStopCount() {
return maxStopCount;
public int defaultMaxStopCount() {
return defaultMaxStopCount;
}

public Map<StreetMode, Integer> maxStopCountForMode() {
return maxStopCountForMode;
}

@Override
Expand All @@ -69,13 +77,14 @@ public boolean equals(Object o) {
return (
penalty.equals(that.penalty) &&
maxDuration.equals(that.maxDuration) &&
maxStopCount == that.maxStopCount
defaultMaxStopCount == that.defaultMaxStopCount &&
maxStopCountForMode.equals(that.maxStopCountForMode)
);
}

@Override
public int hashCode() {
return Objects.hash(penalty, maxDuration, maxStopCount);
return Objects.hash(penalty, maxDuration, defaultMaxStopCount, maxStopCountForMode);
}

@Override
Expand All @@ -84,7 +93,8 @@ public String toString() {
.of(AccessEgressPreferences.class)
.addObj("penalty", penalty, DEFAULT.penalty)
.addObj("maxDuration", maxDuration, DEFAULT.maxDuration)
.addObj("maxStopCount", maxStopCount, DEFAULT.maxStopCount)
.addObj("defaultMaxStopCount", defaultMaxStopCount, DEFAULT.defaultMaxStopCount)
.addObj("maxStopCountForMode", maxStopCountForMode, DEFAULT.maxStopCountForMode)
.toString();
}

Expand All @@ -93,13 +103,15 @@ public static class Builder {
private final AccessEgressPreferences original;
private TimeAndCostPenaltyForEnum<StreetMode> penalty;
private DurationForEnum<StreetMode> maxDuration;
private int maxStopCount;
private Map<StreetMode, Integer> maxStopCountForMode;
private int defaultMaxStopCount;

public Builder(AccessEgressPreferences original) {
this.original = original;
this.maxDuration = original.maxDuration;
this.penalty = original.penalty;
this.maxStopCount = original.maxStopCount;
this.defaultMaxStopCount = original.defaultMaxStopCount;
this.maxStopCountForMode = original.maxStopCountForMode;
}

public Builder withMaxDuration(Consumer<DurationForEnum.Builder<StreetMode>> body) {
Expand All @@ -112,8 +124,12 @@ public Builder withMaxDuration(Duration defaultValue, Map<StreetMode, Duration>
return withMaxDuration(b -> b.withDefault(defaultValue).withValues(values));
}

public Builder withMaxStopCount(int maxCount) {
this.maxStopCount = maxCount;
public Builder withMaxStopCount(
int defaultMaxStopCount,
Map<StreetMode, Integer> maxStopCountForMode
) {
this.defaultMaxStopCount = defaultMaxStopCount;
this.maxStopCountForMode = maxStopCountForMode;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,20 @@ duration can be set per mode(`maxDurationForMode`), because some street modes se
Safety limit to prevent access to and egress from too many stops.
"""
)
.asInt(dftAccessEgress.maxStopCount())
.asInt(dftAccessEgress.defaultMaxStopCount()),
cae
.of("maxStopCountForMode")
.since(V2_7)
.summary(
"Maximal number of stops collected in access/egress routing for the given mode"
)
.description(
"""
Safety limit to prevent access to and egress from too many stops.
Mode-specific version of `maxStopCount`.
"""
)
.asEnumMap(StreetMode.class, Integer.class)
);
})
.withMaxDirectDuration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* <p>
* Descriptions are copied from the GTFS-RT specification with additions of SIRI nordic profile documentation.
*/
public enum OccupancyStatus implements DocumentedEnum {
public enum OccupancyStatus implements DocumentedEnum<OccupancyStatus> {
NO_DATA_AVAILABLE,
EMPTY,
MANY_SEATS_AVAILABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void runPolling() throws InterruptedException, ExecutionException {
final FeedMessage feed = otpHttpClient.getAndMap(
URI.create(url),
this.headers.asMap(),
FeedMessage.PARSER::parseFrom
FeedMessage::parseFrom
);

long feedTimestamp = feed.getHeader().getTimestamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void messageArrived(String topic, MqttMessage message) {
UpdateIncrementality updateIncrementality = FULL_DATASET;
try {
// Decode message
GtfsRealtime.FeedMessage feedMessage = GtfsRealtime.FeedMessage.PARSER.parseFrom(
GtfsRealtime.FeedMessage feedMessage = GtfsRealtime.FeedMessage.parseFrom(
message.getPayload()
);
List<GtfsRealtime.FeedEntity> feedEntityList = feedMessage.getEntityList();
Expand Down
Loading

0 comments on commit bef1c2d

Please sign in to comment.