Skip to content

Commit

Permalink
added a second chance to waypoints - beeline
Browse files Browse the repository at this point in the history
  • Loading branch information
afischerdev committed Dec 13, 2024
1 parent b9b0e21 commit 2712777
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public class RoutingEngine extends Thread {
private boolean finished = false;

protected List<OsmNodeNamed> waypoints = null;
List<OsmNodeNamed> extraWaypoints = null;
protected List<MatchedWaypoint> matchedWaypoints;
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);
private boolean useNodePoints = false; // use the start/end nodes instead of crosspoint

private int engineMode = 0;

Expand Down Expand Up @@ -548,6 +550,20 @@ private OsmTrack findTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
try {
return tryFindTrack(refTracks, lastTracks);
} catch (RoutingIslandException rie) {
if (routingContext.useDynamicDistance) {
useNodePoints = true;
boolean useNodeOne = true;
if (extraWaypoints != null) useNodeOne = false;
extraWaypoints = new ArrayList<>();
for (MatchedWaypoint mwp : matchedWaypoints) {
if (mwp.name.contains("_add")) {
OsmNodeNamed wp = new OsmNodeNamed(useNodeOne ? mwp.node1 : mwp.node1);
wp.name = mwp.name;
wp.direct = mwp.direct;
extraWaypoints.add(wp);
}
}
}
islandNodePairs.freezeTempPairs();
nodesCache.clean(true);
matchedWaypoints = null;
Expand All @@ -560,6 +576,26 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
int nUnmatched = waypoints.size();
boolean hasDirectRouting = false;

if (useNodePoints && extraWaypoints != null) {
// add extra waypoints from the last broken round
for (OsmNodeNamed wp : extraWaypoints) {
if (wp.direct) hasDirectRouting = true;
if (wp.name.startsWith("from")) {
waypoints.add(1, wp);
waypoints.get(0).direct = true;
nUnmatched++;
} else {
waypoints.add(waypoints.size()-1, wp);
waypoints.get(waypoints.size()-2).direct = true;
nUnmatched++;
}
}
}
if (lastTracks.length < waypoints.size()-1) {
refTracks = new OsmTrack[waypoints.size()-1]; // used ways for alternatives
lastTracks = new OsmTrack[waypoints.size()-1];
hasDirectRouting = true;
}
for (OsmNodeNamed wp : waypoints) {
if (hasInfo()) logInfo("wp=" + wp + (wp.direct ? " direct" : ""));
if (wp.direct) hasDirectRouting = true;
Expand Down

0 comments on commit 2712777

Please sign in to comment.