use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class RentABikeAbstractEdge method traverseDropoff.
protected State traverseDropoff(State s0) {
RoutingRequest options = s0.getOptions();
/*
* To dropoff a bike, we need to have rented one.
*/
if (!s0.isBikeRenting() || !hasCompatibleNetworks(networks, s0.getBikeRentalNetworks()))
return null;
BikeRentalStationVertex pickup = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && pickup.getSpacesAvailable() == 0) {
return null;
}
StateEditor s1e = s0.edit(this);
s1e.incrementWeight(options.arriveBy ? options.bikeRentalPickupCost : options.bikeRentalDropoffCost);
s1e.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalPickupTime : options.bikeRentalDropoffTime);
s1e.setBikeRenting(false);
s1e.setBackMode(TraverseMode.WALK);
State s1 = s1e.makeState();
return s1;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class RentABikeAbstractEdge method traverseRent.
protected State traverseRent(State s0) {
RoutingRequest options = s0.getOptions();
/*
* If we already have a bike (rented or own) we won't go any faster by having a second one.
*/
if (!s0.getNonTransitMode().equals(TraverseMode.WALK))
return null;
/*
* To rent a bike, we need to have BICYCLE in allowed modes.
*/
if (!options.modes.contains(TraverseMode.BICYCLE))
return null;
BikeRentalStationVertex dropoff = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && dropoff.getBikesAvailable() == 0) {
return null;
}
StateEditor s1 = s0.edit(this);
s1.incrementWeight(options.arriveBy ? options.bikeRentalDropoffCost : options.bikeRentalPickupCost);
s1.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalDropoffTime : options.bikeRentalPickupTime);
s1.setBikeRenting(true);
s1.setBikeRentalNetwork(networks);
s1.setBackMode(s0.getNonTransitMode());
State s1b = s1.makeState();
return s1b;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class SPTWalker method walk.
/**
* Walk over a SPT. Call a visitor for each visited point.
*/
public void walk(SPTVisitor visitor, double d0) {
int nTotal = 0, nSkippedDupEdge = 0, nSkippedNoGeometry = 0;
Collection<? extends State> allStates = spt.getAllStates();
Set<Vertex> allVertices = new HashSet<Vertex>(spt.getVertexCount());
for (State s : allStates) {
allVertices.add(s.getVertex());
}
Set<Edge> processedEdges = new HashSet<Edge>(allVertices.size());
for (Vertex v : allVertices) {
State s0 = spt.getState(v);
if (s0 == null || !s0.isFinal())
continue;
for (Edge e : s0.getVertex().getIncoming()) {
// Take only street
if (e != null && visitor.accept(e)) {
State s1 = spt.getState(e.getFromVertex());
if (s1 == null || !s1.isFinal())
continue;
if (e.getFromVertex() != null && e.getToVertex() != null) {
// Hack alert: e.hashCode() throw NPE
if (processedEdges.contains(e)) {
nSkippedDupEdge++;
continue;
}
processedEdges.add(e);
}
Vertex vx0 = s0.getVertex();
Vertex vx1 = s1.getVertex();
LineString lineString = e.getGeometry();
if (lineString == null) {
nSkippedNoGeometry++;
continue;
}
// Compute speed along edge
double speedAlongEdge = spt.getOptions().walkSpeed;
if (e instanceof StreetEdge) {
StreetEdge se = (StreetEdge) e;
/*
* Compute effective speed, taking into account end state mode (car, bike,
* walk...) and edge properties (car max speed, slope, etc...)
*/
TraverseMode mode = s0.getNonTransitMode();
speedAlongEdge = se.calculateSpeed(spt.getOptions(), mode, s0.getTimeInMillis());
if (mode != TraverseMode.CAR)
speedAlongEdge = speedAlongEdge * se.getDistance() / se.getSlopeSpeedEffectiveLength();
double avgSpeed = se.getDistance() / Math.abs(s0.getTimeInMillis() - s1.getTimeInMillis()) * 1000;
if (avgSpeed < 1e-10)
avgSpeed = 1e-10;
/*
* We can't go faster than the average speed on the edge. We can go slower
* however, that simply means that one end vertice has a time higher than
* the other end vertice + time to traverse the edge (can happen due to
* max walk clamping).
*/
if (speedAlongEdge > avgSpeed)
speedAlongEdge = avgSpeed;
}
// Length of linestring
double lineStringLen = SphericalDistanceLibrary.fastLength(lineString);
visitor.visit(e, vx0.getCoordinate(), s0, s1, 0.0, lineStringLen, speedAlongEdge);
visitor.visit(e, vx1.getCoordinate(), s0, s1, lineStringLen, 0.0, speedAlongEdge);
nTotal += 2;
Coordinate[] pList = lineString.getCoordinates();
boolean reverse = vx1.getCoordinate().equals(pList[0]);
// Split the linestring in nSteps
if (lineStringLen > d0) {
// Number of steps
int nSteps = (int) Math.floor(lineStringLen / d0) + 1;
// Length of step
double stepLen = lineStringLen / nSteps;
// Distance at start of current seg
double startLen = 0;
// Distance cursor
double curLen = stepLen;
int ns = 1;
for (int i = 0; i < pList.length - 1; i++) {
Coordinate p0 = pList[i];
Coordinate p1 = pList[i + 1];
double segLen = SphericalDistanceLibrary.fastDistance(p0, p1);
while (curLen - startLen < segLen) {
double k = (curLen - startLen) / segLen;
Coordinate p = new Coordinate(p0.x * (1 - k) + p1.x * k, p0.y * (1 - k) + p1.y * k);
visitor.visit(e, p, reverse ? s1 : s0, reverse ? s0 : s1, curLen, lineStringLen - curLen, speedAlongEdge);
nTotal++;
curLen += stepLen;
ns++;
}
startLen += segLen;
if (ns >= nSteps)
break;
}
}
}
}
}
LOG.info("SPTWalker: Generated {} points ({} dup edges, {} no geometry) from {} vertices / {} states.", nTotal, nSkippedDupEdge, nSkippedNoGeometry, allVertices.size(), allStates.size());
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class MatchState method carsCanTraverse.
protected boolean carsCanTraverse(Edge edge) {
// should be done with a method on edge (canTraverse already exists on turnEdge)
State s0 = new State(edge.getFromVertex(), traverseOptions);
State s1 = edge.traverse(s0);
return s1 != null;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class GraphPath method dumpPathParser.
public void dumpPathParser() {
System.out.println(" --- BEGIN GRAPHPATH DUMP ---");
System.out.println(this.toString());
for (State s : states) System.out.println(s.getPathParserStates() + s + " via " + s.getBackEdge());
System.out.println(" --- END GRAPHPATH DUMP ---");
}
Aggregations