Search in sources :

Example 61 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class GraphPath method dump.

/**
 **
 * Private Methods
 ***
 */
public void dump() {
    System.out.println(" --- BEGIN GRAPHPATH DUMP ---");
    System.out.println(this.toString());
    for (State s : states) {
        // System.out.println(s.getBackEdge() + " leads to " + s);
        if (s.getBackEdge() != null) {
            System.out.println(s.getBackEdge().getClass().getSimpleName() + " --> " + s.getVertex().getClass().getSimpleName());
            System.out.println("  " + s.weight);
        }
    }
    System.out.println(" --- END GRAPHPATH DUMP ---");
    System.out.println("Total meters walked in the preceding graphpath: " + states.getLast().getWalkDistance());
}
Also used : State(org.opentripplanner.routing.core.State)

Example 62 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class ShortestPathTree method getState.

/**
 * Returns the 'best' state for the given Vertex, where 'best' depends on the implementation.
 *
 * @param dest the vertex of interest
 * @return a 'best' state at that vertex
 */
public State getState(Vertex dest) {
    Collection<State> states = stateSets.get(dest);
    if (states == null)
        return null;
    State ret = null;
    // TODO are we only checking path parser acceptance when we fetch states via this specific method?
    for (State s : states) {
        if ((ret == null || s.weight < ret.weight) && s.isFinal()) {
            ret = s;
        }
    }
    return ret;
}
Also used : State(org.opentripplanner.routing.core.State)

Example 63 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class ShortestPathTree method getPaths.

/**
 * @return a list of GraphPaths, sometimes empty but never null.
 */
public List<GraphPath> getPaths(Vertex dest, boolean optimize) {
    List<? extends State> stateList = getStates(dest);
    if (stateList == null)
        return Collections.emptyList();
    List<GraphPath> ret = new LinkedList<GraphPath>();
    for (State s : stateList) {
        if (s.isFinal()) {
            ret.add(new GraphPath(s, optimize));
        }
    }
    return ret;
}
Also used : State(org.opentripplanner.routing.core.State)

Example 64 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class ShortestPathTree method add.

/**
 * The add method checks a new State to see if it is non-dominated and thus worth visiting
 * later. If so, the method returns 'true' indicating that the state is deemed useful and should
 * be enqueued for later exploration. The method will also perform implementation-specific
 * actions that track dominant or optimal states.
 *
 * @param newState the State to add to the SPT, if it is deemed non-dominated
 * @return a boolean value indicating whether the state was added to the tree and should
 *          therefore be enqueued
 */
public boolean add(State newState) {
    Vertex vertex = newState.getVertex();
    List<State> states = stateSets.get(vertex);
    // if the vertex has no states, add one and return
    if (states == null) {
        states = new ArrayList<>();
        stateSets.put(vertex, states);
        states.add(newState);
        return true;
    }
    // if the vertex has any states that dominate the new state, don't add the state
    // if the new state dominates any old states, remove them
    Iterator<State> it = states.iterator();
    while (it.hasNext()) {
        State oldState = it.next();
        // we want to reject the new state
        if (dominanceFunction.betterOrEqualAndComparable(oldState, newState))
            return false;
        if (dominanceFunction.betterOrEqualAndComparable(newState, oldState))
            it.remove();
    }
    // any states remaining are co-dominant with the new state
    states.add(newState);
    return true;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) State(org.opentripplanner.routing.core.State)

Example 65 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetSplittingAlerts.

/**
 * Test that alerts on split streets are preserved, i.e. if there are alerts on the street that is split the same alerts should be present on the
 * new street.
 */
@Test
public void testStreetSplittingAlerts() {
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    Alert alert = Alert.createSimpleAlerts("This is the alert");
    Set<Alert> alerts = new HashSet<>();
    alerts.add(alert);
    graph.streetNotesService.addStaticNote(left, alert, StreetNotesService.ALWAYS_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, alert, StreetNotesService.ALWAYS_MATCHER);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    // The alert should be preserved
    // traverse the FreeEdge from the StreetLocation to the new IntersectionVertex
    RoutingRequest req = new RoutingRequest();
    req.setMaxWalkDistance(Double.MAX_VALUE);
    State traversedOne = new State(start, req);
    State currentState;
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(alerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    // now, make sure wheelchair alerts are preserved
    Alert wheelchairAlert = Alert.createSimpleAlerts("This is the wheelchair alert");
    Set<Alert> wheelchairAlerts = new HashSet<>();
    wheelchairAlerts.add(wheelchairAlert);
    graph.streetNotesService.removeStaticNotes(left);
    graph.streetNotesService.removeStaticNotes(leftBack);
    graph.streetNotesService.addStaticNote(left, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    req.setWheelchairAccessible(true);
    start.dispose();
    start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    traversedOne = new State(start, req);
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(wheelchairAlerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    start.dispose();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Alert(org.opentripplanner.routing.alertpatch.Alert) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5