search circles: bugfix + effective coverage

This commit is contained in:
Arndt Brenschede 2018-09-16 09:32:08 +02:00
parent b81ebca103
commit 3d81c7938f
2 changed files with 72 additions and 45 deletions

View file

@ -280,16 +280,43 @@ public class RoutingEngine extends Thread
public void doSearch() public void doSearch()
{
doSearch(0);
}
public void doSearch( int radius )
{ {
try try
{
List<MatchedWaypoint> wpList = new ArrayList<MatchedWaypoint>();
for( OsmNodeNamed wp : waypoints )
{ {
MatchedWaypoint seedPoint = new MatchedWaypoint(); MatchedWaypoint seedPoint = new MatchedWaypoint();
seedPoint.waypoint = waypoints.get(0); seedPoint.waypoint = wp;
List<MatchedWaypoint> listOne = new ArrayList<MatchedWaypoint>(); wpList.add( seedPoint );
listOne.add( seedPoint ); }
matchWaypointsToNodes( listOne );
findTrack( "seededSearch", seedPoint, null, null, null, false ); resetCache( false );
nodesCache.waypointMatcher = new WaypointMatcherImpl( wpList, 250., islandNodePairs );
for( MatchedWaypoint mwp : wpList )
{
preloadPosition( mwp.waypoint );
}
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) catch( IllegalArgumentException e)
{ {

View file

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import btools.mapaccess.OsmNode;
import btools.router.OsmNodeNamed; import btools.router.OsmNodeNamed;
import btools.router.RoutingContext; import btools.router.RoutingContext;
import btools.router.RoutingEngine; import btools.router.RoutingEngine;
@ -26,56 +27,55 @@ public class BadTRDetector
return; return;
} }
int nshots = Integer.parseInt( args[6] ); int x0 = Integer.parseInt( args[1]);
boolean findTrs = false; int y0 = Integer.parseInt( args[2]);
if ( nshots < 0 ) int x1 = Integer.parseInt( args[3]);
{ int y1 = Integer.parseInt( args[4]);
findTrs = true; String profile = args[5];
nshots = -nshots; int radius = Integer.parseInt( args[6] );
} double overlap = Double.parseDouble( args[7] );
OsmNodeNamed lowerLeft = BRouter.readPosition( args, 1, "lowerLeft" );
OsmNodeNamed uppperRight = BRouter.readPosition( args, 3, "uppperRight" );
Random rand = new Random(); Random rand = new Random();
Map<Long,Integer> suspectTRs = new HashMap<Long,Integer>(); Map<Long,Integer> suspectTRs = new HashMap<Long,Integer>();
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 );
for( int nshot = 0; nshot < nshots; nshot++ ) List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
for( int shot=0; shot<shots; shot++ )
{ {
OsmNodeNamed n = new OsmNodeNamed(); OsmNodeNamed n = new OsmNodeNamed();
n.name = "from"; n.name = "from";
n.ilon = lowerLeft.ilon + (int)(rand.nextDouble() * ( uppperRight.ilon - lowerLeft.ilon ) ); n.ilon = lon0 + rand.nextInt( 1000000 );
n.ilat = lowerLeft.ilat + (int)(rand.nextDouble() * ( uppperRight.ilat - lowerLeft.ilat ) ); n.ilat = lat0 + rand.nextInt( 1000000 );
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
wplist.add( n ); wplist.add( n );
SearchBoundary boundary = new SearchBoundary( n, 100000, 0 );
RoutingContext rc = new RoutingContext();
rc.localFunction = args[5];
rc.memoryclass = (int) ( Runtime.getRuntime().maxMemory() / 1024 / 1024 );
if ( findTrs )
{
rc.suspectTRs = suspectTRs;
rc.considerTurnRestrictions = false;
} }
else RoutingContext rc = new RoutingContext();
{ rc.localFunction = profile;
rc.memoryclass = (int) ( Runtime.getRuntime().maxMemory() / 1024 / 1024 );
rc.suspectNodes = suspectTRs; rc.suspectNodes = suspectTRs;
rc.inverseRouting = rand.nextBoolean(); rc.inverseRouting = rand.nextBoolean();
}
RoutingEngine re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc ); RoutingEngine re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
re.boundary = boundary; re.doSearch( radius );
re.doSearch();
if ( re.getErrorMessage() != null ) if ( re.getErrorMessage() != null )
{ {
System.out.println( re.getErrorMessage() ); System.out.println( re.getErrorMessage() );
} }
}
} }
// write tr-suspects to file // write tr-suspects to file
String suspectsFile = "deadend.suspects"; String suspectsFile = "deadend.suspects";