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());
}
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;
}
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;
}
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;
}
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();
}
Aggregations