Skip to content

Commit

Permalink
added debug code to be able to figure why some edges are traversed to…
Browse files Browse the repository at this point in the history
… fast (aside fromom u-shaped roads)
  • Loading branch information
Stefan Steiniger committed Dec 25, 2012
1 parent c7fd149 commit 758ec2f
Showing 1 changed file with 41 additions and 14 deletions.
Expand Up @@ -20,6 +20,7 @@
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;


import org.aspectj.weaver.tools.ISupportsMessageContext;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import org.opensphere.geometry.algorithm.ConcaveHull; import org.opensphere.geometry.algorithm.ConcaveHull;
import org.opentripplanner.analyst.core.GeometryIndex; import org.opentripplanner.analyst.core.GeometryIndex;
Expand Down Expand Up @@ -92,7 +93,10 @@ public class IsoChrone extends RoutingResource{
public static final String RESULT_TYPE_SHED = "SHED"; public static final String RESULT_TYPE_SHED = "SHED";
public static final String RESULT_TYPE_EDGES = "EDGES"; public static final String RESULT_TYPE_EDGES = "EDGES";


private boolean showTooFastEdgesAsDebugGeomsANDnotUShapes = true;
private List debugGeoms = null; private List debugGeoms = null;
private List tooFastTraversedEdgeGeoms = null;

@Autowired GraphService graphService; @Autowired GraphService graphService;
@Autowired private SPTService sptService; @Autowired private SPTService sptService;


Expand Down Expand Up @@ -125,6 +129,7 @@ public String getIsochrone(
) throws Exception { ) throws Exception {


this.debugGeoms = new ArrayList(); this.debugGeoms = new ArrayList();
this.tooFastTraversedEdgeGeoms = new ArrayList();


RoutingRequest sptRequestA = buildRequest(0); RoutingRequest sptRequestA = buildRequest(0);
String from = sptRequestA.getFrom(); String from = sptRequestA.getFrom();
Expand Down Expand Up @@ -422,6 +427,13 @@ else if(output.equals("DEBUGEDGES")){
//-- for debugging, i.e. display of detected u-shapes/crescents //-- for debugging, i.e. display of detected u-shapes/crescents
ArrayList<LineString> withinTimeEdges = this.getLinesAndSubEdgesWithinMaxTime(maxTime, allConnectingEdges, sptA, ArrayList<LineString> withinTimeEdges = this.getLinesAndSubEdgesWithinMaxTime(maxTime, allConnectingEdges, sptA,
angleLimitForUShapeDetection, distanceToleranceForUShapeDetection, maxUserSpeed, usesCar, doSpeedTest); angleLimitForUShapeDetection, distanceToleranceForUShapeDetection, maxUserSpeed, usesCar, doSpeedTest);
if(this.showTooFastEdgesAsDebugGeomsANDnotUShapes){
LOG.debug("displaying edges that are traversed too fast");
this.debugGeoms = this.tooFastTraversedEdgeGeoms;
}
else{
LOG.debug("displaying detected u-shaped roads/crescents");
}
LineString edges[] = new LineString[this.debugGeoms.size()]; LineString edges[] = new LineString[this.debugGeoms.size()];
int k=0; int k=0;
for (Iterator iterator = debugGeoms.iterator(); iterator.hasNext();) { for (Iterator iterator = debugGeoms.iterator(); iterator.hasNext();) {
Expand Down Expand Up @@ -510,6 +522,7 @@ ArrayList<LineString> getLinesAndSubEdgesWithinMaxTime(long maxTime, ArrayList<E
if((sFrom != null) && (sTo != null) ){ if((sFrom != null) && (sTo != null) ){
long fromTime = sFrom.getElapsedTime(); long fromTime = sFrom.getElapsedTime();
long toTime = sTo.getElapsedTime(); long toTime = sTo.getElapsedTime();
long dt = Math.abs(toTime - fromTime);
Geometry edgeGeom = edge.getGeometry(); Geometry edgeGeom = edge.getGeometry();
if ((edgeGeom != null) && (edgeGeom instanceof LineString)){ if ((edgeGeom != null) && (edgeGeom instanceof LineString)){
LineString ls = (LineString)edgeGeom; LineString ls = (LineString)edgeGeom;
Expand Down Expand Up @@ -539,13 +552,13 @@ ArrayList<LineString> getLinesAndSubEdgesWithinMaxTime(long maxTime, ArrayList<E
LineString inputLS = ls; LineString inputLS = ls;
double fraction = 1.0; double fraction = 1.0;
if(fromTime < toTime){ if(fromTime < toTime){
double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), userSpeed, edge, hasCar); double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt , userSpeed, edge, hasCar, uShapeOrLonger);
fraction = (double)distanceToWalkInTimeMissing / (double)lineDist; fraction = (double)distanceToWalkInTimeMissing / (double)lineDist;
} }
else{ else{
// toTime < fromTime : invert the edge direction // toTime < fromTime : invert the edge direction
inputLS = (LineString)ls.reverse(); inputLS = (LineString)ls.reverse();
double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, toTime, (fromTime - toTime), userSpeed, edge, hasCar); double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, toTime, dt, userSpeed, edge, hasCar, uShapeOrLonger);
fraction = (double)distanceToWalkInTimeMissing / (double)lineDist; fraction = (double)distanceToWalkInTimeMissing / (double)lineDist;
} }
// get the subedge // get the subedge
Expand Down Expand Up @@ -584,7 +597,8 @@ private void treatAndAddUshapeWithinTimeLimits(long maxTime, double userSpeed,
LineString ls, boolean hasCar) { LineString ls, boolean hasCar) {


//check if the u-shape can be traveled within the remaining time //check if the u-shape can be traveled within the remaining time
double distanceToMoveInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), userSpeed, edge, hasCar); long dt = Math.abs(toTime - fromTime);
double distanceToMoveInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt, userSpeed, edge, hasCar, true);
double lineDist = edge.getDistance(); double lineDist = edge.getDistance();
double fraction = (double)distanceToMoveInTimeMissing / (double)lineDist; double fraction = (double)distanceToMoveInTimeMissing / (double)lineDist;
// get the sub-edge geom // get the sub-edge geom
Expand All @@ -595,7 +609,7 @@ private void treatAndAddUshapeWithinTimeLimits(long maxTime, double userSpeed,
walkShedEdges.add(subLine); walkShedEdges.add(subLine);
// if it is smaller we need also to calculate the LS from the other side // if it is smaller we need also to calculate the LS from the other side
LineString reversedLine = (LineString)ls.reverse(); LineString reversedLine = (LineString)ls.reverse();
double distanceToMoveInTimeMissing2 = distanceToMoveInRemainingTime(maxTime, toTime, (toTime - fromTime), userSpeed, edge, hasCar); double distanceToMoveInTimeMissing2 = distanceToMoveInRemainingTime(maxTime, toTime, dt, userSpeed, edge, hasCar, true);
double fraction2 = (double)distanceToMoveInTimeMissing2 / (double)lineDist; double fraction2 = (double)distanceToMoveInTimeMissing2 / (double)lineDist;
LineString secondsubLine = this.getSubLineString(reversedLine, fraction2);; LineString secondsubLine = this.getSubLineString(reversedLine, fraction2);;
walkShedEdges.add(secondsubLine); walkShedEdges.add(secondsubLine);
Expand Down Expand Up @@ -639,9 +653,10 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
if(performSpeedTest){ if(performSpeedTest){
// Use also a distance based criteria since the angle criteria may fail. // Use also a distance based criteria since the angle criteria may fail.
// However a distance based one may fail as well for steep terrain. // However a distance based one may fail as well for steep terrain.
long dt = Math.abs(toTime - fromTime);
double lineDist = edge.getDistance(); double lineDist = edge.getDistance();
double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt,
userSpeed, edge, hasCar); userSpeed, edge, hasCar, false);
double approxWalkableDistanceInTime = distanceToWalkInTimeMissing * distanceTolerance; double approxWalkableDistanceInTime = distanceToWalkInTimeMissing * distanceTolerance;
if((approxWalkableDistanceInTime < lineDist)){ if((approxWalkableDistanceInTime < lineDist)){
return true; return true;
Expand All @@ -662,11 +677,13 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
* @param userSpeed in m/sec, dependent on traversal mode * @param userSpeed in m/sec, dependent on traversal mode
* @param edge the edge itself (used to the get the speed in car mode) * @param edge the edge itself (used to the get the speed in car mode)
* @param usesCar if we traverse the edge in car mode * @param usesCar if we traverse the edge in car mode
* @param hasUshape if know, indicate if the edge has a u-shape
* @return the distance in meter that can be moved until maxTime * @return the distance in meter that can be moved until maxTime
*/ */
double distanceToMoveInRemainingTime(long maxTime, long fromTime, double traverseTime, double userSpeed, Edge edge, boolean usesCar){ double distanceToMoveInRemainingTime(long maxTime, long fromTime, double traverseTime, double userSpeed,
Edge edge, boolean usesCar, boolean hasUshape){


boolean hasTooFastCar = false; boolean isTooFast = false;
String msg = ""; String msg = "";


double originalTravelSpeed = edge.getDistance() / traverseTime; //this may be wrong for u-shapes double originalTravelSpeed = edge.getDistance() / traverseTime; //this may be wrong for u-shapes
Expand All @@ -687,20 +704,30 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
double vdiff = Math.abs(originalTravelSpeed - userSpeed); double vdiff = Math.abs(originalTravelSpeed - userSpeed);
double vDiffPercent = vdiff/ (userSpeed/100.0); double vDiffPercent = vdiff/ (userSpeed/100.0);
if(vDiffPercent > 20){ if(vDiffPercent > 20){
hasTooFastCar = true; isTooFast = true;
msg = "v_traversed is much faster than (allowed) v_user [m/s] >>> v_traversed=" + (int)Math.floor(originalTravelSpeed) + ", v_maxUser=" + (int)Math.floor(userSpeed); // [sstein Dec 2012]: Note, it seems like most of these edges are indeed of u-shape type,
if(!usesCar){ // i.e. small roads that come from and return from (the same) main road
LOG.debug(msg); msg = "v_traversed is much faster than (allowed) v_user, edgeName: " + edge.getName() +
", >>> (in m/s): v_traversed=" + (int)Math.floor(originalTravelSpeed) +
", v_maxUser=" + (int)Math.floor(userSpeed);
if(hasUshape){
msg = msg + ", known u-shape, ";
} }
if((usesCar == false) && (hasUshape == false)){
this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
LOG.debug(msg);
} //otherwise we print msg below
} }
} }
// correct speed for car use, as each road has its speed limits // correct speed for car use, as each road has its speed limits
if(usesCar){ if(usesCar){
if(edge instanceof PlainStreetEdge){ if(edge instanceof PlainStreetEdge){
PlainStreetEdge pe = (PlainStreetEdge)edge; PlainStreetEdge pe = (PlainStreetEdge)edge;
userSpeed = pe.getCarSpeed(); userSpeed = pe.getCarSpeed();
if(hasTooFastCar){ // we need to check again if the originalTravelSpeed is faster
LOG.debug(msg + "; setting v_PlainStreetEdge=" + (int)Math.floor(userSpeed) + " [m/s]"); if((isTooFast == true) && (originalTravelSpeed > userSpeed) && (hasUshape == false)){
this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
LOG.debug(msg + "; setting v_PlainStreetEdge=" + (int)Math.floor(userSpeed));
} }
} }
} }
Expand Down

0 comments on commit 758ec2f

Please sign in to comment.