Search in sources :

Example 1 with Request

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

the class PtRouteResource method route.

@GET
@Produces(MediaType.APPLICATION_JSON)
public ObjectNode route(@QueryParam("point") @Size(min = 2, max = 2) List<GHLocationParam> requestPoints, @QueryParam("pt.earliest_departure_time") @NotNull OffsetDateTimeParam departureTimeParam, @QueryParam("pt.profile_duration") DurationParam profileDuration, @QueryParam("pt.arrive_by") @DefaultValue("false") boolean arriveBy, @QueryParam("locale") String localeStr, @QueryParam("pt.ignore_transfers") Boolean ignoreTransfers, @QueryParam("pt.profile") Boolean profileQuery, @QueryParam("pt.limit_solutions") Integer limitSolutions, @QueryParam("pt.limit_trip_time") DurationParam limitTripTime, @QueryParam("pt.limit_street_time") DurationParam limitStreetTime, @QueryParam("pt.access_profile") String accessProfile, @QueryParam("pt.egress_profile") String egressProfile) {
    StopWatch stopWatch = new StopWatch().start();
    List<GHLocation> points = requestPoints.stream().map(AbstractParam::get).collect(toList());
    Instant departureTime = departureTimeParam.get().toInstant();
    Request request = new Request(points, departureTime);
    request.setArriveBy(arriveBy);
    Optional.ofNullable(profileQuery).ifPresent(request::setProfileQuery);
    Optional.ofNullable(profileDuration.get()).ifPresent(request::setMaxProfileDuration);
    Optional.ofNullable(ignoreTransfers).ifPresent(request::setIgnoreTransfers);
    Optional.ofNullable(localeStr).ifPresent(s -> request.setLocale(Helper.getLocale(s)));
    Optional.ofNullable(limitSolutions).ifPresent(request::setLimitSolutions);
    Optional.ofNullable(limitTripTime.get()).ifPresent(request::setLimitTripTime);
    Optional.ofNullable(limitStreetTime.get()).ifPresent(request::setLimitStreetTime);
    Optional.ofNullable(accessProfile).ifPresent(request::setAccessProfile);
    Optional.ofNullable(egressProfile).ifPresent(request::setEgressProfile);
    GHResponse route = ptRouter.route(request);
    return ResponsePathSerializer.jsonObject(route, true, true, false, false, stopWatch.stop().getMillis());
}
Also used : GHLocation(com.graphhopper.gtfs.GHLocation) Instant(java.time.Instant) Request(com.graphhopper.gtfs.Request) GHResponse(com.graphhopper.GHResponse) StopWatch(com.graphhopper.util.StopWatch)

Example 2 with Request

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

the class RealtimeIT method testExtraTripWorksOnlyOnSpecifiedDay.

@Test
public void testExtraTripWorksOnlyOnSpecifiedDay() {
    // 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:45, but tomorrow
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 2, 6, 45).atZone(zoneId).toInstant());
    ghRequest.setIgnoreTransfers(true);
    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()));
    // Today, there is an extra trip right at 6:45, but that doesn't concern me.
    final GtfsRealtime.TripUpdate.Builder extraTripUpdate = feedMessageBuilder.addEntityBuilder().setId("2").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setScheduleRelationship(ADDED).setTripId("EXTRA").setRouteId("CITY").setStartTime("06:45:00"));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(1).setStopId("NADAV").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).atZone(zoneId).toEpochSecond()));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(2).setStopId("BEATTY_AIRPORT").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()));
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(1, response.getAll().size());
    assertEquals(time(1, 5), response.getBest().getTime(), 0.1, "There is an extra trip at 6:45 tomorrow, but that doesn't concern me today.");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 3 with Request

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

the class RealtimeIT method testSkipTransferStop.

@Test
public void testSkipTransferStop() {
    // 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 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);
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(2, response.getAll().size());
    assertEquals(time(1, 6), response.getBest().getTime(), 0.1, "The 6: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());
    assertTrue(((Trip.PtLeg) impossibleAlternative.getLegs().get(0)).stops.get(2).departureCancelled);
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 4 with Request

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

the class RealtimeIT method testMissedTransferBecauseOfDelay.

@Test
public void testMissedTransferBecauseOfDelay() {
    // 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());
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(2, response.getAll().size());
    assertEquals(time(1, 6), response.getBest().getTime(), 0.1, "The 6:44 bus will be late 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");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 5 with Request

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

the class RealtimeIT method testBlockTripSkipsStop.

@Test
public void testBlockTripSkipsStop() {
    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("AB1")).addStopTimeUpdateBuilder().setStopSequence(2).setScheduleRelationship(SKIPPED);
    // 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());
    GHResponse route = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertFalse(route.hasErrors());
    assertTrue(route.getAll().get(route.getAll().size() - 1).isImpossible());
    // Note that my stop (BULLFROG), which is skipped, is a switch of "block legs", so even though it looks like I (impossibly) transfer there,
    // this is not a real transfer. The bus drives through BULLFROG without stopping.
    // Very untypical example, but seems correct.
    Trip.PtLeg ptLeg = (Trip.PtLeg) route.getBest().getLegs().get(3);
    assertEquals(LocalDateTime.parse("2007-01-01T12:00:00").atZone(zoneId).toInstant(), ptLeg.stops.get(ptLeg.stops.size() - 1).plannedArrivalTime.toInstant(), "I have to continue on AB1 which skips my stop, go all the way to the end, and ride back.");
    assertEquals("BFC2", ptLeg.trip_id, "Using expected route");
}
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