Skip to content

Commit

Permalink
store distances not times in Samples, fixes #1889
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Apr 17, 2015
1 parent d48d36d commit ee2e4bc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/opentripplanner/analyst/SampleSet.java
Expand Up @@ -34,8 +34,8 @@ public SampleSet (PointSet pset, SampleFactory sfac) {
} }
v0s[i] = sample.v0; v0s[i] = sample.v0;
v1s[i] = sample.v1; v1s[i] = sample.v1;
d0s[i] = sample.t0; // TODO time not distance in samples d0s[i] = sample.d0;
d1s[i] = sample.t1; // TODO time not distance in samples d1s[i] = sample.d1;
} }
} }


Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/opentripplanner/analyst/TimeSurface.java
Expand Up @@ -46,10 +46,12 @@ public class TimeSurface implements Serializable {
public Map<String, String> params; // The query params sent by the user, for reference only public Map<String, String> params; // The query params sent by the user, for reference only
public SparseMatrixZSampleGrid<WTWD> sampleGrid; // another representation on a regular grid with a triangulation public SparseMatrixZSampleGrid<WTWD> sampleGrid; // another representation on a regular grid with a triangulation
public String description; public String description;
public double walkSpeed = 1.33; // meters/sec TODO could we just store the whole routing request instead of params?


public TimeSurface(ShortestPathTree spt) { public TimeSurface(ShortestPathTree spt) {


params = spt.getOptions().parameters; params = spt.getOptions().parameters;
walkSpeed = spt.getOptions().walkSpeed;


String routerId = spt.getOptions().routerId; String routerId = spt.getOptions().routerId;
if (routerId == null || routerId.isEmpty() || routerId.equalsIgnoreCase("default")) { if (routerId == null || routerId.isEmpty() || routerId.equalsIgnoreCase("default")) {
Expand Down Expand Up @@ -89,6 +91,7 @@ public TimeSurface (AnalystProfileRouterPrototype profileRouter) {
dateTime = req.fromTime; // FIXME dateTime = req.fromTime; // FIXME
routerId = profileRouter.graph.routerId; routerId = profileRouter.graph.routerId;
cutoffMinutes = profileRouter.MAX_DURATION / 60; cutoffMinutes = profileRouter.MAX_DURATION / 60;
walkSpeed = profileRouter.request.walkSpeed;
} }


/** Make a max or min timesurface from propagated times in a ProfileRouter. */ /** Make a max or min timesurface from propagated times in a ProfileRouter. */
Expand All @@ -102,6 +105,7 @@ public TimeSurface (ProfileRouter profileRouter) {
dateTime = req.fromTime; // FIXME dateTime = req.fromTime; // FIXME
routerId = profileRouter.graph.routerId; routerId = profileRouter.graph.routerId;
cutoffMinutes = profileRouter.MAX_DURATION / 60; cutoffMinutes = profileRouter.MAX_DURATION / 60;
walkSpeed = profileRouter.request.walkSpeed;
} }


public static TimeSurface.RangeSet makeSurfaces (AnalystProfileRouterPrototype profileRouter) { public static TimeSurface.RangeSet makeSurfaces (AnalystProfileRouterPrototype profileRouter) {
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/org/opentripplanner/analyst/core/Sample.java
Expand Up @@ -20,14 +20,14 @@ the License, or (at your option) any later version.


public class Sample { public class Sample {


public final int t0, t1; // TODO change from times to distances. public final int d0, d1; // TODO change from times to distances.
public final Vertex v0, v1; public final Vertex v0, v1;


public Sample (Vertex v0, int t0, Vertex v1, int t1) { public Sample (Vertex v0, int d0, Vertex v1, int d1) {
this.v0 = v0; this.v0 = v0;
this.t0 = t0; this.d0 = d0;
this.v1 = v1; this.v1 = v1;
this.t1 = t1; this.d1 = d1;
} }


public byte evalBoardings(ShortestPathTree spt) { public byte evalBoardings(ShortestPathTree spt) {
Expand All @@ -41,16 +41,21 @@ public byte evalBoardings(ShortestPathTree spt) {
m1 = (s1.getNumBoardings()); m1 = (s1.getNumBoardings());
return (byte) ((m0 < m1) ? m0 : m1); return (byte) ((m0 < m1) ? m0 : m1);
} }


/**
* @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) { public long eval(ShortestPathTree spt) {
State s0 = spt.getState(v0); State s0 = spt.getState(v0);
State s1 = spt.getState(v1); State s1 = spt.getState(v1);
long m0 = Long.MAX_VALUE; long m0 = Long.MAX_VALUE;
long m1 = Long.MAX_VALUE; long m1 = Long.MAX_VALUE;
double walkSpeed = spt.getOptions().walkSpeed;
if (s0 != null) if (s0 != null)
m0 = (s0.getActiveTime() + t0); m0 = (int)(s0.getActiveTime() + d0 / walkSpeed);
if (s1 != null) if (s1 != null)
m1 = (s1.getActiveTime() + t1); m1 = (int)(s1.getActiveTime() + d1 / walkSpeed);
return (m0 < m1) ? m0 : m1; return (m0 < m1) ? m0 : m1;
} }


Expand All @@ -59,13 +64,10 @@ public double evalWalkDistance(ShortestPathTree spt) {
State s1 = spt.getState(v1); State s1 = spt.getState(v1);
double m0 = Double.NaN; double m0 = Double.NaN;
double m1 = Double.NaN; double m1 = Double.NaN;
// TODO When using distance instead of t0/t1 times
// the computation will be made simpler.
double walkSpeed = spt.getOptions().walkSpeed;
if (s0 != null) if (s0 != null)
m0 = (s0.getWalkDistance() + t0 * walkSpeed); m0 = (s0.getWalkDistance() + d0);
if (s1 != null) if (s1 != null)
m1 = (s1.getWalkDistance() + t1 * walkSpeed); m1 = (s1.getWalkDistance() + d1);
return (m0 < m1) ? m0 : m1; return (m0 < m1) ? m0 : m1;
} }


Expand All @@ -76,20 +78,20 @@ public long eval(TimeSurface surf) {
if (v0 != null) { if (v0 != null) {
int s0 = surf.getTime(v0); int s0 = surf.getTime(v0);
if (s0 != TimeSurface.UNREACHABLE) { if (s0 != TimeSurface.UNREACHABLE) {
m0 = (int) (s0 + t0); m0 = (int) (s0 + d0 / surf.walkSpeed);
} }
} }
if (v1 != null) { if (v1 != null) {
int s1 = surf.getTime(v1); int s1 = surf.getTime(v1);
if (s1 != TimeSurface.UNREACHABLE) { if (s1 != TimeSurface.UNREACHABLE) {
m1 = (int) (s1 + t1); m1 = (int) (s1 + d1 / surf.walkSpeed);
} }
} }
return (m0 < m1) ? m0 : m1; return (m0 < m1) ? m0 : m1;
} }


public String toString() { public String toString() {
return String.format("Sample: %s in %d sec or %s in %d sec\n", v0, t0, v1, t1); return String.format("Sample: %s at %d meters or %s at %d meters\n", v0, d0, v1, d1);
} }


} }
Expand Down
Expand Up @@ -13,8 +13,10 @@ the License, or (at your option) any later version.


package org.opentripplanner.analyst.request; package org.opentripplanner.analyst.request;


import java.util.List; import com.vividsolutions.jts.geom.Coordinate;

import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.LineString;
import org.opentripplanner.analyst.core.GeometryIndex; import org.opentripplanner.analyst.core.GeometryIndex;
import org.opentripplanner.analyst.core.Sample; import org.opentripplanner.analyst.core.Sample;
import org.opentripplanner.analyst.core.SampleSource; import org.opentripplanner.analyst.core.SampleSource;
Expand All @@ -23,10 +25,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Vertex; import org.opentripplanner.routing.graph.Vertex;


import com.vividsolutions.jts.geom.Coordinate; import java.util.List;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.LineString;


public class SampleFactory implements SampleSource { public class SampleFactory implements SampleSource {


Expand Down Expand Up @@ -112,10 +111,8 @@ public Sample findClosest(List<Edge> edges, Coordinate pt, double xscale) {
if (d > searchRadiusM) if (d > searchRadiusM)
return null; return null;
double d0 = d + best.distanceAlong(); double d0 = d + best.distanceAlong();
int t0 = (int) (d0 / 1.33);
double d1 = d + best.distanceToEnd(); double d1 = d + best.distanceToEnd();
int t1 = (int) (d1 / 1.33); Sample s = new Sample(v0, (int) d0, v1, (int) d1);
Sample s = new Sample(v0, t0, v1, t1);
//System.out.println(s.toString()); //System.out.println(s.toString());
return s; return s;
} }
Expand Down
Expand Up @@ -76,8 +76,8 @@ public OtpsLatLon getSnappedLocation() {
if (e.getToVertex().equals(cachedSample.v1) && e.getGeometry() != null) { if (e.getToVertex().equals(cachedSample.v1) && e.getGeometry() != null) {
LineString geom = e.getGeometry(); LineString geom = e.getGeometry();
LengthIndexedLine liline = new LengthIndexedLine(geom); LengthIndexedLine liline = new LengthIndexedLine(geom);
int t = cachedSample.t0 + cachedSample.t1; int d = cachedSample.d0 + cachedSample.d1;
double k = t == 0 ? 0.0 : 1.0 * cachedSample.t0 / t; double k = d == 0 ? 0.0 : 1.0 * cachedSample.d0 / d;
double x = liline.getStartIndex() + (liline.getEndIndex() - liline.getStartIndex()) double x = liline.getStartIndex() + (liline.getEndIndex() - liline.getStartIndex())
* k; * k;
Coordinate p = liline.extractPoint(x); Coordinate p = liline.extractPoint(x);
Expand Down

0 comments on commit ee2e4bc

Please sign in to comment.