Skip to content

Commit

Permalink
avoid unnecessarily copying Vertex->int maps
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Jan 28, 2015
1 parent 23997a3 commit 7ef10d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
27 changes: 0 additions & 27 deletions src/main/java/org/opentripplanner/analyst/TimeSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,6 @@ public static TimeSurface.RangeSet makeSurfaces (AnalystProfileRouterPrototype p
return result;
}

// FIXME wait this is copying ObjectInt maps two times, just make the surfaces directly when propagating!
public static RangeSet makeSurfaces(ProfileRouter profileRouter, TObjectIntMap<Vertex> lbs, TObjectIntMap<Vertex> ubs) {
TimeSurface minSurface = new TimeSurface(profileRouter);
TimeSurface avgSurface = new TimeSurface(profileRouter);
TimeSurface maxSurface = new TimeSurface(profileRouter);
for (Vertex v : lbs.keySet()) {
int min = lbs.get(v);
int max = ubs.get(v);
int avg = UNREACHABLE;
if (min != UNREACHABLE && max != UNREACHABLE) {
avg = (int)(((long)min + max) / 2); // FIXME HACK
}
minSurface.times.put(v, min);
avgSurface.times.put(v, avg);
maxSurface.times.put(v, max);
}
// TODO merge with the version that takes AnalystProfileRouterPrototype, they are mostly the same.
RangeSet result = new RangeSet();
minSurface.description = "Travel times assuming best luck (never waiting for a transfer).";
avgSurface.description = "Expected travel times (average wait for every transfer).";
maxSurface.description = "Travel times assuming worst luck (maximum wait for every transfer).";
result.min = minSurface;
result.avg = avgSurface;
result.max = maxSurface;
return result;
}

/** Groups together three TimeSurfaces as a single response for profile-analyst. */
public static class RangeSet {
public TimeSurface min;
Expand Down
35 changes: 23 additions & 12 deletions src/main/java/org/opentripplanner/profile/ProfileRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,9 @@ public void finalize() {
private void makeSurfaces() {
LOG.info("Propagating from transit stops to the street network...");
// A map to store the travel time to each vertex
TObjectIntMap<Vertex> lbs = new TObjectIntHashMap<>(1000000, 0.5f, TimeSurface.UNREACHABLE);
TObjectIntMap<Vertex> ubs = new TObjectIntHashMap<>(1000000, 0.5f, TimeSurface.UNREACHABLE);
TimeSurface minSurface = new TimeSurface(this);
TimeSurface avgSurface = new TimeSurface(this);
TimeSurface maxSurface = new TimeSurface(this);
// Grab a cached map of distances to street intersections from each transit stop
StopTreeCache stopTreeCache = graph.index.getStopTreeCache();
// Iterate over all nondominated rides at all clusters
Expand All @@ -552,22 +553,32 @@ private void makeSurfaces() {
if (egressWalkTimeSeconds > request.maxWalkTime * 60) {
continue;
}
int propagated_lb = lb0 + egressWalkTimeSeconds;
int propagated_ub = ub0 + egressWalkTimeSeconds;
int existing_lb = lbs.get(vertex);
int existing_ub = ubs.get(vertex);
if (existing_lb == TimeSurface.UNREACHABLE || existing_lb > propagated_lb) {
lbs.put(vertex, propagated_lb);
int propagated_min = lb0 + egressWalkTimeSeconds;
int propagated_max = ub0 + egressWalkTimeSeconds;
int propagated_avg = (int)(((long) propagated_min + propagated_max) / 2); // FIXME HACK
int existing_min = minSurface.times.get(vertex);
int existing_max = maxSurface.times.get(vertex);
int existing_avg = avgSurface.times.get(vertex);
// FIXME this is taking the least lower bound and the least upper bound
// which is not necessarily wrong but it's a crude way to perform the combination
if (existing_min == TimeSurface.UNREACHABLE || existing_min > propagated_min) {
minSurface.times.put(vertex, propagated_min);
}
if (existing_ub == TimeSurface.UNREACHABLE || existing_ub > propagated_ub) {
ubs.put(vertex, propagated_ub);
if (existing_max == TimeSurface.UNREACHABLE || existing_max > propagated_max) {
maxSurface.times.put(vertex, propagated_max);
}
if (existing_avg == TimeSurface.UNREACHABLE || existing_avg > propagated_avg) {
avgSurface.times.put(vertex, propagated_avg);
}
}
}
}
LOG.info("Done with propagation.");
/* Store the result in a field in the router object. */
timeSurfaceRangeSet = TimeSurface.makeSurfaces(this, lbs, ubs);
/* Store the results in a field in the router object. */
timeSurfaceRangeSet = new TimeSurface.RangeSet();
timeSurfaceRangeSet.min = minSurface;
timeSurfaceRangeSet.max = maxSurface;
timeSurfaceRangeSet.avg = avgSurface;
}

}

0 comments on commit 7ef10d8

Please sign in to comment.