Skip to content
This repository
Browse code

added debug code to be able to figure why some edges are traversed to…

… fast (aside fromom u-shaped roads)
  • Loading branch information...
commit 758ec2f5d06205701b0c8e694bdebe9d70c434a1 1 parent c7fd149
Stefan Steiniger authored December 25, 2012
55  opentripplanner-api-webapp/src/main/java/org/opentripplanner/api/ws/analyst/IsoChrone.java
@@ -20,6 +20,7 @@
20 20
 import javax.ws.rs.core.Response.Status;
21 21
 import javax.xml.bind.annotation.XmlRootElement;
22 22
 
  23
+import org.aspectj.weaver.tools.ISupportsMessageContext;
23 24
 import org.geotools.referencing.GeodeticCalculator;
24 25
 import org.opensphere.geometry.algorithm.ConcaveHull;
25 26
 import org.opentripplanner.analyst.core.GeometryIndex;
@@ -92,7 +93,10 @@
92 93
     public static final String RESULT_TYPE_SHED = "SHED";
93 94
     public static final String RESULT_TYPE_EDGES = "EDGES";
94 95
     
  96
+    private boolean showTooFastEdgesAsDebugGeomsANDnotUShapes = true;
95 97
     private List debugGeoms = null;
  98
+    private List tooFastTraversedEdgeGeoms = null;
  99
+    
96 100
     @Autowired GraphService graphService;
97 101
     @Autowired private SPTService sptService; 
98 102
     
@@ -125,6 +129,7 @@ public String getIsochrone(
125 129
     		) throws Exception {
126 130
 	
127 131
     	this.debugGeoms = new ArrayList();
  132
+    	this.tooFastTraversedEdgeGeoms = new ArrayList();
128 133
     	
129 134
         RoutingRequest sptRequestA = buildRequest(0);
130 135
         String from = sptRequestA.getFrom();
@@ -422,6 +427,13 @@ else if(output.equals("DEBUGEDGES")){
422 427
         		//-- for debugging, i.e. display of detected u-shapes/crescents
423 428
         		ArrayList<LineString> withinTimeEdges = this.getLinesAndSubEdgesWithinMaxTime(maxTime, allConnectingEdges, sptA, 
424 429
         				angleLimitForUShapeDetection, distanceToleranceForUShapeDetection, maxUserSpeed, usesCar, doSpeedTest);
  430
+        		if(this.showTooFastEdgesAsDebugGeomsANDnotUShapes){
  431
+        			LOG.debug("displaying edges that are traversed too fast");
  432
+        			this.debugGeoms = this.tooFastTraversedEdgeGeoms;
  433
+        		}
  434
+        		else{
  435
+        			LOG.debug("displaying detected u-shaped roads/crescents");
  436
+        		}
425 437
         		LineString edges[] = new LineString[this.debugGeoms.size()];
426 438
                 int k=0;
427 439
                 for (Iterator iterator = debugGeoms.iterator(); iterator.hasNext();) {
@@ -510,6 +522,7 @@ LineString getSubLineString(LineString ls, double fraction){
510 522
     		if((sFrom != null) && (sTo != null) ){
511 523
     			long fromTime = sFrom.getElapsedTime();
512 524
     			long toTime = sTo.getElapsedTime();
  525
+    			long dt = Math.abs(toTime - fromTime);
513 526
     			Geometry edgeGeom = edge.getGeometry();
514 527
     			if ((edgeGeom != null) && (edgeGeom instanceof LineString)){
515 528
     				LineString ls = (LineString)edgeGeom;
@@ -539,13 +552,13 @@ LineString getSubLineString(LineString ls, double fraction){
539 552
 							LineString inputLS = ls;
540 553
 							double fraction = 1.0;
541 554
     						if(fromTime < toTime){
542  
-    							double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), userSpeed, edge, hasCar);
  555
+    							double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt , userSpeed, edge, hasCar, uShapeOrLonger);
543 556
 								fraction = (double)distanceToWalkInTimeMissing / (double)lineDist;
544 557
     						}
545 558
     						else{
546 559
     							// toTime < fromTime : invert the edge direction
547 560
     							inputLS = (LineString)ls.reverse();
548  
-								double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, toTime, (fromTime - toTime), userSpeed, edge, hasCar);
  561
+								double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, toTime, dt, userSpeed, edge, hasCar, uShapeOrLonger);
549 562
 								fraction = (double)distanceToWalkInTimeMissing / (double)lineDist;
550 563
     						}
551 564
     						// get the subedge
@@ -584,7 +597,8 @@ private void treatAndAddUshapeWithinTimeLimits(long maxTime, double userSpeed,
584 597
 			LineString ls, boolean hasCar) {
585 598
 		
586 599
 		//check if the u-shape can be traveled within the remaining time
587  
-		double distanceToMoveInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), userSpeed, edge, hasCar);
  600
+		long dt = Math.abs(toTime - fromTime);
  601
+		double distanceToMoveInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt, userSpeed, edge, hasCar, true);
588 602
 		double lineDist = edge.getDistance();
589 603
 		double fraction = (double)distanceToMoveInTimeMissing / (double)lineDist;
590 604
 		// get the sub-edge geom
@@ -595,7 +609,7 @@ private void treatAndAddUshapeWithinTimeLimits(long maxTime, double userSpeed,
595 609
 			walkShedEdges.add(subLine);
596 610
 			// if it is smaller we need also to calculate the LS from the other side
597 611
 			LineString reversedLine = (LineString)ls.reverse();
598  
-			double distanceToMoveInTimeMissing2 = distanceToMoveInRemainingTime(maxTime, toTime, (toTime - fromTime), userSpeed, edge, hasCar);
  612
+			double distanceToMoveInTimeMissing2 = distanceToMoveInRemainingTime(maxTime, toTime, dt, userSpeed, edge, hasCar, true);
599 613
 			double fraction2 = (double)distanceToMoveInTimeMissing2 / (double)lineDist;
600 614
 			LineString secondsubLine = this.getSubLineString(reversedLine, fraction2);;
601 615
 			walkShedEdges.add(secondsubLine);
@@ -639,9 +653,10 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
639 653
 				if(performSpeedTest){
640 654
 					// Use also a distance based criteria since the angle criteria may fail.
641 655
 					// However a distance based one may fail as well for steep terrain.
  656
+					long dt = Math.abs(toTime - fromTime);
642 657
 					double lineDist = edge.getDistance();
643  
-					double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, (toTime - fromTime), 
644  
-							userSpeed, edge, hasCar);
  658
+					double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(maxTime, fromTime, dt, 
  659
+							userSpeed, edge, hasCar, false);
645 660
 					double approxWalkableDistanceInTime = distanceToWalkInTimeMissing * distanceTolerance;
646 661
 					if((approxWalkableDistanceInTime < lineDist)){
647 662
 						return true;
@@ -662,11 +677,13 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
662 677
 	 * @param userSpeed in m/sec, dependent on traversal mode
663 678
 	 * @param edge the edge itself (used to the get the speed in car mode)
664 679
 	 * @param usesCar if we traverse the edge in car mode
  680
+	 * @param hasUshape if know, indicate if the edge has a u-shape
665 681
 	 * @return the distance in meter that can be moved until maxTime
666 682
 	 */
667  
-	double distanceToMoveInRemainingTime(long maxTime, long fromTime, double traverseTime, double userSpeed, Edge edge, boolean usesCar){
  683
+	double distanceToMoveInRemainingTime(long maxTime, long fromTime, double traverseTime, double userSpeed, 
  684
+			Edge edge, boolean usesCar, boolean hasUshape){
668 685
 
669  
-		boolean hasTooFastCar = false;
  686
+		boolean isTooFast = false;
670 687
 		String msg = "";
671 688
 		
672 689
 		double originalTravelSpeed = edge.getDistance() / traverseTime; //this may be wrong for u-shapes
@@ -687,11 +704,19 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
687 704
 			double vdiff = Math.abs(originalTravelSpeed - userSpeed);
688 705
 			double vDiffPercent = vdiff/ (userSpeed/100.0);
689 706
 			if(vDiffPercent > 20){
690  
-				hasTooFastCar = true;
691  
-				msg = "v_traversed is much faster than (allowed) v_user [m/s] >>> v_traversed=" + (int)Math.floor(originalTravelSpeed) + ", v_maxUser=" + (int)Math.floor(userSpeed);			
692  
-				if(!usesCar){
693  
-					LOG.debug(msg);
  707
+				isTooFast = true;
  708
+				// [sstein Dec 2012]: Note, it seems like most of these edges are indeed of u-shape type,
  709
+				// i.e. small roads that come from and return from (the same) main road
  710
+				msg = "v_traversed is much faster than (allowed) v_user, edgeName: " + edge.getName() + 
  711
+						", >>> (in m/s): v_traversed=" + (int)Math.floor(originalTravelSpeed) + 
  712
+						", v_maxUser=" + (int)Math.floor(userSpeed);
  713
+				if(hasUshape){
  714
+					msg = msg + ", known u-shape, ";
694 715
 				}
  716
+				if((usesCar == false) && (hasUshape == false)){
  717
+					this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
  718
+					LOG.debug(msg);
  719
+				} //otherwise we print msg below
695 720
 			}
696 721
 		}
697 722
 		// correct speed for car use, as each road has its speed limits
@@ -699,8 +724,10 @@ private boolean testForUshape(Edge edge, long maxTime, long fromTime, long toTim
699 724
 			if(edge instanceof PlainStreetEdge){
700 725
 				PlainStreetEdge pe = (PlainStreetEdge)edge;
701 726
 				userSpeed = pe.getCarSpeed();
702  
-				if(hasTooFastCar){
703  
-					LOG.debug(msg + "; setting v_PlainStreetEdge=" + (int)Math.floor(userSpeed) + " [m/s]");
  727
+				// we need to check again if the originalTravelSpeed is faster
  728
+				if((isTooFast == true) && (originalTravelSpeed > userSpeed) && (hasUshape == false)){
  729
+					this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
  730
+					LOG.debug(msg + "; setting v_PlainStreetEdge=" + (int)Math.floor(userSpeed));
704 731
 				}
705 732
 			}
706 733
 		}

0 notes on commit 758ec2f

Please sign in to comment.
Something went wrong with that request. Please try again.