private void fixupTransitLeg(Leg leg, State state, TransitIndexService transitIndex) {
    Edge en = state.getBackEdge();
    leg.route = en.getName();
    Trip trip = state.getBackTrip();
    leg.headsign = state.getBackDirection();
    if (trip != null) {
      // this is the stop headsign
      // leg.headsign = "This is the headsign";
      // handle no stop headsign
      if (leg.headsign == null) leg.headsign = trip.getTripHeadsign();

      leg.tripId = trip.getId().getId();
      leg.agencyId = trip.getId().getAgencyId();
      leg.tripShortName = trip.getTripShortName();
      leg.routeShortName = trip.getRoute().getShortName();
      leg.routeLongName = trip.getRoute().getLongName();
      leg.routeColor = trip.getRoute().getColor();
      leg.routeTextColor = trip.getRoute().getTextColor();
      leg.routeId = trip.getRoute().getId().getId();
      if (transitIndex != null) {
        Agency agency = transitIndex.getAgency(leg.agencyId);
        leg.agencyName = agency.getName();
        leg.agencyUrl = agency.getUrl();
      }
    }
    leg.mode = state.getBackMode().toString();
    leg.startTime = makeCalendar(state.getBackState());
  }
Exemplo n.º 2
0
 private void fixupTransitLeg(Leg leg, State state, TransitIndexService transitIndex) {
   EdgeNarrative en = state.getBackEdgeNarrative();
   leg.route = en.getName();
   Trip trip = en.getTrip();
   if (trip != null) {
     leg.headsign = trip.getTripHeadsign();
     leg.tripId = trip.getId().getId();
     leg.agencyId = trip.getId().getAgencyId();
     leg.tripShortName = trip.getTripShortName();
     leg.routeShortName = trip.getRoute().getShortName();
     leg.routeLongName = trip.getRoute().getLongName();
     leg.routeColor = trip.getRoute().getColor();
     leg.routeTextColor = trip.getRoute().getTextColor();
     if (transitIndex != null) {
       Agency agency = transitIndex.getAgency(leg.agencyId);
       leg.agencyName = agency.getName();
       leg.agencyUrl = agency.getUrl();
     }
   }
   leg.mode = en.getMode().toString();
   leg.startTime = makeCalendar(state.getBackState());
 }
Exemplo n.º 3
0
  public State traverse(State state0) {
    RoutingContext rctx = state0.getContext();
    RoutingRequest options = state0.getOptions();
    Trip trip = pattern.getTrip();

    if (options.isArriveBy()) {
      /* reverse traversal, not so much to do */
      // do not alight immediately when arrive-depart dwell has been eliminated
      // this affects multi-itinerary searches
      if (state0.getBackEdge() instanceof TransitBoardAlight
          && !((TransitBoardAlight) state0.getBackEdge()).isBoarding()) {
        return null;
      }
      StateEditor s1 = state0.edit(this);
      int type = pattern.getBoardType(stopIndex);
      if (TransitUtils.handleBoardAlightType(s1, type)) {
        return null;
      }
      s1.setTripId(null);
      s1.setLastAlightedTime(state0.getTime());
      s1.setBackMode(TraverseMode.BOARDING);
      s1.setPreviousStop(fromv);
      return s1.makeState();
    } else {
      /* forward traversal: look for a transit trip on this pattern */
      if (!options.getModes().get(modeMask)) {
        return null;
      }
      /* find next boarding time */
      /*
       * check lists of transit serviceIds running yesterday, today, and tomorrow (relative to
       * initial state) if this pattern's serviceId is running look for the next boarding time
       * choose the soonest boarding time among trips starting yesterday, today, or tomorrow
       */
      long currentTime = state0.getTime();
      int bestWait = -1;
      TraverseMode mode = state0.getNonTransitMode();
      if (options.bannedTrips.containsKey(trip.getId())) {
        // see comment in FrequencyAlight for details
        return null;
      }
      for (ServiceDay sd : rctx.serviceDays) {
        int secondsSinceMidnight = sd.secondsSinceMidnight(currentTime);
        // only check for service on days that are not in the future
        // this avoids unnecessarily examining tomorrow's services
        if (secondsSinceMidnight < 0) continue;
        if (sd.serviceIdRunning(serviceId)) {
          int startTime =
              pattern.getNextDepartureTime(
                  stopIndex,
                  secondsSinceMidnight,
                  options.wheelchairAccessible,
                  mode == TraverseMode.BICYCLE,
                  true);
          if (startTime >= 0) {
            // a trip was found, wait will be non-negative

            int wait = (int) (sd.time(startTime) - currentTime);
            if (wait < 0) _log.error("negative wait time on board");
            if (bestWait < 0 || wait < bestWait) {
              // track the soonest departure over all relevant schedules
              bestWait = wait;
            }
          }
        }
      }
      if (bestWait < 0) {
        return null;
      }

      /* check if trip is banned for this plan */
      if (options.tripIsBanned(trip)) return null;

      /* check if route is preferred for this plan */
      long preferences_penalty = options.preferencesPenaltyForTrip(trip);

      StateEditor s1 = state0.edit(this);
      int type = pattern.getBoardType(stopIndex);
      if (TransitUtils.handleBoardAlightType(s1, type)) {
        return null;
      }
      s1.incrementTimeInSeconds(bestWait);
      s1.incrementNumBoardings();
      s1.setTripId(trip.getId());
      s1.setZone(pattern.getZone(stopIndex));
      s1.setRoute(trip.getRoute().getId());
      s1.setBackMode(TraverseMode.BOARDING);

      long wait_cost = bestWait;
      if (state0.getNumBoardings() == 0) {
        wait_cost *= options.waitAtBeginningFactor;
      } else {
        wait_cost *= options.waitReluctance;
      }
      s1.incrementWeight(preferences_penalty);
      s1.incrementWeight(wait_cost + options.getBoardCost(mode));
      return s1.makeState();
    }
  }
Exemplo n.º 4
0
 @Override
 public String getMessage() {
   return String.format(FMT, speed, distance, trip.getRoute().getId(), trip.getId(), seq);
 }