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()
{
doSearch(0);
}
public void doSearch( int radius )
{
try
{
MatchedWaypoint seedPoint = new MatchedWaypoint();
seedPoint.waypoint = waypoints.get(0);
List<MatchedWaypoint> listOne = new ArrayList<MatchedWaypoint>();
listOne.add( seedPoint );
matchWaypointsToNodes( listOne );
List<MatchedWaypoint> wpList = new ArrayList<MatchedWaypoint>();
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)
{

View file

@ -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<Long,Integer> suspectTRs = new HashMap<Long,Integer>();
Map<Long,Integer> suspectTRs = new HashMap<Long,Integer>();
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<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
wplist.add( n );
SearchBoundary boundary = new SearchBoundary( n, 100000, 0 );
for( int shot=0; shot<shots; shot++ )
{
OsmNodeNamed n = new OsmNodeNamed();
n.name = "from";
n.ilon = lon0 + rand.nextInt( 1000000 );
n.ilat = lat0 + rand.nextInt( 1000000 );
wplist.add( n );
}
RoutingContext rc = new RoutingContext();
rc.localFunction = args[5];
rc.localFunction = profile;
rc.memoryclass = (int) ( Runtime.getRuntime().maxMemory() / 1024 / 1024 );
if ( findTrs )
{
rc.suspectTRs = suspectTRs;
rc.considerTurnRestrictions = false;
}
else
{
rc.suspectNodes = suspectTRs;
rc.inverseRouting = rand.nextBoolean();
}
RoutingEngine re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
re.boundary = boundary;
rc.suspectNodes = suspectTRs;
rc.inverseRouting = rand.nextBoolean();
re.doSearch();
RoutingEngine re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
re.doSearch( radius );
if ( re.getErrorMessage() != null )
{
System.out.println( re.getErrorMessage() );
}
}
}
// write tr-suspects to file
String suspectsFile = "deadend.suspects";