-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
139824b
commit 1d5778d
Showing
10 changed files
with
147 additions
and
25 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> gtfsFiles | ||
) { | ||
var extra = new HashMap<Class<?>, 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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters