Skip to content

Commit

Permalink
Merge pull request #235 from ibi-group/upstream-merge-2024-11-07
Browse files Browse the repository at this point in the history
Upstream merge 2024-11-07
  • Loading branch information
miles-grant-ibigroup authored Nov 11, 2024
2 parents 3be9af7 + 9452e12 commit 08f3833
Show file tree
Hide file tree
Showing 460 changed files with 4,859 additions and 702 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
branches:
- ibi-dev
- ibi-dev-2.x
env:
# Since version 3.9.0 of Maven it will automatically understand this environment variable.
# However, as of 2024-11 the latest versions of Ubuntu and Debian were on 3.8.8 so it will take some
# time until we can remove the $MAVEN_ARGS below.
MAVEN_ARGS: "--no-transfer-progress -Dstyle.color=always"
jobs:
build-linux:
env:
Expand Down Expand Up @@ -40,22 +45,29 @@ jobs:
# https://github.com/actions/runner-images/issues/1499
# we set nodePath and npmPath to skip downloading the node binary, which frequently times out
run: |
mvn --batch-mode jacoco:prepare-agent test jacoco:report -P prettierCheck,unit-tests -Dprettier.nodePath=node -Dprettier.npmPath=npm
mvn --batch-mode package -Dmaven.test.skip -P prettierSkip
mvn $MAVEN_ARGS jacoco:prepare-agent test jacoco:report -P prettierCheck,unit-tests -Dprettier.nodePath=node -Dprettier.npmPath=npm
mvn $MAVEN_ARGS package -Dmaven.test.skip -P prettierSkip
- name: Send coverage data to codecov.io
if: github.repository_owner == 'opentripplanner'
uses: codecov/codecov-action@v4
with:
files: target/site/jacoco/jacoco.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

- name: Upload test results to Codecov
# always upload test results, even when failed
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: "*TEST-*.xml"

- name: Deploy to Github Package Registry
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev-1.x' || github.ref == 'refs/heads/dev-2.x')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn --batch-mode deploy --settings maven-settings.xml -DskipTests -DGITHUB_REPOSITORY=$GITHUB_REPOSITORY -P prettierSkip -P deployGitHub
run: mvn $MAVEN_ARGS deploy --settings maven-settings.xml -DskipTests -DGITHUB_REPOSITORY=$GITHUB_REPOSITORY -P prettierSkip -P deployGitHub

## IBI start
# So that the branch name can be reference via $GITHUB_REF_SLUG.
Expand Down Expand Up @@ -122,7 +134,7 @@ jobs:
- name: Configure Windows Pagefile
uses: al-cheb/[email protected]
- name: Run tests
run: mvn --batch-mode test -P prettierSkip
run: mvn $MAVEN_ARGS test -P prettierSkip

docs:
if: github.repository_owner == 'opentripplanner'
Expand Down Expand Up @@ -235,7 +247,7 @@ jobs:
distribution: temurin
cache: maven
- name: Compile Java code
run: mvn --batch-mode compile -DskipTests -P prettierSkip
run: mvn $MAVEN_ARGS compile -DskipTests -P prettierSkip

container-image:
if: github.repository_owner == 'opentripplanner' && github.event_name == 'push' && (github.ref == 'refs/heads/dev-2.x' || github.ref == 'refs/heads/master')
Expand Down Expand Up @@ -279,4 +291,4 @@ jobs:
MAVEN_SKIP_ARGS="-P prettierSkip -Dmaven.test.skip=true -Dmaven.source.skip=true"
mvn --batch-mode $MAVEN_SKIP_ARGS package com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_version
mvn $MAVEN_ARGS $MAVEN_SKIP_ARGS package com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_version
5 changes: 5 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>otp-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>otp-raptor</artifactId>
<version>${project.version}</version>
</dependency>

<!-- 3rd party dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void carHail() {
@Test
void carHailWithTransit() {
var modeSet = new QualifiedModeSet("CAR_HAIL,BUS,RAIL");
assertEquals(Set.of(COACH, BUS, RAIL), Set.copyOf(modeSet.getTransitModes()));
assertEquals(Set.of(BUS, RAIL), Set.copyOf(modeSet.getTransitModes()));

assertEquals(WALK, modeSet.getRequestModes().directMode);
assertEquals(CAR_HAILING, modeSet.getRequestModes().accessMode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.opentripplanner.ext.sorlandsbanen;

import org.opentripplanner.raptor.api.model.RaptorAccessEgress;
import org.opentripplanner.raptor.api.model.RaptorCostConverter;
import org.opentripplanner.raptor.api.model.RaptorTransferConstraint;
import org.opentripplanner.raptor.spi.RaptorCostCalculator;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.cost.RaptorCostConverter;
import org.opentripplanner.transit.model.basic.TransitMode;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum ApiRequestMode {
TRAM(TransitMode.TRAM),
SUBWAY(TransitMode.SUBWAY),
RAIL(TransitMode.RAIL),
BUS(TransitMode.BUS, TransitMode.COACH),
BUS(TransitMode.BUS),
COACH(TransitMode.COACH),
FERRY(TransitMode.FERRY),
CABLE_CAR(TransitMode.CABLE_CAR),
GONDOLA(TransitMode.GONDOLA),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.opentripplanner.routing.graphfinder.PatternAtStop;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
import org.opentripplanner.routing.graphfinder.PlaceType;
import org.opentripplanner.routing.services.TransitAlertService;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingService;
import org.opentripplanner.service.vehiclerental.VehicleRentalService;
Expand Down Expand Up @@ -394,7 +395,7 @@ public DataFetcher<Object> node() {
case "Agency":
return transitService.getAgencyForId(FeedScopedId.parse(id));
case "Alert":
return null; //TODO
return transitService.getTransitAlertService().getAlertById(FeedScopedId.parse(id));
case "BikePark":
var bikeParkId = FeedScopedId.parse(id);
return vehicleParkingService == null
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.opentripplanner.astar.strategy;

import java.util.function.Predicate;
import org.opentripplanner.astar.spi.AStarState;
import org.opentripplanner.astar.spi.SearchTerminationStrategy;

/**
* This termination strategy is used to terminate an a-star search after a number of states matching
* some criteria has been found. For example it can be used to limit a search to a maximum number of
* stops.
*/
public class MaxCountTerminationStrategy<State extends AStarState<State, ?, ?>>
implements SearchTerminationStrategy<State> {

private final int maxCount;
private final Predicate<State> shouldIncreaseCount;
private int count;

/**
* @param maxCount Terminate the search after this many matching states have been reached.
* @param shouldIncreaseCount A predicate to check if a state should increase the count or not.
*/
public MaxCountTerminationStrategy(int maxCount, Predicate<State> shouldIncreaseCount) {
this.maxCount = maxCount;
this.shouldIncreaseCount = shouldIncreaseCount;
this.count = 0;
}

@Override
public boolean shouldSearchTerminate(State current) {
if (shouldIncreaseCount.test(current)) {
count++;
}
return count >= maxCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.util.List;
import java.util.Set;
import org.opentripplanner.astar.model.ShortestPathTree;
import org.opentripplanner.astar.spi.SkipEdgeStrategy;
import org.opentripplanner.astar.strategy.ComposingSkipEdgeStrategy;
import org.opentripplanner.astar.strategy.DurationSkipEdgeStrategy;
import org.opentripplanner.astar.strategy.MaxCountSkipEdgeStrategy;
import org.opentripplanner.astar.strategy.MaxCountTerminationStrategy;
import org.opentripplanner.ext.dataoverlay.routing.DataOverlayContext;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.framework.application.OTPRequestTimeoutException;
Expand All @@ -30,8 +28,6 @@
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.search.StreetSearchBuilder;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.request.StreetSearchRequest;
import org.opentripplanner.street.search.request.StreetSearchRequestMapper;
import org.opentripplanner.street.search.state.State;
import org.opentripplanner.street.search.strategy.DominanceFunctions;
import org.opentripplanner.transit.model.site.AreaStop;
Expand All @@ -46,8 +42,8 @@ public class StreetNearbyStopFinder implements NearbyStopFinder {
/**
* Construct a NearbyStopFinder for the given graph and search radius.
*
* @param maxStopCount The maximum stops to return. 0 means no limit. Regardless of the maxStopCount
* we will always return all the directly connected stops.
* @param maxStopCount The maximum stops to return. 0 means no limit. Regardless of the
* maxStopCount we will always return all the directly connected stops.
*/
public StreetNearbyStopFinder(
Duration durationLimit,
Expand Down Expand Up @@ -117,23 +113,30 @@ public Collection<NearbyStop> findNearbyStops(
// Return only the origin vertices if there are no valid street modes
if (
streetRequest.mode() == StreetMode.NOT_SET ||
(maxStopCount != 0 && stopsFound.size() >= maxStopCount)
(maxStopCount > 0 && stopsFound.size() >= maxStopCount)
) {
return stopsFound;
}
stopsFound = new ArrayList<>(stopsFound);

ShortestPathTree<State, Edge, Vertex> spt = StreetSearchBuilder
var streetSearch = StreetSearchBuilder
.of()
.setSkipEdgeStrategy(getSkipEdgeStrategy())
.setSkipEdgeStrategy(new DurationSkipEdgeStrategy<>(durationLimit))
.setDominanceFunction(new DominanceFunctions.MinimumWeight())
.setRequest(request)
.setArriveBy(reverseDirection)
.setStreetRequest(streetRequest)
.setFrom(reverseDirection ? null : originVertices)
.setTo(reverseDirection ? originVertices : null)
.setDataOverlayContext(dataOverlayContext)
.getShortestPathTree();
.setDataOverlayContext(dataOverlayContext);

if (maxStopCount > 0) {
streetSearch.setTerminationStrategy(
new MaxCountTerminationStrategy<>(maxStopCount, this::hasReachedStop)
);
}

ShortestPathTree<State, Edge, Vertex> spt = streetSearch.getShortestPathTree();

// Only used if OTPFeature.FlexRouting.isOn()
Multimap<AreaStop, State> locationsMap = ArrayListMultimap.create();
Expand Down Expand Up @@ -186,16 +189,6 @@ public Collection<NearbyStop> findNearbyStops(
return stopsFound;
}

private SkipEdgeStrategy<State, Edge> getSkipEdgeStrategy() {
var durationSkipEdgeStrategy = new DurationSkipEdgeStrategy(durationLimit);

if (maxStopCount > 0) {
var strategy = new MaxCountSkipEdgeStrategy<>(maxStopCount, this::hasReachedStop);
return new ComposingSkipEdgeStrategy<>(strategy, durationSkipEdgeStrategy);
}
return durationSkipEdgeStrategy;
}

private boolean canBoardFlex(State state, boolean reverse) {
Collection<Edge> edges = reverse
? state.getVertex().getIncoming()
Expand All @@ -212,13 +205,13 @@ private boolean canBoardFlex(State state, boolean reverse) {
* <p>
* This is important because there can be cases where states that cannot actually board the vehicle
* can dominate those that can thereby leading to zero found stops when this predicate is used with
* the {@link MaxCountSkipEdgeStrategy}.
* the {@link MaxCountTerminationStrategy}.
* <p>
* An example of this would be an egress/reverse search with a very high walk reluctance where the
* states that speculatively rent a vehicle move the walk states down the A* priority queue until
* the required number of stops are reached to abort the search, leading to zero egress results.
*/
public boolean hasReachedStop(State state) {
private boolean hasReachedStop(State state) {
var vertex = state.getVertex();
return (
vertex instanceof TransitStopVertex && state.isFinal() && !ignoreVertices.contains(vertex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static TransitMode mapMode(int routeType) {
// Railway Service
return TransitMode.RAIL;
} else if (routeType >= 200 && routeType < 300) { //Coach Service
return TransitMode.BUS;
return TransitMode.COACH;
} else if (routeType >= 300 && routeType < 500) { //Suburban Railway Service and Urban Railway service
if (routeType >= 401 && routeType <= 402) {
return TransitMode.SUBWAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@

/**
* Represents the real-time update of a single trip.
* @param pattern the pattern to which belongs the updated trip. This can be a new pattern created in real-time.
* @param updatedTripTimes the new trip times for the updated trip.
* @param serviceDate the service date for which this update applies (updates are valid only for one service date)
* @param addedTripOnServiceDate optionally if this trip update adds a new trip, the TripOnServiceDate corresponding to this new trip.
* @param tripCreation true if this update creates a new trip, not present in scheduled data.
* @param routeCreation true if an added trip cannot be registered under an existing route and a new route must be created.
*
* @param pattern the pattern to which belongs the updated trip. This can be a new
* pattern created in real-time.
* @param updatedTripTimes the new trip times for the updated trip.
* @param serviceDate the service date for which this update applies (updates are valid
* only for one service date)
* @param addedTripOnServiceDate optionally if this trip update adds a new trip, the
* TripOnServiceDate corresponding to this new trip.
* @param tripCreation true if this update creates a new trip, not present in scheduled
* data.
* @param routeCreation true if an added trip cannot be registered under an existing route
* and a new route must be created.
* @param producer the producer of the real-time update.
*/
public record RealTimeTripUpdate(
TripPattern pattern,
TripTimes updatedTripTimes,
LocalDate serviceDate,
@Nullable TripOnServiceDate addedTripOnServiceDate,
boolean tripCreation,
boolean routeCreation
boolean routeCreation,
@Nullable String producer
) {
public RealTimeTripUpdate {
Objects.requireNonNull(pattern);
Expand All @@ -38,6 +46,25 @@ public RealTimeTripUpdate(
TripTimes updatedTripTimes,
LocalDate serviceDate
) {
this(pattern, updatedTripTimes, serviceDate, null, false, false);
this(pattern, updatedTripTimes, serviceDate, null, false, false, null);
}

public RealTimeTripUpdate(
TripPattern pattern,
TripTimes updatedTripTimes,
LocalDate serviceDate,
@Nullable TripOnServiceDate addedTripOnServiceDate,
boolean tripCreation,
boolean routeCreation
) {
this(
pattern,
updatedTripTimes,
serviceDate,
addedTripOnServiceDate,
tripCreation,
routeCreation,
null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ public Result<UpdateSuccess, UpdateError> update(RealTimeTripUpdate realTimeTrip
}

// The time tables are finished during the commit

return Result.success(UpdateSuccess.noWarnings());
return Result.success(UpdateSuccess.noWarnings(realTimeTripUpdate.producer()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.opentripplanner.model.SystemNotice;
import org.opentripplanner.model.fare.ItineraryFares;
import org.opentripplanner.raptor.api.model.RaptorConstants;
import org.opentripplanner.raptor.api.model.RaptorCostConverter;
import org.opentripplanner.raptor.api.path.PathStringBuilder;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.cost.RaptorCostConverter;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.preference.ItineraryFilterPreferences;
import org.opentripplanner.utils.lang.DoubleUtils;
Expand Down
Loading

0 comments on commit 08f3833

Please sign in to comment.