new round trip function

This commit is contained in:
afischerdev 2025-02-09 10:41:47 +01:00
parent 0b5df946b9
commit 9fd52f02d3

View File

@ -50,7 +50,7 @@ public class RoutingEngine extends Thread {
private int engineMode = 0;
private int MAX_STEPS_CHECK = 250;
private int MAX_STEPS_CHECK = 500;
private int ROUNDTRIP_DEFAULT_DIRECTIONADD = 45;
@ -496,41 +496,11 @@ public class RoutingEngine extends Thread {
wpt2.name = "rt1_" + direction;
OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "via1";
onn.name = "rt1";
waypoints.add(onn);
} else {
int[] pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius, direction-directionAdd);
MatchedWaypoint wpt2 = new MatchedWaypoint();
wpt2.waypoint = new OsmNode(pos[0], pos[1]);
wpt2.name = "via1_" + (int) (direction-directionAdd);
OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "via1";
waypoints.add(onn);
pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius, direction+directionAdd);
MatchedWaypoint wpt3 = new MatchedWaypoint();
wpt3.waypoint = new OsmNode(pos[0], pos[1]);
wpt3.name = "via2_" + (int) (direction+directionAdd);
onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "via2";
waypoints.add(onn);
pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius/2, direction);
OsmNodeNamed n = new OsmNodeNamed();
n.name = "nogo" + (int) (searchRadius/3);
n.ilon = pos[0];
n.ilat = pos[1];
n.isNogo = true;
n.radius = (int) (searchRadius/3);
n.nogoWeight = Double.NaN;
routingContext.setWaypoint(n, false);
onn = new OsmNodeNamed(waypoints.get(0));
onn.name = "to_rt";
waypoints.add(onn);
//buildPointsFromAngle(waypoints, direction, directionAdd, searchRadius, true);
buildPointsFromCircle(waypoints, direction, searchRadius, 5);
}
routingContext.waypointCatchingRange = 1000;
@ -546,6 +516,50 @@ public class RoutingEngine extends Thread {
}
void buildPointsFromAngle(List<OsmNodeNamed> waypoints, double startAngle, double addAngle, double searchRadius, boolean withNogoCenter) {
int[] pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius, startAngle - addAngle);
OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "rt1";
waypoints.add(onn);
pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius, startAngle + addAngle);
onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "rt2";
waypoints.add(onn);
onn = new OsmNodeNamed(waypoints.get(0));
onn.name = "to_rt";
waypoints.add(onn);
if (withNogoCenter) { // add a nogo area
pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius/2, startAngle);
OsmNodeNamed n = new OsmNodeNamed();
n.name = "nogo" + (int) (searchRadius/3);
n.ilon = pos[0];
n.ilat = pos[1];
n.isNogo = true;
n.radius = (int) (searchRadius/3);
n.nogoWeight = Double.NaN;
routingContext.setWaypoint(n, false);
}
}
void buildPointsFromCircle(List<OsmNodeNamed> waypoints, double startAngle, double searchRadius, int points) {
//startAngle -= 90;
for (int i = 1; i < points; i++) {
double anAngle = 90 - (180.0 * i / points);
int[] pos = CheapRuler.destination(waypoints.get(0).ilon, waypoints.get(0).ilat, searchRadius, startAngle - anAngle);
OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "rt" + i;
waypoints.add(onn);
}
OsmNodeNamed onn = new OsmNodeNamed(waypoints.get(0));
onn.name = "to_rt";
waypoints.add(onn);
}
private void postElevationCheck(OsmTrack track) {
OsmPathElement lastPt = null;
OsmPathElement startPt = null;
@ -793,7 +807,8 @@ public class RoutingEngine extends Thread {
}
for (MatchedWaypoint mwp : matchedWaypoints) {
if (hasInfo() && matchedWaypoints.size() != nUnmatched) logInfo("new wp=" + mwp.waypoint + " " + mwp.crosspoint + (mwp.direct ? " direct" : ""));
if (hasInfo() && matchedWaypoints.size() != nUnmatched)
logInfo("new wp=" + mwp.waypoint + " " + mwp.crosspoint + (mwp.direct ? " direct" : ""));
}
routingContext.checkMatchedWaypointAgainstNogos(matchedWaypoints);
@ -884,7 +899,7 @@ public class RoutingEngine extends Thread {
// check for way back on way point
private boolean snappPathConnection(OsmTrack tt, OsmTrack t, MatchedWaypoint startWp) {
if (!startWp.name.startsWith("via"))
if (!startWp.name.startsWith("via") && !startWp.name.startsWith("rt"))
return false;
int ourSize = tt.nodes.size();
@ -1188,7 +1203,8 @@ public class RoutingEngine extends Thread {
range = -MAX_DYNAMIC_RANGE;
List<MatchedWaypoint> tmp = new ArrayList<>();
for (MatchedWaypoint mwp : unmatchedWaypoints) {
if (mwp.crosspoint == null || mwp.radius >= routingContext.waypointCatchingRange) tmp.add(mwp);
if (mwp.crosspoint == null || mwp.radius >= routingContext.waypointCatchingRange)
tmp.add(mwp);
}
ok = nodesCache.matchWaypointsToNodes(tmp, range, islandNodePairs);
}
@ -1199,12 +1215,12 @@ public class RoutingEngine extends Thread {
}
}
// add beeline points when not already done
if (useDynamicDistance && !useNodePoints) {
if (useDynamicDistance && !useNodePoints && engineMode != BROUTER_ENGINEMODE_ROUNDTRIP) {
List<MatchedWaypoint> waypoints = new ArrayList<>();
for (int i = 0; i < unmatchedWaypoints.size(); i++) {
MatchedWaypoint wp = unmatchedWaypoints.get(i);
if (wp.waypoint.calcDistance(wp.crosspoint) > routingContext.waypointCatchingRange) {
if (engineMode != BROUTER_ENGINEMODE_ROUNDTRIP) {
MatchedWaypoint nmw = new MatchedWaypoint();
if (i == 0) {
OsmNodeNamed onn = new OsmNodeNamed(wp.waypoint);
@ -1250,13 +1266,20 @@ public class RoutingEngine extends Thread {
} else {
waypoints.add(wp);
}
} else {
waypoints.add(wp);
}
}
unmatchedWaypoints.clear();
unmatchedWaypoints.addAll(waypoints);
}
// round trip cross point to way point
if (engineMode == BROUTER_ENGINEMODE_ROUNDTRIP) {
for (int i = 1; i < unmatchedWaypoints.size()-1; i++) {
MatchedWaypoint wp = unmatchedWaypoints.get(i);
wp.waypoint.ilon = wp.crosspoint.ilon;
wp.waypoint.ilat = wp.crosspoint.ilat;
}
}
}
private OsmTrack searchTrack(MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack) {