change use of direct routing

This commit is contained in:
afischerdev 2022-12-05 11:50:52 +01:00
parent 3e53659f18
commit d67b3c0ec9
4 changed files with 41 additions and 15 deletions

View file

@ -292,16 +292,16 @@ public class RoutingEngine extends Thread {
private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) { private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
OsmTrack totaltrack = new OsmTrack(); OsmTrack totaltrack = new OsmTrack();
int nUnmatched = waypoints.size(); int nUnmatched = waypoints.size();
boolean hasDirectRouting = false;
if (hasInfo()) { for (OsmNodeNamed wp : waypoints) {
for (OsmNodeNamed wp : waypoints) { if (hasInfo()) logInfo("wp=" + wp + (wp.direct ? " direct" : ""));
logInfo("wp=" + wp); if (wp.direct) hasDirectRouting = true;
}
} }
// check for a track for that target // check for a track for that target
OsmTrack nearbyTrack = null; OsmTrack nearbyTrack = null;
if (lastTracks[waypoints.size() - 2] == null) { if (!hasDirectRouting && lastTracks[waypoints.size() - 2] == null) {
StringBuilder debugInfo = hasInfo() ? new StringBuilder() : null; StringBuilder debugInfo = hasInfo() ? new StringBuilder() : null;
nearbyTrack = OsmTrack.readBinary(routingContext.rawTrackPath, waypoints.get(waypoints.size() - 1), routingContext.getNogoChecksums(), routingContext.profileTimestamp, debugInfo); nearbyTrack = OsmTrack.readBinary(routingContext.rawTrackPath, waypoints.get(waypoints.size() - 1), routingContext.getNogoChecksums(), routingContext.profileTimestamp, debugInfo);
if (nearbyTrack != null) { if (nearbyTrack != null) {
@ -314,13 +314,13 @@ public class RoutingEngine extends Thread {
} }
} }
if (matchedWaypoints == null) // could exist from the previous alternative level if (matchedWaypoints == null) { // could exist from the previous alternative level
{
matchedWaypoints = new ArrayList<MatchedWaypoint>(); matchedWaypoints = new ArrayList<MatchedWaypoint>();
for (int i = 0; i < nUnmatched; i++) { for (int i = 0; i < nUnmatched; i++) {
MatchedWaypoint mwp = new MatchedWaypoint(); MatchedWaypoint mwp = new MatchedWaypoint();
mwp.waypoint = waypoints.get(i); mwp.waypoint = waypoints.get(i);
mwp.name = waypoints.get(i).name; mwp.name = waypoints.get(i).name;
mwp.direct = waypoints.get(i).direct;
matchedWaypoints.add(mwp); matchedWaypoints.add(mwp);
} }
matchWaypointsToNodes(matchedWaypoints); matchWaypointsToNodes(matchedWaypoints);
@ -330,6 +330,7 @@ public class RoutingEngine extends Thread {
airDistanceCostFactor = 0.; airDistanceCostFactor = 0.;
for (int i = 0; i < matchedWaypoints.size() - 1; i++) { for (int i = 0; i < matchedWaypoints.size() - 1; i++) {
nodeLimit = MAXNODES_ISLAND_CHECK; nodeLimit = MAXNODES_ISLAND_CHECK;
if (matchedWaypoints.get(i).direct) continue;
if (routingContext.inverseRouting) { if (routingContext.inverseRouting) {
OsmTrack seg = findTrack("start-island-check", matchedWaypoints.get(i), matchedWaypoints.get(i + 1), null, null, false); OsmTrack seg = findTrack("start-island-check", matchedWaypoints.get(i), matchedWaypoints.get(i + 1), null, null, false);
if (seg == null && nodeLimit > 0) { if (seg == null && nodeLimit > 0) {
@ -383,10 +384,7 @@ public class RoutingEngine extends Thread {
private OsmTrack searchTrack(MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack) { private OsmTrack searchTrack(MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack) {
// remove nogos with waypoints inside // remove nogos with waypoints inside
try { try {
List<OsmNode> wpts2 = new ArrayList<OsmNode>(); boolean calcBeeline = startWp.direct;
wpts2.add(startWp.waypoint);
wpts2.add(endWp.waypoint);
boolean calcBeeline = routingContext.allInOneNogo(wpts2);
if (!calcBeeline) return searchRoutedTrack(startWp, endWp, nearbyTrack, refTrack); if (!calcBeeline) return searchRoutedTrack(startWp, endWp, nearbyTrack, refTrack);

View file

@ -290,9 +290,20 @@ public final class NodesCache {
if (first_file_access_failed) { if (first_file_access_failed) {
throw new IllegalArgumentException("datafile " + first_file_access_name + " not found"); throw new IllegalArgumentException("datafile " + first_file_access_name + " not found");
} }
for (MatchedWaypoint mwp : unmatchedWaypoints) { int len = unmatchedWaypoints.size();
for (int i = 0; i < len; i++) {
MatchedWaypoint mwp = unmatchedWaypoints.get(i);
if (mwp.crosspoint == null) { if (mwp.crosspoint == null) {
throw new IllegalArgumentException(mwp.name + "-position not mapped in existing datafile"); if (unmatchedWaypoints.size() > 1 && i == unmatchedWaypoints.size()-1 && unmatchedWaypoints.get(i-1).direct) {
mwp.crosspoint = new OsmNode(mwp.waypoint.ilon, mwp.waypoint.ilat);
mwp.direct = true;
} else {
throw new IllegalArgumentException(mwp.name + "-position not mapped in existing datafile");
}
}
if (unmatchedWaypoints.size() > 1 && i == unmatchedWaypoints.size()-1 && unmatchedWaypoints.get(i-1).direct) {
mwp.crosspoint = new OsmNode(mwp.waypoint.ilon, mwp.waypoint.ilat);
mwp.direct = true;
} }
} }
} }

View file

@ -25,7 +25,7 @@ public class OsmNode extends OsmLink implements OsmPos {
/** /**
* The elevation * The elevation
*/ */
public short selev; public short selev = Short.MIN_VALUE;
/** /**
* The node-tags, if any * The node-tags, if any

View file

@ -46,7 +46,24 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
if (d == 0.) if (d == 0.)
return; return;
for (MatchedWaypoint mwp : waypoints) { int len = waypoints.size();
for (int i = 0; i < len; i++) {
MatchedWaypoint mwp = waypoints.get(i);
if (mwp.direct &&
(i == 0 ||
waypoints.get(i - 1).direct)
) {
if (mwp.crosspoint == null) {
mwp.crosspoint = new OsmNode();
mwp.crosspoint.ilon = mwp.waypoint.ilon;
mwp.crosspoint.ilat = mwp.waypoint.ilat;
mwp.hasUpdate = true;
anyUpdate = true;
}
continue;
}
OsmNode wp = mwp.waypoint; OsmNode wp = mwp.waypoint;
double x1 = (lon1 - wp.ilon) * dlon2m; double x1 = (lon1 - wp.ilon) * dlon2m;