use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class PlainStreetEdgeTest method testTraverseModeSwitchBike.
/**
* Test the traversal of two edges with different traverse modes, with a focus on cycling.
* This test will fail unless the following three conditions are met:
* 1. Turn costs are computed based on the back edge's traverse mode during reverse traversal.
* 2. Turn costs are computed such that bike walking is taken into account correctly.
* 3. User-specified bike speeds are applied correctly during turn cost computation.
*/
@Test
public void testTraverseModeSwitchBike() {
StreetEdge e0 = edge(v0, v1, 50.0, StreetTraversalPermission.PEDESTRIAN);
StreetEdge e1 = edge(v1, v2, 18.4, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
v1.trafficLight = (true);
RoutingRequest forward = proto.clone();
forward.setMode(TraverseMode.BICYCLE);
forward.bikeSpeed = 3.0f;
forward.setRoutingContext(_graph, v0, v2);
State s0 = new State(forward);
State s1 = e0.traverse(s0);
State s2 = e1.traverse(s1);
RoutingRequest reverse = proto.clone();
reverse.setMode(TraverseMode.BICYCLE);
reverse.setArriveBy(true);
reverse.bikeSpeed = 3.0f;
reverse.setRoutingContext(_graph, v0, v2);
State s3 = new State(reverse);
State s4 = e1.traverse(s3);
State s5 = e0.traverse(s4);
assertEquals(73, s2.getElapsedTimeSeconds());
assertEquals(73, s5.getElapsedTimeSeconds());
}
use of org.opentripplanner.routing.core.RoutingRequest 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.core.RoutingRequest 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.core.RoutingRequest 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());
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testTraverseMode.
public void testTraverseMode() throws Exception {
Vertex stop_a = graph.getVertex(feedId + ":A_depart");
Vertex stop_b = graph.getVertex(feedId + ":B_arrive");
ShortestPathTree spt;
RoutingRequest options = new RoutingRequest();
options.setModes(new TraverseModeSet("TRAM,RAIL,SUBWAY,FUNICULAR,GONDOLA"));
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 0, 0, 0, 0);
options.setRoutingContext(graph, stop_a, stop_b);
spt = aStar.getShortestPathTree(options);
// a to b is bus only
assertNull(spt.getPath(stop_b, false));
options.setModes(new TraverseModeSet("TRAM,RAIL,SUBWAY,FUNICULAR,GONDOLA,CABLE_CAR,BUS"));
spt = aStar.getShortestPathTree(options);
assertNotNull(spt.getPath(stop_b, false));
}
Aggregations