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
{ {
MatchedWaypoint seedPoint = new MatchedWaypoint(); List<MatchedWaypoint> wpList = new ArrayList<MatchedWaypoint>();
seedPoint.waypoint = waypoints.get(0); for( OsmNodeNamed wp : waypoints )
List<MatchedWaypoint> listOne = new ArrayList<MatchedWaypoint>(); {
listOne.add( seedPoint ); MatchedWaypoint seedPoint = new MatchedWaypoint();
matchWaypointsToNodes( listOne ); 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) 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 nshot = 0; nshot < nshots; nshot++ ) for( int y = y0; y < y1; y++ )
{ {
OsmNodeNamed n = new OsmNodeNamed(); for( int x = x0; x < x1; x++ )
n.name = "from"; {
n.ilon = lowerLeft.ilon + (int)(rand.nextDouble() * ( uppperRight.ilon - lowerLeft.ilon ) ); // calculate n-circles for this latitude
n.ilat = lowerLeft.ilat + (int)(rand.nextDouble() * ( uppperRight.ilat - lowerLeft.ilat ) ); 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>(); List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
wplist.add( n ); for( int shot=0; shot<shots; shot++ )
{
SearchBoundary boundary = new SearchBoundary( n, 100000, 0 ); 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(); RoutingContext rc = new RoutingContext();
rc.localFunction = args[5]; rc.localFunction = profile;
rc.memoryclass = (int) ( Runtime.getRuntime().maxMemory() / 1024 / 1024 ); rc.memoryclass = (int) ( Runtime.getRuntime().maxMemory() / 1024 / 1024 );
if ( findTrs ) rc.suspectNodes = suspectTRs;
{ rc.inverseRouting = rand.nextBoolean();
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;
re.doSearch(); RoutingEngine re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
re.doSearch( radius );
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";