diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java new file mode 100644 index 00000000000..9b7e274e9ea --- /dev/null +++ b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java @@ -0,0 +1,140 @@ +package org.opentripplanner.ext.flex; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.graph_builder.module.FakeGraph.getFileForResource; +import static org.opentripplanner.routing.api.request.StreetMode.FLEXIBLE; + +import java.io.File; +import java.net.URISyntaxException; +import java.time.Duration; +import java.time.ZonedDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.opentripplanner.ConstantsForTests; +import org.opentripplanner.graph_builder.model.GtfsBundle; +import org.opentripplanner.graph_builder.module.DirectTransferGenerator; +import org.opentripplanner.graph_builder.module.GtfsModule; +import org.opentripplanner.graph_builder.module.StreetLinkerModule; +import org.opentripplanner.model.GenericLocation; +import org.opentripplanner.model.calendar.ServiceDateInterval; +import org.opentripplanner.model.plan.Itinerary; +import org.opentripplanner.routing.RoutingService; +import org.opentripplanner.routing.api.request.RoutingRequest; +import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.routing.graph.Graph; +import org.opentripplanner.standalone.config.RouterConfig; +import org.opentripplanner.standalone.server.Router; +import org.opentripplanner.util.OTPFeature; + +/** + * This test checks the combination of transit and flex works. + */ +public class FlexIntegrationTest { + + static long dateTime = ZonedDateTime.parse("2021-12-02T12:00:00-05:00[America/New_York]") + .toInstant() + .getEpochSecond(); + + static Graph graph; + static RoutingService service; + static Router router; + + @BeforeAll + static void setup() throws URISyntaxException { + OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, true)); + var osmPath = getFileForResource(FlexTest.COBB_OSM).getAbsolutePath(); + var gtfsPath = getFileForResource(FlexTest.COBB_BUS_30_GTFS).getAbsolutePath(); + var flexGtfsPath = getFileForResource(FlexTest.COBB_FLEX_GTFS).getAbsolutePath(); + + graph = ConstantsForTests.buildOsmGraph(osmPath); + addGtfsToGraph(graph, List.of(gtfsPath, flexGtfsPath)); + router = new Router(graph, RouterConfig.DEFAULT); + router.startup(); + + service = new RoutingService(graph); + } + + @Test + public void shouldReturnARouteTransferringFromBusToFlex() { + var from = new GenericLocation(33.84329482265106, -84.583740234375); + var to = new GenericLocation(33.86701256815635, -84.61787939071655); + + var itin = getItinerary(graph, from, to); + + assertEquals(4, itin.legs.size()); + + var walkToBus = itin.legs.get(0); + assertEquals(TraverseMode.WALK, walkToBus.mode); + + var bus = itin.legs.get(1); + assertEquals(TraverseMode.BUS, bus.mode); + assertEquals("30", bus.getRoute().getShortName()); + + var transfer = itin.legs.get(2); + assertEquals(TraverseMode.WALK, transfer.mode); + + var flex = itin.legs.get(3); + assertEquals(TraverseMode.BUS, flex.mode); + assertEquals("Zone 2", flex.getRoute().getShortName()); + assertTrue(flex.flexibleTrip); + + } + + private Itinerary getItinerary(Graph graph, GenericLocation from, GenericLocation to) { + RoutingRequest request = new RoutingRequest(); + request.dateTime = dateTime; + request.from = from; + request.to = to; + request.numItineraries = 10; + request.searchWindow = Duration.ofHours(2); + request.setRoutingContext(graph); + + request.modes.egressMode = FLEXIBLE; + + var result = service.route(request, router); + var itineraries = result.getTripPlan().itineraries; + + return itineraries.get(2); + } + + private static void addGtfsToGraph( + Graph graph, + List gtfsFiles + ) { + var extra = new HashMap, Object>(); + + // GTFS + var gtfsBundles = gtfsFiles.stream() + .map(f -> new GtfsBundle(new File(f))) + .collect(Collectors.toList()); + GtfsModule gtfsModule = new GtfsModule(gtfsBundles, ServiceDateInterval.unbounded()); + gtfsModule.buildGraph(graph, extra); + + // link stations to streets + StreetLinkerModule streetLinkerModule = new StreetLinkerModule(); + streetLinkerModule.buildGraph(graph, extra); + + // link flex locations to streets + var flexMapper = new FlexLocationsToStreetEdgesMapper(); + flexMapper.buildGraph(graph, new HashMap<>()); + + // generate direct transfers + var req = new RoutingRequest(); + var transfers = new DirectTransferGenerator(600, List.of(req)); + transfers.buildGraph(graph, extra); + + graph.index(); + } + + + @AfterAll + static void teardown() { + OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, false)); + } +} diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/FlexTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/FlexTest.java index a0da1a8e361..0c38e92e406 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/FlexTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/FlexTest.java @@ -19,6 +19,11 @@ abstract public class FlexTest { + static final String ASPEN_GTFS = "/flex/aspen-flex-on-demand.gtfs.zip"; + static final String COBB_FLEX_GTFS = "/flex/cobblinc-scheduled-deviated-flex.gtfs.zip"; + static final String COBB_BUS_30_GTFS = "/flex/cobblinc-bus-30-only.gtfs.zip"; + static final String COBB_OSM = "/flex/cobb-county.filtered.osm.pbf"; + static final DirectFlexPathCalculator calculator = new DirectFlexPathCalculator(null); static final ServiceDate serviceDate = new ServiceDate(2021, 4, 11); static final int secondsSinceMidnight = LocalTime.of(10, 0).toSecondOfDay(); diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/ScheduledDeviatedTripTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/ScheduledDeviatedTripTest.java index cb19f395444..6d3a71790ac 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/ScheduledDeviatedTripTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/ScheduledDeviatedTripTest.java @@ -35,8 +35,6 @@ */ public class ScheduledDeviatedTripTest extends FlexTest { - static final String COBB_COUNTY_GTFS = "/flex/cobblinc-scheduled-deviated-flex.gtfs.zip"; - static Graph graph; @Test @@ -121,7 +119,7 @@ public void calculateDirectFare() { @BeforeAll static void setup() throws URISyntaxException { - graph = FlexTest.buildFlexGraph(COBB_COUNTY_GTFS); + graph = FlexTest.buildFlexGraph(COBB_FLEX_GTFS); } private static NearbyStop getNearbyStop(FlexTrip trip) { diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/UnscheduledTripTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/UnscheduledTripTest.java index 9206aa661ce..6bbcde88f86 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/UnscheduledTripTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/UnscheduledTripTest.java @@ -25,8 +25,6 @@ */ public class UnscheduledTripTest extends FlexTest { - static final String ASPEN_GTFS = "/flex/aspen-flex-on-demand.gtfs.zip"; - static Graph graph; @Test diff --git a/src/ext-test/resources/flex/cobb-county.filtered.osm.pbf b/src/ext-test/resources/flex/cobb-county.filtered.osm.pbf new file mode 100644 index 00000000000..6a958703cef Binary files /dev/null and b/src/ext-test/resources/flex/cobb-county.filtered.osm.pbf differ diff --git a/src/ext-test/resources/flex/cobblinc-bus-30-only.gtfs.zip b/src/ext-test/resources/flex/cobblinc-bus-30-only.gtfs.zip new file mode 100644 index 00000000000..37716690a40 Binary files /dev/null and b/src/ext-test/resources/flex/cobblinc-bus-30-only.gtfs.zip differ diff --git a/src/main/java/org/opentripplanner/routing/algorithm/transferoptimization/model/OptimizedPathTail.java b/src/main/java/org/opentripplanner/routing/algorithm/transferoptimization/model/OptimizedPathTail.java index c9710ccc567..f57a6e3bb7e 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/transferoptimization/model/OptimizedPathTail.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/transferoptimization/model/OptimizedPathTail.java @@ -86,7 +86,6 @@ public OptimizedPathTail mutate() { /** Start by adding the last transit leg with the egress leg attached. */ public OptimizedPathTail addTransitTail(TransitPathLeg leg) { var next = leg.nextLeg(); - // this could also be a transfer to a flex leg if(next.isTransferLeg()) { next = next.nextLeg(); } diff --git a/src/main/java/org/opentripplanner/updater/GraphUpdaterManager.java b/src/main/java/org/opentripplanner/updater/GraphUpdaterManager.java index aa8a8e1a0f8..e692064c8d5 100644 --- a/src/main/java/org/opentripplanner/updater/GraphUpdaterManager.java +++ b/src/main/java/org/opentripplanner/updater/GraphUpdaterManager.java @@ -202,7 +202,7 @@ private void reportReadinessForUpdaters() { while (true) { try { if (updaterList.stream().allMatch(GraphUpdater::isPrimed)) { - LOG.info("OTP UPDATERS INITIALIZED - OTP is read for routing!"); + LOG.info("OTP UPDATERS INITIALIZED - OTP is ready for routing!"); return; } //noinspection BusyWait diff --git a/src/test/java/org/opentripplanner/gtfs/GtfsContextBuilder.java b/src/test/java/org/opentripplanner/gtfs/GtfsContextBuilder.java index 76aa1a7f89d..a318656be7c 100644 --- a/src/test/java/org/opentripplanner/gtfs/GtfsContextBuilder.java +++ b/src/test/java/org/opentripplanner/gtfs/GtfsContextBuilder.java @@ -93,18 +93,6 @@ public GtfsContextBuilder withDeduplicator(Deduplicator deduplicator) { return this; } - /** - * The {@link org.opentripplanner.graph_builder.module.GtfsModule} is responsible for repairing - * StopTimes for all trips and trip patterns generation, so turn this feature off - * when using GtfsModule to load data. - * - * This feature is turned on by default. - */ - public GtfsContextBuilder turnOffRepairStopTimesAndTripPatternsGeneration() { - this.repairStopTimesAndGenerateTripPatterns = false; - return this; - } - /** * This method will: *
    diff --git a/src/test/java/org/opentripplanner/transit/raptor/_data/stoparrival/BasicPathTestCase.java b/src/test/java/org/opentripplanner/transit/raptor/_data/stoparrival/BasicPathTestCase.java index 0af48193de1..f7ef5dee1e0 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/_data/stoparrival/BasicPathTestCase.java +++ b/src/test/java/org/opentripplanner/transit/raptor/_data/stoparrival/BasicPathTestCase.java @@ -10,12 +10,6 @@ import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; -import org.opentripplanner.ext.flex.FlexAccessEgress; -import org.opentripplanner.model.Stop; -import org.opentripplanner.routing.algorithm.GraphRoutingTest; -import org.opentripplanner.routing.algorithm.raptor.transit.FlexAccessEgressAdapter; -import org.opentripplanner.routing.algorithm.raptor.transit.StopIndexForRaptor; -import org.opentripplanner.routing.algorithm.raptor.transit.TransitTuningParameters; import org.opentripplanner.routing.algorithm.raptor.transit.cost.DefaultCostCalculator; import org.opentripplanner.transit.raptor._data.RaptorTestConstants; import org.opentripplanner.transit.raptor._data.transit.TestTransfer;