use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class SimpleStreetSplitterTest method testFindEndVertexForParkAndRide.
/**
* Tests that traverse mode WALK is used when getting closest end vertex for park and ride.
*/
@Test
public void testFindEndVertexForParkAndRide() {
GenericLocation genericLocation = new GenericLocation(10.0, 23.0);
RoutingRequest routingRequest = new RoutingRequest();
routingRequest.setMode(TraverseMode.CAR);
routingRequest.parkAndRide = true;
spySimpleStreetSplitter.getClosestVertex(genericLocation, routingRequest, true);
verify(spySimpleStreetSplitter).link(any(Vertex.class), eq(TraverseMode.WALK), eq(routingRequest));
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestBikeRental method testBasic.
public void testBasic() throws Exception {
// generate a very simple graph
Graph graph = new Graph();
StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
@SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
@SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
AStar aStar = new AStar();
// it is impossible to get from v1 to v3 by walking
RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT));
options.setRoutingContext(graph, v1, v3);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(v3, false);
assertNull(path);
// or biking + walking (assuming walking bikes is disallowed)
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.BICYCLE, TraverseMode.TRANSIT));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNull(path);
// so we add a bike share
BikeRentalStation station = new BikeRentalStation();
station.id = "id";
station.name = new NonLocalizedString("station");
station.x = -77.049;
station.y = 36.856;
station.bikesAvailable = 5;
station.spacesAvailable = 5;
BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
new StreetBikeRentalLink(stationVertex, v2);
new StreetBikeRentalLink(v2, stationVertex);
Set<String> networks = new HashSet<String>(Arrays.asList("default"));
new RentABikeOnEdge(stationVertex, stationVertex, networks);
new RentABikeOffEdge(stationVertex, stationVertex, networks);
// but we can't get off the bike at v3, so we still fail
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.BICYCLE, TraverseMode.TRANSIT));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
// null is returned because the only state at the target is not final
assertNull(path);
BikeRentalStation station2 = new BikeRentalStation();
station2.id = "id2";
station2.name = new NonLocalizedString("station2");
station2.x = -77.049;
station2.y = 36.857;
station2.bikesAvailable = 5;
station2.spacesAvailable = 5;
BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
new StreetBikeRentalLink(stationVertex2, v3);
new StreetBikeRentalLink(v3, stationVertex2);
new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
// now we succeed!
options = new RoutingRequest();
options.streetSubRequestModes.setWalk(true);
options.streetSubRequestModes.setBicycle(true);
options.bikeRental = true;
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNotNull(path);
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestFares method testPortland.
public void testPortland() throws Exception {
Graph gg = ConstantsForTests.getInstance().getPortlandGraph();
String feedId = gg.getFeedIds().iterator().next();
RoutingRequest options = new RoutingRequest();
ShortestPathTree spt;
GraphPath path = null;
long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 0, 0);
options.dateTime = startTime;
options.setRoutingContext(gg, feedId + ":10579", feedId + ":8371");
// from zone 3 to zone 2
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":8371"), true);
assertNotNull(path);
FareService fareService = gg.getService(FareService.class);
// was: fareService.getCost(path);
Fare cost = null;
assertEquals(new Money(new WrappedCurrency("USD"), 200), cost.getFare(FareType.regular));
// long trip
startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 14, 0, 0);
options.dateTime = startTime;
options.setRoutingContext(gg, feedId + ":8389", feedId + ":1252");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":1252"), true);
assertNotNull(path);
// was: fareService.getCost(path);
cost = null;
// assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 460));
// complex trip
options.maxTransfers = 5;
startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 14, 0, 0);
options.dateTime = startTime;
options.setRoutingContext(gg, feedId + ":10428", feedId + ":4231");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":4231"), true);
assertNotNull(path);
// was: fareService.getCost(path);
cost = null;
//
// this is commented out because portland's fares are, I think, broken in the gtfs. see
// thread on gtfs-changes.
// assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 430));
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestFares method testKCM.
public void testKCM() throws Exception {
Graph gg = new Graph();
GtfsContext context = contextBuilder(ConstantsForTests.KCM_GTFS).build();
GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
factory.setFareServiceFactory(new SeattleFareServiceFactory());
factory.run(gg);
gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
RoutingRequest options = new RoutingRequest();
String feedId = gg.getFeedIds().iterator().next();
String vertex0 = feedId + ":2010";
String vertex1 = feedId + ":2140";
ShortestPathTree spt;
GraphPath path = null;
FareService fareService = gg.getService(FareService.class);
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 5, 0, 0);
options.setRoutingContext(gg, vertex0, vertex1);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(vertex1), true);
// was: fareService.getCost(path);
Fare costOffPeak = null;
assertEquals(costOffPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 250));
long onPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 8, 0, 0);
options.dateTime = onPeakStartTime;
options.setRoutingContext(gg, vertex0, vertex1);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(vertex1), true);
// was: fareService.getCost(path);
Fare costOnPeak = null;
assertEquals(costOnPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 275));
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestFares method testBasic.
public void testBasic() throws Exception {
Graph gg = new Graph();
GtfsContext context = contextBuilder(ConstantsForTests.CALTRAIN_GTFS).build();
GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
factory.run(gg);
gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
RoutingRequest options = new RoutingRequest();
String feedId = gg.getFeedIds().iterator().next();
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
ShortestPathTree spt;
GraphPath path = null;
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
FareService fareService = gg.getService(FareService.class);
// was: fareService.getCost(path);
Fare cost = null;
assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 425));
}
Aggregations