use of com.graphhopper.gtfs.Request 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");
}
use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.
the class RealtimeIT method testSkipDepartureStop.
@Test
public void testSkipDepartureStop() {
// NADAV stop
final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
// NANAA stop
final double TO_LAT = 36.914944, TO_LON = -116.761472;
Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
// I want to go at 6:44
ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant());
// But the 6:00 departure of my line is going to skip my departure stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1").setTimestamp(ZonedDateTime.of(LocalDate.of(2007, 1, 1), LocalTime.of(0, 0), zoneId).toEpochSecond()));
feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(3).setScheduleRelationship(SKIPPED);
GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
ResponsePath possibleAlternative = response.getAll().stream().filter(a -> !a.isImpossible()).findFirst().get();
assertFalse(((Trip.PtLeg) possibleAlternative.getLegs().get(0)).stops.get(0).departureCancelled);
assertEquals(time(0, 35), possibleAlternative.getTime(), 0.1, "I have to wait half an hour for the next one (and ride 5 minutes)");
ResponsePath impossibleAlternative = response.getAll().stream().filter(a -> a.isImpossible()).findFirst().get();
assertTrue(impossibleAlternative.isImpossible());
assertTrue(((Trip.PtLeg) impossibleAlternative.getLegs().get(0)).stops.get(0).departureCancelled);
}
use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.
the class RealtimeIT method testDelayWithoutTransfer.
@Test
public void testDelayWithoutTransfer() {
// NADAV stop
final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
// NANAA stop
final double TO_LAT = 36.914944, TO_LON = -116.761472;
Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
// I want to go at 6:44
Instant initialTime = LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant();
ghRequest.setEarliestDepartureTime(initialTime);
ghRequest.setIgnoreTransfers(true);
// The 6:00 departure of my line is going to be late by 3 minutes
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(header());
feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(4).setScheduleRelationship(SCHEDULED).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(180).build());
GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
assertEquals(1, response.getAll().size());
assertEquals(time(0, 8), response.getBest().getLegs().get(response.getBest().getLegs().size() - 1).getArrivalTime().toInstant().toEpochMilli() - initialTime.toEpochMilli(), 0.1, "My line run is 3 minutes late.");
}
use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.
the class ExtendedRouteTypeIT method testRoute1.
@Test
public void testRoute1() {
final double FROM_LAT = 36.9010208, FROM_LON = -116.7659466;
final double TO_LAT = 36.9059371, TO_LON = -116.7618071;
Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 9, 0, 0).atZone(zoneId).toInstant());
ghRequest.setIgnoreTransfers(true);
GHResponse route = ptRouter.route(ghRequest);
assertFalse(route.hasErrors());
assertEquals(1, route.getAll().size());
assertEquals(time(1, 0), route.getBest().getTime(), 0.1, "Expected travel time == scheduled arrival time");
}
Aggregations