use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestTransfers method testForbiddenStopToStopTransfer.
public void testForbiddenStopToStopTransfer() throws Exception {
// Replace the transfer table with an empty table
TransferTable table = new TransferTable();
when(graph.getTransferTable()).thenReturn(table);
// Compute a normal path between two stops
Vertex origin = graph.getVertex(feedId + ":N");
Vertex destination = graph.getVertex(feedId + ":H");
// Set options like time and routing context
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
options.setRoutingContext(graph, origin, destination);
// Plan journey
GraphPath path;
List<Trip> trips;
path = planJourney(options);
trips = extractTrips(path);
// Validate result
assertEquals("8.1", trips.get(0).getId().getId());
assertEquals("4.2", trips.get(1).getId().getId());
// Add forbidden transfer to table
Stop stopK = new Stop();
stopK.setId(new AgencyAndId(feedId, "K"));
Stop stopF = new Stop();
stopF.setId(new AgencyAndId(feedId, "F"));
table.addTransferTime(stopK, stopF, null, null, null, null, StopTransfer.FORBIDDEN_TRANSFER);
// Plan journey
path = planJourney(options);
trips = extractTrips(path);
// Check that no trip was returned
assertEquals(0, trips.size());
// Revert the graph, thus using the original transfer table again
reset(graph);
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestTransfers method planJourney.
/**
* Plan journey and return list of states and edges
* @param options are options to use for planning the journey
* @param optimize is true when optimization should be used
* @return ordered list of states and edges in the journey
*/
private GraphPath planJourney(RoutingRequest options, boolean optimize) {
// Calculate route and convert to path
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(options.rctx.target, optimize);
// Return list of states and edges in the journey
return path;
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TimetableTest method testUpdate.
@Test
public void testUpdate() {
TripUpdate tripUpdate;
TripUpdate.Builder tripUpdateBuilder;
TripDescriptor.Builder tripDescriptorBuilder;
StopTimeUpdate.Builder stopTimeUpdateBuilder;
StopTimeEvent.Builder stopTimeEventBuilder;
String feedId = graph.getFeedIds().iterator().next();
int trip_1_1_index = timetable.getTripIndex(new AgencyAndId("agency", "1.1"));
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_c = graph.getVertex(feedId + ":C");
RoutingRequest options = new RoutingRequest();
ShortestPathTree spt;
GraphPath path;
// non-existing trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("b");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
tripUpdate = tripUpdateBuilder.build();
TripTimes updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNull(updatedTripTimes);
// update trip with bad data
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(0);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SKIPPED);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNull(updatedTripTimes);
// update trip with non-increasing data
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(2);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 10, 1));
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 10, 0));
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNull(updatedTripTimes);
// ---
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 0, 0);
long endTime;
options.dateTime = startTime;
// ---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 20 * 60;
assertEquals(endTime, path.getEndTime());
// update trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(1);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 2, 0));
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 2, 0));
tripUpdate = tripUpdateBuilder.build();
assertEquals(20 * 60, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
assertEquals(20 * 60 + 120, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));
// ---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 20 * 60 + 120;
assertEquals(endTime, path.getEndTime());
// cancel trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
TripTimes tripTimes = timetable.getTripTimes(trip_1_1_index);
for (int i = 0; i < tripTimes.getNumStops(); i++) {
assertEquals(TripTimes.UNAVAILABLE, tripTimes.getDepartureTime(i));
assertEquals(TripTimes.UNAVAILABLE, tripTimes.getArrivalTime(i));
}
// ---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 40 * 60;
assertEquals(endTime, path.getEndTime());
// update trip arrival time incorrectly
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(1);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setDelay(0);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
// update trip arrival time only
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(2);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setDelay(1);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
// update trip departure time only
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(2);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setDelay(-1);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
// update trip using stop id
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopId("B");
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setDelay(-1);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNotNull(updatedTripTimes);
timetable.setTripTimes(trip_1_1_index, updatedTripTimes);
// update trip arrival time at first stop and make departure time incoherent at second stop
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(1);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setDelay(0);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(1);
stopTimeUpdateBuilder.setStopSequence(2);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setDelay(-1);
tripUpdate = tripUpdateBuilder.build();
updatedTripTimes = timetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate);
assertNull(updatedTripTimes);
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestHopFactory method testDwell.
public void testDwell() throws Exception {
Vertex stop_a = graph.getVertex(feedId + ":A_depart");
Vertex stop_c = graph.getVertex(feedId + ":C_arrive");
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 8, 0, 0);
options.setRoutingContext(graph, stop_a, stop_c);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(stop_c, false);
assertNotNull(path);
assertEquals(6, path.states.size());
long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 8, 30, 0);
assertEquals(endTime, path.getEndTime());
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestHopFactory method testRouting.
public void testRouting() throws Exception {
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_b = graph.getVertex(feedId + ":B");
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_d = graph.getVertex(feedId + ":D");
Vertex stop_e = graph.getVertex(feedId + ":E");
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
ShortestPathTree spt;
GraphPath path;
// A to B
options.setRoutingContext(graph, stop_a, stop_b);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_b, false);
assertNotNull(path);
assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_b));
// A to C
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c));
// A to D
options.setRoutingContext(graph, stop_a, stop_d);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_d, false);
assertNotNull(path);
assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c, stop_d));
long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0) + 40 * 60;
assertEquals(endTime, path.getEndTime());
// A to E
options.setRoutingContext(graph, stop_a, stop_e);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, false);
assertNotNull(path);
assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c, stop_e));
endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0) + 70 * 60;
assertEquals(endTime, path.getEndTime());
}
Aggregations