use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class EuclideanRemainingWeightHeuristic method initialize.
@Override
public void initialize(RoutingRequest options, long abortTime) {
RoutingRequest req = options;
Vertex target = req.rctx.target;
this.transit = req.modes.isTransit();
maxStreetSpeed = req.getStreetSpeedUpperBound();
maxTransitSpeed = req.getTransitSpeedUpperBound();
if (target.getDegreeIn() == 1) {
Edge edge = Iterables.getOnlyElement(target.getIncoming());
if (edge instanceof FreeEdge) {
target = edge.getFromVertex();
}
}
lat = target.getLat();
lon = target.getLon();
requiredWalkDistance = determineRequiredWalkDistance(req);
walkReluctance = req.walkReluctance;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class EuclideanRemainingWeightHeuristic method estimateRemainingWeight.
/**
* On a non-transit trip, the remaining weight is simply distance / street speed.
* On a transit trip, there are two cases:
* (1) we're not on a transit vehicle. In this case, there are two possible ways to compute
* the remaining distance, and we take whichever is smaller:
* (a) walking distance / walking speed
* (b) boarding cost + transit distance / transit speed (this is complicated a bit when
* we know that there is some walking portion of the trip).
* (2) we are on a transit vehicle, in which case the remaining weight is simply transit
* distance / transit speed (no need for boarding cost), again considering any mandatory
* walking.
*/
@Override
public double estimateRemainingWeight(State s) {
Vertex sv = s.getVertex();
double euclideanDistance = SphericalDistanceLibrary.fastDistance(sv.getLat(), sv.getLon(), lat, lon);
if (transit) {
if (euclideanDistance < requiredWalkDistance) {
return walkReluctance * euclideanDistance / maxStreetSpeed;
}
/* Due to the above conditional, the following value is known to be positive. */
double transitWeight = (euclideanDistance - requiredWalkDistance) / maxTransitSpeed;
double streetWeight = walkReluctance * (requiredWalkDistance / maxStreetSpeed);
return transitWeight + streetWeight;
} else {
// all travel is on-street, no transit involved
return walkReluctance * euclideanDistance / maxStreetSpeed;
}
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class MultiTargetTerminationStrategy method shouldSearchTerminate.
/**
* Updates the list of reached targets and returns True if all the
* targets have been reached.
*/
@Override
public boolean shouldSearchTerminate(Vertex origin, Vertex target, State current, ShortestPathTree spt, RoutingRequest traverseOptions) {
Vertex currentVertex = current.getVertex();
// but rather along edges in the graph.
if (unreachedTargets.contains(currentVertex)) {
unreachedTargets.remove(currentVertex);
reachedTargets.add(currentVertex);
}
return unreachedTargets.size() == 0;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class State method multipleOptionsBefore.
public boolean multipleOptionsBefore() {
boolean foundAlternatePaths = false;
TraverseMode requestedMode = getNonTransitMode();
for (Edge out : backState.vertex.getOutgoing()) {
if (out == backEdge) {
continue;
}
if (!(out instanceof StreetEdge)) {
continue;
}
State outState = out.traverse(backState);
if (outState == null) {
continue;
}
if (!outState.getBackMode().equals(requestedMode)) {
// walking a bike, so, not really an exit
continue;
}
// this section handles the case of an option which is only an option if you walk your
// bike. It is complicated because you will not need to walk your bike until one
// edge after the current edge.
// now, from here, try a continuing path.
Vertex tov = outState.getVertex();
boolean found = false;
for (Edge out2 : tov.getOutgoing()) {
State outState2 = out2.traverse(outState);
if (outState2 != null && !outState2.getBackMode().equals(requestedMode)) {
// walking a bike, so, not really an exit
continue;
}
found = true;
break;
}
if (!found) {
continue;
}
// there were paths we didn't take.
foundAlternatePaths = true;
break;
}
return foundAlternatePaths;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makeContours.
/**
* @return a map from contour (isochrone) thresholds in seconds to geometries.
*/
private Map<Integer, Geometry> makeContours() throws Exception {
Map<Vertex, Double> points = makePoints();
if (points == null || points.isEmpty()) {
LOG.error("No destinations were reachable.");
return null;
}
/* Set up transforms into projected coordinates (necessary for buffering in meters) */
/* We could avoid projection by equirectangular approximation */
CoordinateReferenceSystem wgs = DefaultGeographicCRS.WGS84;
CoordinateReferenceSystem crs = CRS.decode(crsCode);
MathTransform toMeters = CRS.findMathTransform(wgs, crs, false);
MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false);
GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();
/* One list of geometries for each contour */
Multimap<Integer, Geometry> bufferLists = ArrayListMultimap.create();
for (int c = 0; c < nContours; ++c) {
int thresholdSeconds = (c + 1) * contourSpacingMinutes * 60;
for (Map.Entry<Vertex, Double> vertexSeconds : points.entrySet()) {
double remainingSeconds = thresholdSeconds - vertexSeconds.getValue();
if (remainingSeconds > 60) {
// avoid degenerate geometries
double remainingMeters = remainingSeconds * request.walkSpeed;
Geometry point = geomf.createPoint(vertexSeconds.getKey().getCoordinate());
point = JTS.transform(point, toMeters);
Geometry buffer = point.buffer(remainingMeters);
bufferLists.put(thresholdSeconds, buffer);
}
}
}
/* Union the geometries at each contour threshold. */
Map<Integer, Geometry> contours = Maps.newHashMap();
for (Integer threshold : bufferLists.keys()) {
Collection<Geometry> buffers = bufferLists.get(threshold);
// make geometry collection
Geometry geom = geomf.buildGeometry(buffers);
// combine all individual buffers in this contour into one
geom = geom.union();
if (!resultsProjected)
geom = JTS.transform(geom, fromMeters);
contours.put(threshold, geom);
}
return contours;
}
Aggregations