Skip to content

Commit

Permalink
bee-line patch: Nogo covering 2 Waypoints triggers a beeline segment
Browse files Browse the repository at this point in the history
  • Loading branch information
abrensch committed Mar 31, 2021
1 parent 372a04a commit eb71650
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
5 changes: 4 additions & 1 deletion brouter-core/src/main/java/btools/router/OsmPath.java
Expand Up @@ -139,7 +139,10 @@ public void init( OsmPath origin, OsmLink link, OsmTrack refTrack, boolean detai
protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath origin, OsmLink link, RoutingContext rc )
{
byte[] description = link.descriptionBitmap;
if ( description == null ) throw new IllegalArgumentException( "null description for: " + link );
if ( description == null )
{
return; // could be a beeline path
}

boolean recordTransferNodes = detailMode || rc.countTraffic;

Expand Down
47 changes: 44 additions & 3 deletions brouter-core/src/main/java/btools/router/RoutingContext.java
Expand Up @@ -16,6 +16,7 @@
import btools.expressions.BExpressionContextWay;
import btools.mapaccess.GeometryDecoder;
import btools.mapaccess.OsmLink;
import btools.mapaccess.OsmNode;
import btools.util.CheapAngleMeter;
import btools.util.CheapRuler;

Expand Down Expand Up @@ -191,6 +192,7 @@ public void readGlobalConfig()
public List<OsmNodeNamed> poipoints;

public List<OsmNodeNamed> nogopoints = null;
private List<OsmNodeNamed> nogopoints_all = null; // full list not filtered for wayoints-in-nogos
private List<OsmNodeNamed> keepnogopoints = null;
private OsmNodeNamed pendingEndpoint = null;

Expand Down Expand Up @@ -258,14 +260,29 @@ public static void prepareNogoPoints( List<OsmNodeNamed> nogos )
}
}

public void cleanNogolist( List<OsmNodeNamed> waypoints )
/**
* restore the full nogolist previously saved by cleanNogoList
*/
public void restoreNogoList()
{
nogopoints = nogopoints_all;
}

/**
* clean the nogolist (previoulsy saved by saveFullNogolist())
* by removing nogos with waypoints within
*
* @return true if all wayoints are all in the same (full-weigth) nogo area (triggering bee-line-mode)
*/
public void cleanNogoList( List<OsmNode> waypoints )
{
nogopoints_all = nogopoints;
if ( nogopoints == null ) return;
List<OsmNodeNamed> nogos = new ArrayList<OsmNodeNamed>();
for( OsmNodeNamed nogo : nogopoints )
{
boolean goodGuy = true;
for( OsmNodeNamed wp : waypoints )
for( OsmNode wp : waypoints )
{
if ( wp.calcDistance( nogo ) < nogo.radius
&& (!(nogo instanceof OsmNogoPolygon)
Expand All @@ -274,14 +291,38 @@ public void cleanNogolist( List<OsmNodeNamed> waypoints )
: ((OsmNogoPolygon)nogo).isOnPolyline(wp.ilon, wp.ilat))))
{
goodGuy = false;
break;
}
}
if ( goodGuy ) nogos.add( nogo );
}
nogopoints = nogos.isEmpty() ? null : nogos;
}

public boolean allInOneNogo( List<OsmNode> waypoints )
{
if ( nogopoints == null ) return false;
boolean allInTotal = false;
for( OsmNodeNamed nogo : nogopoints )
{
boolean allIn = Double.isNaN( nogo.nogoWeight );
for( OsmNode wp : waypoints )
{
int dist = wp.calcDistance( nogo );
if ( dist < nogo.radius
&& (!(nogo instanceof OsmNogoPolygon)
|| (((OsmNogoPolygon)nogo).isClosed
? ((OsmNogoPolygon)nogo).isWithin(wp.ilon, wp.ilat)
: ((OsmNogoPolygon)nogo).isOnPolyline(wp.ilon, wp.ilat))))
{
continue;
}
allIn = false;
}
allInTotal |= allIn;
}
return allInTotal;
}

public long[] getNogoChecksums()
{
long[] cs = new long[3];
Expand Down
32 changes: 29 additions & 3 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Expand Up @@ -151,9 +151,6 @@ public void doRun( long maxRunningTime )
{
try
{
// delete nogos with waypoints in them
routingContext.cleanNogolist( waypoints );

startTime = System.currentTimeMillis();
long startTime0 = startTime;
this.maxRunningTime = maxRunningTime;
Expand Down Expand Up @@ -459,6 +456,29 @@ private void matchWaypointsToNodes( List<MatchedWaypoint> unmatchedWaypoints )
}

private OsmTrack searchTrack( MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack )
{
// remove nogos with waypoints inside
try
{
List<OsmNode> wpts2 = new ArrayList<OsmNode>();
wpts2.add( startWp.waypoint );
wpts2.add( endWp.waypoint );
boolean calcBeeline = routingContext.allInOneNogo(wpts2);

if ( !calcBeeline ) return searchRoutedTrack( startWp, endWp, nearbyTrack, refTrack );

// we want a beeline-segment
OsmPath path = routingContext.createPath( new OsmLink( null, startWp.crosspoint ) );
path = routingContext.createPath( path, new OsmLink( startWp.crosspoint, endWp.crosspoint ), null, false );
return compileTrack( path, false );
}
finally
{
routingContext.restoreNogoList();
}
}

private OsmTrack searchRoutedTrack( MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack )
{
OsmTrack track = null;
double[] airDistanceCostFactors = new double[]{ routingContext.pass1coefficient, routingContext.pass2coefficient };
Expand Down Expand Up @@ -650,13 +670,19 @@ private OsmTrack findTrack( String operationName, MatchedWaypoint startWp, Match
{
try
{
List<OsmNode> wpts2 = new ArrayList<OsmNode>();
if ( startWp != null ) wpts2.add( startWp.waypoint );
if ( endWp != null ) wpts2.add( endWp.waypoint );
routingContext.cleanNogoList(wpts2);

boolean detailed = guideTrack != null;
resetCache( detailed );
nodesCache.nodesMap.cleanupMode = detailed ? 0 : ( routingContext.considerTurnRestrictions ? 2 : 1 );
return _findTrack( operationName, startWp, endWp, costCuttingTrack, refTrack, fastPartialRecalc );
}
finally
{
routingContext.restoreNogoList();
nodesCache.clean( false ); // clean only non-virgin caches
}
}
Expand Down

0 comments on commit eb71650

Please sign in to comment.