use of com.graphhopper.gtfs.PtRouter in project graphhopper by graphhopper.
the class RealtimeIT method testMissedTransferBecauseOfDelayBackwards.
// TODO: Similar case, but where I need a new transfer edge for it to work
// TODO: Similar case, but where the departure of the second leg is later than all other departures on that day.
@Test
public void testMissedTransferBecauseOfDelayBackwards() {
// NADAV stop
final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
// BEATTY_AIRPORT stop
final double TO_LAT = 36.868446, TO_LON = -116.784582;
Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
// I want to be there at 7:20
ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 8, 20).atZone(zoneId).toInstant());
ghRequest.setArriveBy(true);
// But the 6:00 departure of my line is going to skip my transfer stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(header());
feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("07:00:00")).addStopTimeUpdateBuilder().setStopSequence(5).setScheduleRelationship(SCHEDULED).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(300).build());
PtRouter graphHopper = graphHopperFactory.createWith(feedMessageBuilder.build());
GHResponse response = graphHopper.route(ghRequest);
assertEquals(2, response.getAll().size());
assertEquals(time(1, 6), response.getBest().getTime(), 0.1, "The 7:44 bus will not call at STAGECOACH, so I will be 30 min late at the airport.");
ResponsePath impossibleAlternative = response.getAll().get(1);
assertTrue(impossibleAlternative.isImpossible());
Trip.Stop delayedStop = ((Trip.PtLeg) impossibleAlternative.getLegs().get(0)).stops.get(2);
assertEquals(300, Duration.between(delayedStop.plannedArrivalTime.toInstant(), delayedStop.predictedArrivalTime.toInstant()).getSeconds(), "Five minutes late");
// But when I ask about tomorrow, it works as planned
ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 2, 8, 20).atZone(zoneId).toInstant());
response = graphHopper.route(ghRequest);
assertEquals(1, response.getAll().size());
Trip.Stop notDelayedStop = ((Trip.PtLeg) response.getBest().getLegs().get(0)).stops.get(2);
assertNull(notDelayedStop.predictedArrivalTime, "Not late");
}
use of com.graphhopper.gtfs.PtRouter in project graphhopper by graphhopper.
the class RealtimeIT method testDelayAtEndForNonFrequencyBasedTrip.
@Test
public void testDelayAtEndForNonFrequencyBasedTrip() {
// STAGECOACH stop
final double FROM_LAT = 36.915682, FROM_LON = -116.751677;
// BULLFROG stop
final double TO_LAT = 36.88108, TO_LON = -116.81797;
Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 0, 0).atZone(zoneId).toInstant());
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(header());
feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("AB1")).addStopTimeUpdateBuilder().setStopSequence(2).setScheduleRelationship(SCHEDULED).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(300).build());
PtRouter graphHopper = graphHopperFactory.createWith(feedMessageBuilder.build());
GHResponse route = graphHopper.route(ghRequest);
assertFalse(route.hasErrors());
assertFalse(route.getAll().isEmpty());
assertEquals(time(8, 15), route.getBest().getTime(), 0.1, "Travel time == predicted travel time");
assertEquals("STBA", (((Trip.PtLeg) route.getBest().getLegs().get(0)).trip_id), "Using expected route");
assertEquals("AB1", (((Trip.PtLeg) route.getBest().getLegs().get(1)).trip_id), "Using expected route");
assertEquals(LocalTime.parse("08:15"), LocalTime.from(((Trip.PtLeg) route.getBest().getLegs().get(1)).stops.get(1).predictedArrivalTime.toInstant().atZone(zoneId)), "Delay at destination");
// Two legs, no transfers allowed. Need two 'p' tickets costing 125 cents each.
assertEquals(250, route.getBest().getFare().multiply(BigDecimal.valueOf(100)).intValue(), "Paid expected fare");
}