use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.
/**
* Compute a set of initial coordinates for the given SPT
*
* @param spt
* @return
*/
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
for (State s : spt.getAllStates()) {
Vertex v = s.getVertex();
// Take only street
if (v instanceof StreetVertex) {
retval.add(v.getCoordinate());
}
}
LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
return retval;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class SampleGridRenderer method sampleSPT.
/**
* Sample a SPT using a SPTWalker and an AccumulativeGridSampler.
*/
public static void sampleSPT(final ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double gridSizeMeters, final double offRoadDistanceMeters, final double offRoadWalkSpeedMps, final double maxWalkDistance, final int maxTimeSec, final double cosLat) {
AccumulativeMetric<WTWD> accMetric = new WTWDAccumulativeMetric(cosLat, offRoadDistanceMeters, offRoadWalkSpeedMps, gridSizeMeters);
final AccumulativeGridSampler<WTWD> gridSampler = new AccumulativeGridSampler<WTWD>(sampleGrid, accMetric);
// At which distance we split edges along the geometry during sampling.
// For best results, this should be slighly lower than the grid size.
double walkerSplitDistanceMeters = gridSizeMeters * 0.5;
SPTWalker johnny = new SPTWalker(spt);
johnny.walk(new SPTVisitor() {
@Override
public final boolean accept(Edge e) {
return e instanceof StreetEdge;
}
@Override
public final void visit(Edge e, Coordinate c, State s0, State s1, double d0, double d1, double speedAlongEdge) {
double wd0 = s0.getWalkDistance() + d0;
double wd1 = s0.getWalkDistance() + d1;
double t0 = wd0 > maxWalkDistance ? Double.POSITIVE_INFINITY : s0.getActiveTime() + d0 / speedAlongEdge;
double t1 = wd1 > maxWalkDistance ? Double.POSITIVE_INFINITY : s1.getActiveTime() + d1 / speedAlongEdge;
if (t0 < maxTimeSec || t1 < maxTimeSec) {
if (!Double.isInfinite(t0) || !Double.isInfinite(t1)) {
WTWD z = new WTWD();
z.w = 1.0;
z.d = 0.0;
if (t0 < t1) {
z.wTime = t0;
z.wBoardings = s0.getNumBoardings();
z.wWalkDist = s0.getWalkDistance() + d0;
} else {
z.wTime = t1;
z.wBoardings = s1.getNumBoardings();
z.wWalkDist = s1.getWalkDistance() + d1;
}
gridSampler.addSamplingPoint(c, z, offRoadWalkSpeedMps);
}
}
}
}, walkerSplitDistanceMeters);
gridSampler.close();
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class Sample method eval.
/**
* @param spt the ShortestPathTree with respect to which this sample will be evaluated
* @return the travel time to reach this Sample point from the SPT's origin
*/
public long eval(ShortestPathTree spt) {
State s0 = spt.getState(v0);
State s1 = spt.getState(v1);
long m0 = Long.MAX_VALUE;
long m1 = Long.MAX_VALUE;
double walkSpeed = spt.getOptions().walkSpeed;
if (s0 != null)
m0 = (int) (s0.getActiveTime() + d0 / walkSpeed);
if (s1 != null)
m1 = (int) (s1.getActiveTime() + d1 / walkSpeed);
return (m0 < m1) ? m0 : m1;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class Sample method evalWalkDistance.
public double evalWalkDistance(ShortestPathTree spt) {
State s0 = spt.getState(v0);
State s1 = spt.getState(v1);
double m0 = Double.NaN;
double m1 = Double.NaN;
if (s0 != null)
m0 = (s0.getWalkDistance() + d0);
if (s1 != null)
m1 = (s1.getWalkDistance() + d1);
return (m0 < m1) ? m0 : m1;
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class DefaultFareServiceImpl method createRides.
protected List<Ride> createRides(GraphPath path) {
List<Ride> rides = new LinkedList<Ride>();
Ride ride = null;
for (State state : path.states) {
Edge edge = state.getBackEdge();
if (!(edge instanceof HopEdge))
continue;
HopEdge hEdge = (HopEdge) edge;
if (ride == null || !state.getRoute().equals(ride.route)) {
ride = new Ride();
rides.add(ride);
ride.startZone = hEdge.getBeginStop().getZoneId();
ride.zones.add(ride.startZone);
ride.agency = state.getBackTrip().getRoute().getAgency().getId();
ride.route = state.getRoute();
ride.startTime = state.getBackState().getTimeSeconds();
ride.firstStop = hEdge.getBeginStop();
ride.trip = state.getTripId();
}
ride.lastStop = hEdge.getEndStop();
ride.endZone = ride.lastStop.getZoneId();
ride.zones.add(ride.endZone);
ride.endTime = state.getTimeSeconds();
// in default fare service, classify rides by mode
ride.classifier = state.getBackMode();
}
return rides;
}
Aggregations