use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestAStar method testBasic.
public void testBasic() throws Exception {
GtfsContext context = contextBuilder(ConstantsForTests.CALTRAIN_GTFS).build();
Graph gg = new Graph();
GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
factory.run(gg);
gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
RoutingRequest options = new RoutingRequest();
ShortestPathTree spt;
GraphPath path = null;
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");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
long endTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 13, 29, 0);
assertEquals(path.getEndTime(), endTime);
/* test backwards traversal */
options.setArriveBy(true);
options.dateTime = endTime;
options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Millbrae Caltrain"), true);
long expectedStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 39, 0);
assertTrue(path.getStartTime() - expectedStartTime <= 1);
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestFares method testFareComponent.
public void testFareComponent() throws Exception {
Graph gg = new Graph();
GtfsContext context = contextBuilder(ConstantsForTests.FARE_COMPONENT_GTFS).build();
GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
factory.run(gg);
gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
String feedId = gg.getFeedIds().iterator().next();
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
ShortestPathTree spt;
GraphPath path;
Fare fare;
List<FareComponent> fareComponents = null;
FareService fareService = gg.getService(FareService.class);
Money tenUSD = new Money(new WrappedCurrency("USD"), 1000);
// A -> B, base case
options.setRoutingContext(gg, feedId + ":A", feedId + ":B");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":B"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 1);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
// D -> E, null case
options.setRoutingContext(gg, feedId + ":D", feedId + ":E");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":E"), true);
// was: fareService.getCost(path);
fare = null;
assertNull(fare);
// A -> C, 2 components in a path
options.setRoutingContext(gg, feedId + ":A", feedId + ":C");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":C"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 2);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
assertEquals(fareComponents.get(1).price, tenUSD);
assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BC"));
assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
// B -> D, 2 fully connected components
options.setRoutingContext(gg, feedId + ":B", feedId + ":D");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":D"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 1);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "BD"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "2"));
assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "3"));
// E -> G, missing in between fare
options.setRoutingContext(gg, feedId + ":E", feedId + ":G");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":G"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 1);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
// C -> E, missing fare after
options.setRoutingContext(gg, feedId + ":C", feedId + ":E");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":E"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 1);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "CD"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "3"));
// D -> G, missing fare before
options.setRoutingContext(gg, feedId + ":D", feedId + ":G");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":G"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 1);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
// A -> D, use individual component parts
options.setRoutingContext(gg, feedId + ":A", feedId + ":D");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":D"), true);
// was: fareService.getCost(path);
fare = null;
fareComponents = fare.getDetails(FareType.regular);
assertEquals(fareComponents.size(), 2);
assertEquals(fareComponents.get(0).price, tenUSD);
assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
assertEquals(fareComponents.get(1).price, tenUSD);
assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BD"));
assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
assertEquals(fareComponents.get(1).routes.get(1), new FeedScopedId("agency", "3"));
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TurnRestrictionTest method testForwardAsCar.
@Test
public void testForwardAsCar() {
RoutingRequest options = new RoutingRequest(TraverseMode.CAR);
options.carSpeed = 1.0;
options.setRoutingContext(graph, topRight, bottomLeft);
ShortestPathTree tree = new AStar().getShortestPathTree(options);
GraphPath path = tree.getPath(bottomLeft, false);
assertNotNull(path);
// If not for turn restrictions, the shortest path would be to take 1st to Main,
// Main to 2nd, 2nd to Broad and Broad until the corner of Broad and 3rd.
// However, most of these turns are not allowed. Instead, the shortest allowed
// path is 1st to Broad, Broad to 3rd.
List<State> states = path.states;
assertEquals(5, states.size());
assertEquals("maple_1st", states.get(0).getVertex().getLabel());
assertEquals("main_1st", states.get(1).getVertex().getLabel());
assertEquals("broad_1st", states.get(2).getVertex().getLabel());
assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AStarTest method testForwardExtraEdges.
@Test
public void testForwardExtraEdges() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
new TemporaryConcreteEdge(from, graph.getVertex("shilshole_22nd"));
TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
new TemporaryConcreteEdge(graph.getVertex("56th_20th"), to);
options.setRoutingContext(graph, from, to);
ShortestPathTree tree = new AStar().getShortestPathTree(options);
options.cleanup();
GraphPath path = tree.getPath(to, false);
List<State> states = path.states;
assertEquals(9, states.size());
assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
assertEquals("market_22nd", states.get(3).getVertex().getLabel());
assertEquals("market_leary", states.get(4).getVertex().getLabel());
assertEquals("market_russell", states.get(5).getVertex().getLabel());
assertEquals("market_20th", states.get(6).getVertex().getLabel());
assertEquals("56th_20th", states.get(7).getVertex().getLabel());
assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AStarTest method testBack.
@Test
public void testBack() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
options.setArriveBy(true);
options.setRoutingContext(graph, graph.getVertex("56th_24th"), graph.getVertex("leary_20th"));
ShortestPathTree tree = new AStar().getShortestPathTree(options);
GraphPath path = tree.getPath(graph.getVertex("56th_24th"), false);
List<State> states = path.states;
assertTrue(states.size() == 6 || states.size() == 7);
assertEquals("56th_24th", states.get(0).getVertex().getLabel());
int n;
// we could go either way around the block formed by 56th, 22nd, market, and 24th.
if (states.size() == 7) {
assertEquals("market_24th", states.get(1).getVertex().getLabel());
assertEquals("market_ballard", states.get(2).getVertex().getLabel());
n = 0;
} else {
assertEquals("56th_22nd", states.get(1).getVertex().getLabel());
n = -1;
}
assertEquals("market_22nd", states.get(n + 3).getVertex().getLabel());
assertEquals("market_leary", states.get(n + 4).getVertex().getLabel());
assertEquals("leary_vernon", states.get(n + 5).getVertex().getLabel());
assertEquals("leary_20th", states.get(n + 6).getVertex().getLabel());
}
Aggregations