Search in sources :

Example 6 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testMissedTransferButExtraTripOnSecondLeg.

@Test
public void testMissedTransferButExtraTripOnSecondLeg() {
    // 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 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 be 5 minutes late at 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("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(5).setScheduleRelationship(SCHEDULED).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(300).build());
    final GtfsRealtime.TripUpdate.Builder extraTripUpdate = feedMessageBuilder.addEntityBuilder().setId("2").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setScheduleRelationship(ADDED).setTripId("EXTRA").setRouteId("STBA").setStartTime("06:45:00"));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(1).setStopId("STAGECOACH").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 15).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 15).atZone(zoneId).toEpochSecond()));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(2).setStopId("BEATTY_AIRPORT").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 20).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 20).atZone(zoneId).toEpochSecond()));
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    // assertEquals(2, response.getAll().size());
    assertEquals(time(0, 36), response.getBest().getTime(), 0.1, "The 6:44 bus will be late at STAGECOACH, but I won't be late because there's an extra trip.");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 7 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testHeavyDelayWhereWeShouldTakeOtherTripInstead.

@Test
public void testHeavyDelayWhereWeShouldTakeOtherTripInstead() {
    // 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 be super-late :-(
    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().setScheduleRelationship(SCHEDULED).setStopSequence(3).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(3600).build());
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(2, response.getAll().size());
    ResponsePath best = response.getBest();
    Trip.PtLeg bestPtLeg = (Trip.PtLeg) best.getLegs().get(0);
    assertEquals(LocalDateTime.parse("2007-01-01T07:19:00").atZone(zoneId).toInstant(), bestPtLeg.stops.get(bestPtLeg.stops.size() - 1).plannedArrivalTime.toInstant(), "It's better to wait half an hour for the next one (and ride 5 minutes).");
    assertNull(bestPtLeg.stops.get(bestPtLeg.stops.size() - 1).predictedArrivalTime, "There is no predicted arrival time.");
    ResponsePath impossibleAlternative = response.getAll().get(1);
    assertTrue(impossibleAlternative.isImpossible());
    Trip.PtLeg impossiblePtLeg = (Trip.PtLeg) impossibleAlternative.getLegs().get(0);
    assertEquals(LocalDateTime.parse("2007-01-01T06:49:00").atZone(zoneId).toInstant(), impossiblePtLeg.stops.get(impossiblePtLeg.stops.size() - 1).plannedArrivalTime.toInstant(), "The impossible alternative is my planned 5-minute-trip");
    assertEquals(LocalDateTime.parse("2007-01-01T07:49:00").atZone(zoneId).toInstant(), impossiblePtLeg.stops.get(impossiblePtLeg.stops.size() - 1).predictedArrivalTime.toInstant(), "..which is very late today");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 8 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testExtraTrip.

@Test
public void testExtraTrip() {
    // 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 go at 6:44
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant());
    ghRequest.setIgnoreTransfers(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(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(5).setScheduleRelationship(SKIPPED);
    // Add a few more trips (but we only need the first one; add more because there used to be a bug with something like an index overflow)
    for (int i = 0; i < 1; i++) {
        final GtfsRealtime.TripUpdate.Builder extraTripUpdate = feedMessageBuilder.addEntityBuilder().setId("2").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setScheduleRelationship(ADDED).setTripId("EXTRA" + i).setRouteId("CITY").setStartTime("06:45:0" + i));
        extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(1).setStopId("NADAV").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).plusMinutes(i).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).plusMinutes(i).atZone(zoneId).toEpochSecond()));
        extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(2).setStopId("BEATTY_AIRPORT").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 15).plusMinutes(i).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 7, 15).plusMinutes(i).atZone(zoneId).toEpochSecond()));
    }
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(1, response.getAll().size());
    assertEquals(time(0, 31), response.getBest().getTime(), 0.1, "Luckily, there is an extra service directly from my stop to the airport, at 6:45, taking 30 minutes");
    ResponsePath solution = response.getAll().get(0);
    Trip.PtLeg ptLeg = ((Trip.PtLeg) solution.getLegs().stream().filter(leg -> leg instanceof Trip.PtLeg).findFirst().get());
    assertEquals("EXTRA0", ptLeg.trip_id);
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 9 with Request

use of com.graphhopper.gtfs.Request 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");
}
Also used : Request(com.graphhopper.gtfs.Request) PtRouter(com.graphhopper.gtfs.PtRouter) Test(org.junit.jupiter.api.Test)

Example 10 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testBlockTrips.

@Test
public void testBlockTrips() {
    // BEATTY_AIRPORT stop
    final double FROM_LAT = 36.868446, FROM_LON = -116.784582;
    // FUR_CREEK_RES stop
    final double TO_LAT = 36.425288, TO_LON = -117.133162;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 8, 0).atZone(zoneId).toInstant());
    ghRequest.setIgnoreTransfers(true);
    // My line does not stop at Bullfrog today. If this was a real transfer, I would not be
    // able to change lines there. But it is not a real transfer, so I can go on as planned.
    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(SKIPPED);
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals("AB1", (((Trip.PtLeg) response.getBest().getLegs().get(0)).trip_id), "I can still use the AB1 trip");
    assertEquals(time(1, 20), response.getBest().getTime(), "It takes");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Aggregations

Request (com.graphhopper.gtfs.Request)19 Test (org.junit.jupiter.api.Test)18 PtRouter (com.graphhopper.gtfs.PtRouter)2 GHResponse (com.graphhopper.GHResponse)1 GHLocation (com.graphhopper.gtfs.GHLocation)1 StopWatch (com.graphhopper.util.StopWatch)1 Instant (java.time.Instant)1