Search in sources :

Example 6 with RoutingRequest

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));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Test(org.junit.Test)

Example 7 with 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);
}
Also used : AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) RentABikeOffEdge(org.opentripplanner.routing.edgetype.RentABikeOffEdge) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) RentABikeOnEdge(org.opentripplanner.routing.edgetype.RentABikeOnEdge) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) RentABikeOffEdge(org.opentripplanner.routing.edgetype.RentABikeOffEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RentABikeOnEdge(org.opentripplanner.routing.edgetype.RentABikeOnEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetBikeRentalLink(org.opentripplanner.routing.edgetype.StreetBikeRentalLink) HashSet(java.util.HashSet)

Example 8 with RoutingRequest

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));
}
Also used : Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare)

Example 9 with RoutingRequest

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));
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) SeattleFareServiceFactory(org.opentripplanner.routing.impl.SeattleFareServiceFactory) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest)

Example 10 with RoutingRequest

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));
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare)

Aggregations

RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)159 GraphPath (org.opentripplanner.routing.spt.GraphPath)52 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)43 State (org.opentripplanner.routing.core.State)37 Vertex (org.opentripplanner.routing.graph.Vertex)36 Test (org.junit.jupiter.api.Test)32 Test (org.junit.Test)30 Graph (org.opentripplanner.routing.graph.Graph)24 AStar (org.opentripplanner.routing.algorithm.astar.AStar)22 Edge (org.opentripplanner.routing.graph.Edge)21 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)20 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)20 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)20 RequestModes (org.opentripplanner.routing.api.request.RequestModes)18 StateEditor (org.opentripplanner.routing.core.StateEditor)18 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)14 Router (org.opentripplanner.standalone.server.Router)13 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11