Package org.opentripplanner.routing.core

Examples of org.opentripplanner.routing.core.State


    TPQueryData queryData = options.getExtension(TPQueryData.class);

    List<StopEntry> destStops = queryData.getDestStops();

    State results = null;

    TransferParent transfers = tpService.getTransferPatternsForStops(
        queryData.getTransferPatternData(), _stop, destStops);

    for (TransferNode tree : transfers.getTransfers()) {

      TPState pathState = TPState.start(queryData, tree);

      Vertex fromVertex = new WalkToStopVertex(_context, _stop);
      Vertex toVertex = new TPDepartureVertex(_context, pathState);
      EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);

      StateEditor edit = s0.edit(this, narrative);
      edit.incrementTimeInSeconds(options.minTransferTime);

      double w = options.minTransferTime * options.waitAtBeginningFactor;
      edit.incrementWeight(w);

      State r = edit.makeState();
      results = r.addToExistingResultChain(results);
    }

    return results;
  }
View Full Code Here


    return s0.edit(this, narrative).makeState();
  }

  private State traverseReverse(State s0) {

    State results = null;

    long time = s0.getTime();
    TraverseOptions options = s0.getOptions();

    /**
     * Look for arrivals in the previous X minutes
     */
    long timeFrom = SupportLibrary.getPreviousTimeWindow(_context, time);
    long timeTo = time;

    List<ArrivalAndDepartureInstance> arrivals = getArrivalsInTimeRange(time,
        timeFrom, timeTo, options);

    for (ArrivalAndDepartureInstance instance : arrivals) {

      long arrivalTime = instance.getBestArrivalTime();

      // Prune anything that doesn't have an arrival time in the proper range,
      // since the stopTimeService method will also return instances that depart
      // in the target interval as well
      if (arrivalTime < timeFrom || time <= arrivalTime)
        continue;

      Vertex fromVertex = new BlockArrivalVertex(_context, instance);
      Vertex toVertex = new ArrivalVertex(_context, _stop, s0.getTime());
      EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);

      OBAStateEditor edit = (OBAStateEditor) s0.edit(this, narrative);

      int dwellTime = (int) ((time - arrivalTime) / 1000);

      edit.setTime(arrivalTime);
      edit.incrementNumBoardings();
      edit.setEverBoarded(true);

      if (s0.getNumBoardings() == 0)
        edit.incrementInitialWaitTime(dwellTime * 1000);

      double w = ItineraryWeightingLibrary.computeWeightForWait(s0, dwellTime);
      edit.incrementWeight(w);

      State r = edit.makeState();
      results = r.addToExistingResultChain(results);
    }

    // In addition to all the departures, we can just remain waiting at the stop
    int dwellTime = (int) ((time - timeFrom) / 1000);
    double w = ItineraryWeightingLibrary.computeWeightForWait(s0, dwellTime);

    Vertex fromVertex = new ArrivalVertex(_context, _stop, timeFrom);
    Vertex toVertex = new ArrivalVertex(_context, _stop, s0.getTime());
    EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);

    OBAStateEditor edit = (OBAStateEditor) s0.edit(this, narrative);

    edit.incrementWeight(w);
    edit.setTime(time);

    if (s0.getNumBoardings() == 0)
      edit.incrementInitialWaitTime(dwellTime * 1000);

    State r = edit.makeState();
    results = r.addToExistingResultChain(results);

    return results;
  }
View Full Code Here

        return true;

      if (byTripSequence.getItineraryCount() >= opts.numItineraries)
        return false;

      State minVertex = getMinVertex(byTripSequence.getStates().values());

      if (current.getWeight() > minVertex.getWeight() * 1.5)
        return false;
    }

    return true;
  }
View Full Code Here

    return true;
  }

  private State getMinVertex(Iterable<OBAState> states) {

    State minVertex = null;
    double minWeight = Double.POSITIVE_INFINITY;

    for (OBAState state : states) {
      if (state.isLookaheadItinerary())
        continue;
View Full Code Here

    applyConstraintsToOptions(constraints.getConstraints(), options);

    Coordinate c = new Coordinate(location.getLon(), location.getLat());
    Vertex origin = _streetVertexIndexService.getClosestVertex(c, options);

    State originState = new OBAState(time, origin, options);
    BasicShortestPathTree tree = _transitShedPathService.getTransitShed(origin,
        originState, options);

    Map<StopEntry, Long> results = new HashMap<StopEntry, Long>();
View Full Code Here

  private ItineraryBean getPathAsItinerary(GraphPath path,
      OBATraverseOptions options) {

    ItineraryBean itinerary = new ItineraryBean();

    State startState = path.states.getFirst();
    State endState = path.states.getLast();

    itinerary.setStartTime(startState.getTime());
    itinerary.setEndTime(endState.getTime());

    List<LegBean> legs = new ArrayList<LegBean>();
    itinerary.setLegs(legs);

    /**
     * We set the current state index to 1, skipping the first state, since it
     * has no back edge
     */
    List<State> states = new ArrayList<State>(path.states);
    int currentIndex = 1;

    while (currentIndex < states.size()) {

      State state = states.get(currentIndex);
      EdgeNarrative edgeNarrative = state.getBackEdgeNarrative();

      TraverseMode mode = edgeNarrative.getMode();

      if (mode.isTransit()) {
        currentIndex = extendTransitLeg(states, currentIndex, options, legs);
View Full Code Here

    TransitLegBuilder builder = new TransitLegBuilder();

    while (currentIndex < states.size()) {

      State state = states.get(currentIndex);
      Edge edge = state.getBackEdge();
      EdgeNarrative narrative = state.getBackEdgeNarrative();
      TraverseMode mode = narrative.getMode();

      if (!mode.isTransit())
        break;
View Full Code Here

    List<State> streetStates = new ArrayList<State>();

    while (currentIndex < states.size()) {

      State state = states.get(currentIndex);
      EdgeNarrative narrative = state.getBackEdgeNarrative();
      TraverseMode edgeMode = narrative.getMode();

      if (mode != edgeMode)
        break;
View Full Code Here

    OBATraverseOptions obaOpts = (OBATraverseOptions) s0.getOptions();
    if (obaOpts.extraSpecialMode)
      return getNextScheduledBlockDepartureResults(s0);

    State results = null;

    long time = s0.getTime();

    /**
     * Look for departures in the next X minutes
     */
    long fromTime = time;
    long toTime = SupportLibrary.getNextTimeWindow(_context, time);

    List<ArrivalAndDepartureInstance> departures = getDeparturesInTimeRange(s0,
        fromTime, toTime);

    for (ArrivalAndDepartureInstance instance : departures) {

      long departureTime = instance.getBestDepartureTime();

      /**
       * Prune anything that doesn't have a departure in the proper range, since
       * the arrivals and departures method will also return instances that
       * arrive in the target interval as well
       */
      if (departureTime < time || toTime <= departureTime)
        continue;

      // If this is the last stop time in the block, don't continue
      if (!SupportLibrary.hasNextStopTime(instance))
        continue;

      State r = getDepartureAsTraverseResult(instance, s0);
      results = r.addToExistingResultChain(results);
    }

    // In addition to all the departures, we can just remain waiting at the stop
    DepartureVertex fromVertex = new DepartureVertex(_context, _stop,
        s0.getTime());
    DepartureVertex toVertex = new DepartureVertex(_context, _stop, toTime);
    EdgeNarrative narrative = narrative(s0, fromVertex, toVertex);

    OBAStateEditor edit = (OBAStateEditor) s0.edit(this, narrative);
    edit.setTime(toTime);

    int dwellTime = (int) ((toTime - time) / 1000);
    double w = ItineraryWeightingLibrary.computeWeightForWait(s0, dwellTime);
    edit.incrementWeight(w);

    if (s0.getNumBoardings() == 0)
      edit.incrementInitialWaitTime(dwellTime * 1000);

    State r = edit.makeState();
    results = r.addToExistingResultChain(results);

    return results;
  }
View Full Code Here

    ArrivalAndDepartureService arrivalAndDepartureService = _context.getArrivalAndDepartureService();

    List<ArrivalAndDepartureInstance> instances = arrivalAndDepartureService.getNextScheduledBlockTripDeparturesForStop(
        _stop, s0.getTime(), false);

    State results = null;

    for (ArrivalAndDepartureInstance instance : instances) {
      State r = getDepartureAsTraverseResult(instance, s0);
      results = r.addToExistingResultChain(results);
    }

    return results;
  }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.core.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.