automatically ignore islands
This commit is contained in:
parent
f2d04ef70a
commit
599a24f710
8 changed files with 203 additions and 23 deletions
|
|
@ -14,6 +14,7 @@ import btools.mapaccess.NodesCache;
|
|||
import btools.mapaccess.OsmLink;
|
||||
import btools.mapaccess.OsmLinkHolder;
|
||||
import btools.mapaccess.OsmNode;
|
||||
import btools.mapaccess.OsmNodePairSet;
|
||||
import btools.mapaccess.OsmNodesMap;
|
||||
import btools.util.SortedHeap;
|
||||
import btools.util.StackSampler;
|
||||
|
|
@ -30,6 +31,8 @@ public class RoutingEngine extends Thread
|
|||
private int linksProcessed = 0;
|
||||
|
||||
private int nodeLimit; // used for target island search
|
||||
private int MAXNODES_ISLAND_CHECK = 500;
|
||||
private OsmNodePairSet islandNodePairs = new OsmNodePairSet(MAXNODES_ISLAND_CHECK);
|
||||
|
||||
protected OsmTrack foundTrack = new OsmTrack();
|
||||
private OsmTrack foundRawTrack = null;
|
||||
|
|
@ -328,9 +331,24 @@ public class RoutingEngine extends Thread
|
|||
terminate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private OsmTrack findTrack( OsmTrack[] refTracks, OsmTrack[] lastTracks )
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
try
|
||||
{
|
||||
return tryFindTrack( refTracks, lastTracks );
|
||||
}
|
||||
catch( RoutingIslandException rie )
|
||||
{
|
||||
islandNodePairs.freezeTempPairs();
|
||||
nodesCache.clean( true );
|
||||
matchedWaypoints = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OsmTrack tryFindTrack( OsmTrack[] refTracks, OsmTrack[] lastTracks )
|
||||
{
|
||||
OsmTrack totaltrack = new OsmTrack();
|
||||
int nUnmatched = waypoints.size();
|
||||
|
|
@ -377,7 +395,7 @@ public class RoutingEngine extends Thread
|
|||
airDistanceCostFactor = 0.;
|
||||
for( int i=0; i<matchedWaypoints.size() -1; i++ )
|
||||
{
|
||||
nodeLimit = 200;
|
||||
nodeLimit = MAXNODES_ISLAND_CHECK;
|
||||
if ( routingContext.inverseRouting )
|
||||
{
|
||||
OsmTrack seg = findTrack( "start-island-check", matchedWaypoints.get(i), matchedWaypoints.get(i+1), null, null, false );
|
||||
|
|
@ -435,7 +453,7 @@ public class RoutingEngine extends Thread
|
|||
private void matchWaypointsToNodes( List<MatchedWaypoint> unmatchedWaypoints )
|
||||
{
|
||||
resetCache( false );
|
||||
nodesCache.waypointMatcher = new WaypointMatcherImpl( unmatchedWaypoints, 250. );
|
||||
nodesCache.waypointMatcher = new WaypointMatcherImpl( unmatchedWaypoints, 250., islandNodePairs );
|
||||
for( MatchedWaypoint mwp : unmatchedWaypoints )
|
||||
{
|
||||
preloadPosition( mwp.waypoint );
|
||||
|
|
@ -467,7 +485,10 @@ public class RoutingEngine extends Thread
|
|||
for( int idxLat=-1; idxLat<=1; idxLat++ )
|
||||
for( int idxLon=-1; idxLon<=1; idxLon++ )
|
||||
{
|
||||
nodesCache.loadSegmentFor( n.ilon + d*idxLon , n.ilat +d*idxLat );
|
||||
if ( idxLon != 0 || idxLat != 0 )
|
||||
{
|
||||
nodesCache.loadSegmentFor( n.ilon + d*idxLon , n.ilat +d*idxLat );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -608,6 +629,7 @@ public class RoutingEngine extends Thread
|
|||
long maxmem = routingContext.memoryclass * 131072L; // 1/8 of total
|
||||
|
||||
nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay, routingContext.forceSecondaryData, maxmem, nodesCache, detailed );
|
||||
islandNodePairs.clearTempPairs();
|
||||
}
|
||||
|
||||
private OsmNode getStartNode( long startId )
|
||||
|
|
@ -741,7 +763,7 @@ public class RoutingEngine extends Thread
|
|||
}
|
||||
finally
|
||||
{
|
||||
nodesCache.cleanNonVirgin();
|
||||
nodesCache.clean( false ); // clean only non-virgin caches
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -878,6 +900,10 @@ public class RoutingEngine extends Thread
|
|||
OsmNode currentNode = path.getTargetNode();
|
||||
|
||||
long currentNodeId = currentNode.getIdFromPos();
|
||||
long sourceNodeId = sourceNode.getIdFromPos();
|
||||
|
||||
islandNodePairs.addTempPair( sourceNodeId, currentNodeId );
|
||||
|
||||
if ( path.treedepth != 1 )
|
||||
{
|
||||
if ( path.treedepth == 0 ) // hack: sameSegment Paths marked treedepth=0 to pass above check
|
||||
|
|
@ -885,7 +911,6 @@ public class RoutingEngine extends Thread
|
|||
path.treedepth = 1;
|
||||
}
|
||||
|
||||
long sourceNodeId = sourceNode.getIdFromPos();
|
||||
if ( ( sourceNodeId == endNodeId1 && currentNodeId == endNodeId2 )
|
||||
|| ( sourceNodeId == endNodeId2 && currentNodeId == endNodeId1 ) )
|
||||
{
|
||||
|
|
@ -1078,7 +1103,6 @@ public class RoutingEngine extends Thread
|
|||
{
|
||||
bestPath.airdistance += boundary.getBoundaryDistance( nextNode );
|
||||
}
|
||||
|
||||
bestPath.treedepth = path.treedepth + 1;
|
||||
link.addLinkHolder( bestPath, currentNode );
|
||||
synchronized( openSet )
|
||||
|
|
@ -1092,6 +1116,12 @@ public class RoutingEngine extends Thread
|
|||
|
||||
path.unregisterUpTree( routingContext );
|
||||
}
|
||||
|
||||
if ( nodesVisited < MAXNODES_ISLAND_CHECK && islandNodePairs.getFreezeCount() < 5 )
|
||||
{
|
||||
throw new RoutingIslandException();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package btools.router;
|
||||
|
||||
public class RoutingIslandException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import btools.codec.WaypointMatcher;
|
||||
import btools.mapaccess.OsmNode;
|
||||
import btools.mapaccess.OsmNodePairSet;
|
||||
|
||||
/**
|
||||
* the WaypointMatcher is feeded by the decoder with geoemtries of ways that are
|
||||
|
|
@ -15,16 +16,20 @@ import btools.mapaccess.OsmNode;
|
|||
public final class WaypointMatcherImpl implements WaypointMatcher
|
||||
{
|
||||
private List<MatchedWaypoint> waypoints;
|
||||
private OsmNodePairSet islandPairs;
|
||||
|
||||
private int lonStart;
|
||||
private int latStart;
|
||||
private int lonTarget;
|
||||
private int latTarget;
|
||||
private boolean anyUpdate;
|
||||
private int lonLast;
|
||||
private int latLast;
|
||||
|
||||
public WaypointMatcherImpl( List<MatchedWaypoint> waypoints, double maxDistance )
|
||||
public WaypointMatcherImpl( List<MatchedWaypoint> waypoints, double maxDistance, OsmNodePairSet islandPairs )
|
||||
{
|
||||
this.waypoints = waypoints;
|
||||
this.islandPairs = islandPairs;
|
||||
for ( MatchedWaypoint mwp : waypoints )
|
||||
{
|
||||
mwp.radius = maxDistance * 110984.; // 6378000. / 57.3;
|
||||
|
|
@ -105,11 +110,23 @@ public final class WaypointMatcherImpl implements WaypointMatcher
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startNode( int ilon, int ilat, byte[] wayTags )
|
||||
public boolean start( int ilonStart, int ilatStart, int ilonTarget, int ilatTarget )
|
||||
{
|
||||
lonLast = lonStart = ilon;
|
||||
latLast = latStart = ilat;
|
||||
if ( islandPairs.size() > 0 )
|
||||
{
|
||||
long n1 = ( (long) ilonStart ) << 32 | ilatStart;
|
||||
long n2 = ( (long) ilonTarget ) << 32 | ilatTarget;
|
||||
if ( islandPairs.hasPair( n1, n2 ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
lonLast = lonStart = ilonStart;
|
||||
latLast = latStart = ilatStart;
|
||||
lonTarget = ilonTarget;
|
||||
latTarget = ilatTarget;
|
||||
anyUpdate = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -121,9 +138,9 @@ public final class WaypointMatcherImpl implements WaypointMatcher
|
|||
}
|
||||
|
||||
@Override
|
||||
public void endNode( int ilon, int ilat )
|
||||
public void end()
|
||||
{
|
||||
checkSegment( lonLast, latLast, ilon, ilat );
|
||||
checkSegment( lonLast, latLast, lonTarget, latTarget );
|
||||
if ( anyUpdate )
|
||||
{
|
||||
for ( MatchedWaypoint mwp : waypoints )
|
||||
|
|
@ -132,7 +149,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher
|
|||
{
|
||||
mwp.hasUpdate = false;
|
||||
mwp.node1 = new OsmNode( lonStart, latStart );
|
||||
mwp.node2 = new OsmNode( ilon, ilat );
|
||||
mwp.node2 = new OsmNode( lonTarget, latTarget );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue