added distance check for dynamic range
This commit is contained in:
parent
a6ba70a786
commit
2f4c125bf5
@ -11,4 +11,6 @@ public interface WaypointMatcher {
|
|||||||
void transferNode(int ilon, int ilat);
|
void transferNode(int ilon, int ilat);
|
||||||
|
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
boolean hasMatch(int lon, int lat);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,8 @@ public class RoutingEngine extends Thread {
|
|||||||
|
|
||||||
private int MAX_STEPS_CHECK = 10;
|
private int MAX_STEPS_CHECK = 10;
|
||||||
|
|
||||||
|
private int MAX_DYNAMIC_RANGE = 60000;
|
||||||
|
|
||||||
protected OsmTrack foundTrack = new OsmTrack();
|
protected OsmTrack foundTrack = new OsmTrack();
|
||||||
private OsmTrack foundRawTrack = null;
|
private OsmTrack foundRawTrack = null;
|
||||||
private int alternativeIndex = 0;
|
private int alternativeIndex = 0;
|
||||||
@ -980,7 +982,7 @@ public class RoutingEngine extends Thread {
|
|||||||
if (!ok && useDynamicDistance) {
|
if (!ok && useDynamicDistance) {
|
||||||
logInfo("second check for way points");
|
logInfo("second check for way points");
|
||||||
resetCache(false);
|
resetCache(false);
|
||||||
range = -range;
|
range = -MAX_DYNAMIC_RANGE;
|
||||||
List<MatchedWaypoint> tmp = new ArrayList<>();
|
List<MatchedWaypoint> tmp = new ArrayList<>();
|
||||||
for (MatchedWaypoint mwp : unmatchedWaypoints) {
|
for (MatchedWaypoint mwp : unmatchedWaypoints) {
|
||||||
if (mwp.crosspoint == null) tmp.add(mwp);
|
if (mwp.crosspoint == null) tmp.add(mwp);
|
||||||
@ -1000,35 +1002,30 @@ public class RoutingEngine extends Thread {
|
|||||||
if (wp.waypoint.calcDistance(wp.crosspoint) > routingContext.waypointCatchingRange) {
|
if (wp.waypoint.calcDistance(wp.crosspoint) > routingContext.waypointCatchingRange) {
|
||||||
MatchedWaypoint nmw = new MatchedWaypoint();
|
MatchedWaypoint nmw = new MatchedWaypoint();
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
nmw.waypoint = new OsmNode(wp.waypoint.ilon, wp.waypoint.ilat);
|
OsmNodeNamed onn = new OsmNodeNamed(wp.waypoint);
|
||||||
|
onn.name = "from";
|
||||||
|
nmw.waypoint = onn;
|
||||||
|
nmw.name = onn.name;
|
||||||
nmw.crosspoint = new OsmNode(wp.waypoint.ilon, wp.waypoint.ilat);
|
nmw.crosspoint = new OsmNode(wp.waypoint.ilon, wp.waypoint.ilat);
|
||||||
nmw.direct = true;
|
nmw.direct = true;
|
||||||
wp.waypoint = new OsmNode(wp.crosspoint.ilon, wp.crosspoint.ilat);
|
onn = new OsmNodeNamed(wp.crosspoint);
|
||||||
|
onn.name = wp.name + "_add";
|
||||||
|
wp.waypoint = onn;
|
||||||
} else {
|
} else {
|
||||||
nmw.waypoint = new OsmNode(wp.crosspoint.ilon, wp.crosspoint.ilat);
|
OsmNodeNamed onn = new OsmNodeNamed(wp.crosspoint);
|
||||||
|
onn.name = wp.name + "_add";
|
||||||
|
nmw.waypoint = onn;
|
||||||
nmw.crosspoint = new OsmNode(wp.crosspoint.ilon, wp.crosspoint.ilat);
|
nmw.crosspoint = new OsmNode(wp.crosspoint.ilon, wp.crosspoint.ilat);
|
||||||
nmw.node1 = new OsmNode(wp.node1.ilon, wp.node1.ilat);
|
nmw.node1 = new OsmNode(wp.node1.ilon, wp.node1.ilat);
|
||||||
nmw.node2 = new OsmNode(wp.node2.ilon, wp.node2.ilat);
|
nmw.node2 = new OsmNode(wp.node2.ilon, wp.node2.ilat);
|
||||||
nmw.direct = true;
|
nmw.direct = true;
|
||||||
wp.crosspoint = new OsmNode(wp.waypoint.ilon, wp.waypoint.ilat);
|
wp.crosspoint = new OsmNode(wp.waypoint.ilon, wp.waypoint.ilat);
|
||||||
}
|
}
|
||||||
nmw.name = wp.name + "_1";
|
if (wp.name != null) nmw.name = wp.name;
|
||||||
waypoints.add(nmw);
|
waypoints.add(nmw);
|
||||||
waypoints.add(wp);
|
wp.name = wp.name + "_add";
|
||||||
if (wp.name.startsWith("via")) {
|
|
||||||
wp.direct = true;
|
|
||||||
MatchedWaypoint emw = new MatchedWaypoint();
|
|
||||||
emw.waypoint = new OsmNode(nmw.crosspoint.ilon, nmw.crosspoint.ilat);
|
|
||||||
emw.crosspoint = new OsmNode(nmw.crosspoint.ilon, nmw.crosspoint.ilat);
|
|
||||||
emw.node1 = new OsmNode(nmw.node1.ilon, nmw.node1.ilat);
|
|
||||||
emw.node2 = new OsmNode(nmw.node2.ilon, nmw.node2.ilat);
|
|
||||||
emw.direct = false;
|
|
||||||
emw.name = wp.name + "_2";
|
|
||||||
waypoints.add(emw);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
waypoints.add(wp);
|
|
||||||
}
|
}
|
||||||
|
waypoints.add(wp);
|
||||||
}
|
}
|
||||||
unmatchedWaypoints.clear();
|
unmatchedWaypoints.clear();
|
||||||
unmatchedWaypoints.addAll(waypoints);
|
unmatchedWaypoints.addAll(waypoints);
|
||||||
|
|||||||
@ -17,6 +17,9 @@ import btools.codec.WaypointMatcher;
|
|||||||
import btools.expressions.BExpressionContextWay;
|
import btools.expressions.BExpressionContextWay;
|
||||||
|
|
||||||
public final class NodesCache {
|
public final class NodesCache {
|
||||||
|
|
||||||
|
private int MAX_DYNAMIC_CATCHES = 20; // used with RoutingEngiine MAX_DYNAMIC_RANGE = 60000m
|
||||||
|
|
||||||
private File segmentDir;
|
private File segmentDir;
|
||||||
private File secondarySegmentsDir = null;
|
private File secondarySegmentsDir = null;
|
||||||
|
|
||||||
@ -287,11 +290,11 @@ public final class NodesCache {
|
|||||||
waypointMatcher = new WaypointMatcherImpl(unmatchedWaypoints, maxDistance, islandNodePairs);
|
waypointMatcher = new WaypointMatcherImpl(unmatchedWaypoints, maxDistance, islandNodePairs);
|
||||||
for (MatchedWaypoint mwp : unmatchedWaypoints) {
|
for (MatchedWaypoint mwp : unmatchedWaypoints) {
|
||||||
int cellsize = 12500;
|
int cellsize = 12500;
|
||||||
preloadPosition(mwp.waypoint, cellsize, 1);
|
preloadPosition(mwp.waypoint, cellsize, 1, false);
|
||||||
// get a second chance
|
// get a second chance
|
||||||
if (mwp.crosspoint == null || mwp.radius > Math.abs(maxDistance)) {
|
if (mwp.crosspoint == null || mwp.radius > Math.abs(maxDistance)) {
|
||||||
cellsize = 1000000 / 32;
|
cellsize = 1000000 / 32;
|
||||||
preloadPosition(mwp.waypoint, cellsize, maxDistance < 0 ? 15 : 2);
|
preloadPosition(mwp.waypoint, cellsize, maxDistance < 0 ? MAX_DYNAMIC_CATCHES : 2, maxDistance < 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,19 +321,24 @@ public final class NodesCache {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preloadPosition(OsmNode n, int d, int scale) {
|
private void preloadPosition(OsmNode n, int d, int maxscale, boolean bUseDynamicRange) {
|
||||||
first_file_access_failed = false;
|
first_file_access_failed = false;
|
||||||
first_file_access_name = null;
|
first_file_access_name = null;
|
||||||
loadSegmentFor(n.ilon, n.ilat);
|
loadSegmentFor(n.ilon, n.ilat);
|
||||||
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 (int idxLat = -scale; idxLat <= scale; idxLat++)
|
int scale = 1;
|
||||||
for (int idxLon = -scale; idxLon <= scale; idxLon++) {
|
while (scale < maxscale) {
|
||||||
if (idxLon != 0 || idxLat != 0) {
|
for (int idxLat = -scale; idxLat <= scale; idxLat++)
|
||||||
loadSegmentFor(n.ilon + d * idxLon, n.ilat + d * idxLat);
|
for (int idxLon = -scale; idxLon <= scale; idxLon++) {
|
||||||
|
if (idxLon != 0 || idxLat != 0) {
|
||||||
|
loadSegmentFor(n.ilon + d * idxLon, n.ilat + d * idxLat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (bUseDynamicRange && waypointMatcher.hasMatch(n.ilon, n.ilat)) break;
|
||||||
|
scale++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsmFile fileForSegment(int lonDegree, int latDegree) throws Exception {
|
private OsmFile fileForSegment(int lonDegree, int latDegree) throws Exception {
|
||||||
|
|||||||
@ -41,13 +41,13 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||||||
MatchedWaypoint last = null;
|
MatchedWaypoint last = null;
|
||||||
this.maxDistance = maxDistance;
|
this.maxDistance = maxDistance;
|
||||||
if (maxDistance < 0.) {
|
if (maxDistance < 0.) {
|
||||||
this.maxDistance = -1;
|
this.maxDistance *= -1;
|
||||||
maxDistance *= -1;
|
maxDistance *= -1;
|
||||||
useDynamicRange = true;
|
useDynamicRange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MatchedWaypoint mwp : waypoints) {
|
for (MatchedWaypoint mwp : waypoints) {
|
||||||
mwp.radius = useDynamicRange ? mwp.radius != maxDistance ? mwp.radius : -1 : maxDistance;
|
mwp.radius = maxDistance;
|
||||||
if (last != null && mwp.directionToNext == -1) {
|
if (last != null && mwp.directionToNext == -1) {
|
||||||
last.directionToNext = CheapAngleMeter.getDirection(last.waypoint.ilon, last.waypoint.ilat, mwp.waypoint.ilon, mwp.waypoint.ilat);
|
last.directionToNext = CheapAngleMeter.getDirection(last.waypoint.ilon, last.waypoint.ilat, mwp.waypoint.ilon, mwp.waypoint.ilat);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||||||
double r22 = x2 * x2 + y2 * y2;
|
double r22 = x2 * x2 + y2 * y2;
|
||||||
double radius = Math.abs(r12 < r22 ? y1 * dx - x1 * dy : y2 * dx - x2 * dy) / d;
|
double radius = Math.abs(r12 < r22 ? y1 * dx - x1 * dy : y2 * dx - x2 * dy) / d;
|
||||||
|
|
||||||
if (radius < mwp.radius || (this.maxDistance == -1d)) {
|
if (radius < mwp.radius) {
|
||||||
double s1 = x1 * dx + y1 * dy;
|
double s1 = x1 * dx + y1 * dy;
|
||||||
double s2 = x2 * dx + y2 * dy;
|
double s2 = x2 * dx + y2 * dy;
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||||||
if (s2 > 0.) {
|
if (s2 > 0.) {
|
||||||
radius = Math.sqrt(s1 < s2 ? r12 : r22);
|
radius = Math.sqrt(s1 < s2 ? r12 : r22);
|
||||||
|
|
||||||
if (radius > mwp.radius && mwp.radius != -1) {
|
if (radius > mwp.radius) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,6 +239,17 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMatch(int lon, int lat) {
|
||||||
|
for (MatchedWaypoint mwp : waypoints) {
|
||||||
|
if (mwp.waypoint.ilon == lon && mwp.waypoint.ilat == lat &&
|
||||||
|
(mwp.radius < this.maxDistance || mwp.crosspoint != null)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// check limit of list size (avoid long runs)
|
// check limit of list size (avoid long runs)
|
||||||
void updateWayList(List<MatchedWaypoint> ways, MatchedWaypoint mw) {
|
void updateWayList(List<MatchedWaypoint> ways, MatchedWaypoint mw) {
|
||||||
ways.add(mw);
|
ways.add(mw);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user