From 3d81c7938fe9752ee89d350e58768b33a43fbe38 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sun, 16 Sep 2018 09:32:08 +0200 Subject: [PATCH] search circles: bugfix + effective coverage --- .../java/btools/router/RoutingEngine.java | 39 ++++++++-- .../java/btools/server/BadTRDetector.java | 78 +++++++++---------- 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index e73925d..a263026 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -280,16 +280,43 @@ public class RoutingEngine extends Thread public void doSearch() + { + doSearch(0); + } + + public void doSearch( int radius ) { try { - MatchedWaypoint seedPoint = new MatchedWaypoint(); - seedPoint.waypoint = waypoints.get(0); - List listOne = new ArrayList(); - listOne.add( seedPoint ); - matchWaypointsToNodes( listOne ); + List wpList = new ArrayList(); + for( OsmNodeNamed wp : waypoints ) + { + MatchedWaypoint seedPoint = new MatchedWaypoint(); + seedPoint.waypoint = wp; + wpList.add( seedPoint ); + } + + resetCache( false ); + nodesCache.waypointMatcher = new WaypointMatcherImpl( wpList, 250., islandNodePairs ); + for( MatchedWaypoint mwp : wpList ) + { + preloadPosition( mwp.waypoint ); + } - findTrack( "seededSearch", seedPoint, null, null, null, false ); + for( MatchedWaypoint mwp : wpList ) + { + if ( mwp.crosspoint != null ) + { + if ( radius > 0 ) + { + boundary = new SearchBoundary( mwp.waypoint, radius, 0 ); + routingContext.inverseRouting = !routingContext.inverseRouting; // hack + routingContext.inverseDirection = routingContext.inverseRouting; + } + MAXNODES_ISLAND_CHECK = -1; + findTrack( "seededSearch", mwp, null, null, null, false ); + } + } } catch( IllegalArgumentException e) { diff --git a/brouter-server/src/main/java/btools/server/BadTRDetector.java b/brouter-server/src/main/java/btools/server/BadTRDetector.java index 0170797..9c3c461 100644 --- a/brouter-server/src/main/java/btools/server/BadTRDetector.java +++ b/brouter-server/src/main/java/btools/server/BadTRDetector.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.Random; +import btools.mapaccess.OsmNode; import btools.router.OsmNodeNamed; import btools.router.RoutingContext; import btools.router.RoutingEngine; @@ -26,56 +27,55 @@ public class BadTRDetector return; } - int nshots = Integer.parseInt( args[6] ); - boolean findTrs = false; - if ( nshots < 0 ) - { - findTrs = true; - nshots = -nshots; - } - - OsmNodeNamed lowerLeft = BRouter.readPosition( args, 1, "lowerLeft" ); - OsmNodeNamed uppperRight = BRouter.readPosition( args, 3, "uppperRight" ); + int x0 = Integer.parseInt( args[1]); + int y0 = Integer.parseInt( args[2]); + int x1 = Integer.parseInt( args[3]); + int y1 = Integer.parseInt( args[4]); + String profile = args[5]; + int radius = Integer.parseInt( args[6] ); + double overlap = Double.parseDouble( args[7] ); + Random rand = new Random(); - Map suspectTRs = new HashMap(); - - + Map suspectTRs = new HashMap(); - for( int nshot = 0; nshot < nshots; nshot++ ) - { - OsmNodeNamed n = new OsmNodeNamed(); - n.name = "from"; - n.ilon = lowerLeft.ilon + (int)(rand.nextDouble() * ( uppperRight.ilon - lowerLeft.ilon ) ); - n.ilat = lowerLeft.ilat + (int)(rand.nextDouble() * ( uppperRight.ilat - lowerLeft.ilat ) ); - + for( int y = y0; y < y1; y++ ) + { + for( int x = x0; x < x1; x++ ) + { + // calculate n-circles for this latitude + int lon0 = 1000000 * ( x + 180 ); + int lat0 = 1000000 * ( y + 90 ); + OsmNode n0 = new OsmNode( lon0, lat0 ); + double arect = n0.calcDistance( new OsmNode( lon0, lat0 + 1000000 ) ); + arect *= n0.calcDistance( new OsmNode( lon0 + 1000000, lat0 ) ); + double adisc = ( Math.PI * radius ) * radius; + int shots = (int)(1. + overlap * arect / adisc); + +System.out.println( "shots for y=" + y + " x=" + x + " -> " + shots ); + List wplist = new ArrayList(); - wplist.add( n ); - - SearchBoundary boundary = new SearchBoundary( n, 100000, 0 ); - + for( int shot=0; shot