Remove unused traffic simulation code

This commit is contained in:
ulteq 2024-05-11 19:52:26 +02:00
parent 8270ae6638
commit 2a94b7f300
10 changed files with 19 additions and 432 deletions

View file

@ -524,7 +524,7 @@ public class FormatGpx extends Formatter {
idx2 += 6;
int idx3 = line.indexOf('"', idx2);
int ilat = (int) ((Double.parseDouble(line.substring(idx2, idx3)) + 90.) * 1000000. + 0.5);
track.nodes.add(OsmPathElement.create(ilon, ilat, (short) 0, null, false));
track.nodes.add(OsmPathElement.create(ilon, ilat, (short) 0, null));
}
}
br.close();

View file

@ -5,8 +5,6 @@
*/
package btools.router;
import java.io.IOException;
import btools.mapaccess.OsmLink;
import btools.mapaccess.OsmLinkHolder;
import btools.mapaccess.OsmNode;
@ -33,8 +31,6 @@ abstract class OsmPath implements OsmLinkHolder {
public OsmPathElement originElement;
public OsmPathElement myElement;
protected float traffic;
private OsmLinkHolder nextForLink = null;
public int treedepth = 0;
@ -72,25 +68,6 @@ abstract class OsmPath implements OsmLinkHolder {
public MessageData message;
public void unregisterUpTree(RoutingContext rc) {
try {
OsmPathElement pe = originElement;
while (pe instanceof OsmPathElementWithTraffic && ((OsmPathElementWithTraffic) pe).unregister(rc)) {
pe = pe.origin;
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public void registerUpTree() {
if (originElement instanceof OsmPathElementWithTraffic) {
OsmPathElementWithTraffic ot = (OsmPathElementWithTraffic) originElement;
ot.register();
ot.addTraffic(traffic);
}
}
public void init(OsmLink link) {
this.link = link;
targetNode = link.getTarget(null);
@ -102,7 +79,7 @@ abstract class OsmPath implements OsmLinkHolder {
public void init(OsmPath origin, OsmLink link, OsmTrack refTrack, boolean detailMode, RoutingContext rc) {
if (origin.myElement == null) {
origin.myElement = OsmPathElement.create(origin, rc.countTraffic);
origin.myElement = OsmPathElement.create(origin);
}
this.originElement = origin.myElement;
this.link = link;
@ -143,7 +120,7 @@ abstract class OsmPath implements OsmLinkHolder {
return;
}
boolean recordTransferNodes = detailMode || rc.countTraffic;
boolean recordTransferNodes = detailMode;
rc.nogoCost = 0.;
@ -272,7 +249,7 @@ abstract class OsmPath implements OsmLinkHolder {
if (recordTransferNodes) {
if (rc.wayfraction > 0.) {
ele1 = interpolateEle(ele1, ele2, 1. - rc.wayfraction);
originElement = OsmPathElement.create(rc.ilonshortest, rc.ilatshortest, ele1, null, rc.countTraffic);
originElement = OsmPathElement.create(rc.ilonshortest, rc.ilatshortest, ele1, null);
} else {
originElement = null; // prevent duplicate point
}
@ -333,13 +310,6 @@ abstract class OsmPath implements OsmLinkHolder {
cost += (int) sectionCost;
// calculate traffic
if (rc.countTraffic) {
int minDist = (int) rc.trafficSourceMinDist;
int cost2 = cost < minDist ? minDist : cost;
traffic += dist * rc.expctxWay.getTrafficSourceDensity() * Math.pow(cost2 / 10000.f, rc.trafficSourceExponent);
}
// compute kinematic
computeKinematic(rc, dist, delta_h, detailMode);
@ -357,7 +327,7 @@ abstract class OsmPath implements OsmLinkHolder {
if (stopAtEndpoint) {
if (recordTransferNodes) {
originElement = OsmPathElement.create(rc.ilonshortest, rc.ilatshortest, originEle2, originElement, rc.countTraffic);
originElement = OsmPathElement.create(rc.ilonshortest, rc.ilatshortest, originEle2, originElement);
originElement.cost = cost;
if (message != null) {
originElement.message = message;
@ -383,10 +353,8 @@ abstract class OsmPath implements OsmLinkHolder {
transferNode = transferNode.next;
if (recordTransferNodes) {
originElement = OsmPathElement.create(lon2, lat2, originEle2, originElement, rc.countTraffic);
originElement = OsmPathElement.create(lon2, lat2, originEle2, originElement);
originElement.cost = cost;
originElement.addTraffic(traffic);
traffic = 0;
}
lon0 = lon1;
lat0 = lat1;

View file

@ -81,16 +81,16 @@ public class OsmPathElement implements OsmPos {
public OsmPathElement origin;
// construct a path element from a path
public static final OsmPathElement create(OsmPath path, boolean countTraffic) {
public static final OsmPathElement create(OsmPath path) {
OsmNode n = path.getTargetNode();
OsmPathElement pe = create(n.getILon(), n.getILat(), n.getSElev(), path.originElement, countTraffic);
OsmPathElement pe = create(n.getILon(), n.getILat(), n.getSElev(), path.originElement);
pe.cost = path.cost;
pe.message = path.message;
return pe;
}
public static final OsmPathElement create(int ilon, int ilat, short selev, OsmPathElement origin, boolean countTraffic) {
OsmPathElement pe = countTraffic ? new OsmPathElementWithTraffic() : new OsmPathElement();
public static final OsmPathElement create(int ilon, int ilat, short selev, OsmPathElement origin) {
OsmPathElement pe = new OsmPathElement();
pe.ilon = ilon;
pe.ilat = ilat;
pe.selev = selev;
@ -101,9 +101,6 @@ public class OsmPathElement implements OsmPos {
protected OsmPathElement() {
}
public void addTraffic(float traffic) {
}
public String toString() {
return ilon + "_" + ilat;
}

View file

@ -1,68 +0,0 @@
package btools.router;
import java.io.IOException;
/**
* Extension to OsmPathElement to count traffic load
*
* @author ab
*/
public final class OsmPathElementWithTraffic extends OsmPathElement {
private int registerCount;
private float farTraffic;
private float nearTraffic;
public void register() {
if (registerCount++ == 0) {
if (origin instanceof OsmPathElementWithTraffic) {
OsmPathElementWithTraffic ot = (OsmPathElementWithTraffic) origin;
ot.register();
ot.farTraffic += farTraffic;
ot.nearTraffic += nearTraffic;
farTraffic = 0;
nearTraffic = 0;
}
}
}
@Override
public void addTraffic(float traffic) {
this.farTraffic += traffic;
this.nearTraffic += traffic;
}
// unregister from origin if our registercount is 0, else do nothing
public static double maxtraffic = 0.;
public boolean unregister(RoutingContext rc) throws IOException {
if (--registerCount == 0) {
if (origin instanceof OsmPathElementWithTraffic) {
OsmPathElementWithTraffic ot = (OsmPathElementWithTraffic) origin;
int costdelta = cost - ot.cost;
ot.farTraffic += farTraffic * Math.exp(-costdelta / rc.farTrafficDecayLength);
ot.nearTraffic += nearTraffic * Math.exp(-costdelta / rc.nearTrafficDecayLength);
if (costdelta > 0 && farTraffic > maxtraffic) maxtraffic = farTraffic;
int t2 = cost == ot.cost ? -1 : (int) (rc.farTrafficWeight * farTraffic + rc.nearTrafficWeight * nearTraffic);
if (t2 > 4000 || t2 == -1) {
// System.out.println( "unregistered: " + this + " origin=" + ot + " farTraffic =" + farTraffic + " nearTraffic =" + nearTraffic + " cost=" + cost );
if (rc.trafficOutputStream != null) {
rc.trafficOutputStream.writeLong(getIdFromPos());
rc.trafficOutputStream.writeLong(ot.getIdFromPos());
rc.trafficOutputStream.writeInt(t2);
}
}
farTraffic = 0;
nearTraffic = 0;
}
return true;
}
return false;
}
}

View file

@ -5,7 +5,6 @@
*/
package btools.router;
import java.io.DataOutput;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -141,14 +140,6 @@ public final class RoutingContext {
starttimeoffset = expctxGlobal.getVariableValue("starttimeoffset", 0.f);
transitonly = expctxGlobal.getVariableValue("transitonly", 0.f) != 0.f;
farTrafficWeight = expctxGlobal.getVariableValue("farTrafficWeight", 2.f);
nearTrafficWeight = expctxGlobal.getVariableValue("nearTrafficWeight", 2.f);
farTrafficDecayLength = expctxGlobal.getVariableValue("farTrafficDecayLength", 30000.f);
nearTrafficDecayLength = expctxGlobal.getVariableValue("nearTrafficDecayLength", 3000.f);
trafficDirectionFactor = expctxGlobal.getVariableValue("trafficDirectionFactor", 0.9f);
trafficSourceExponent = expctxGlobal.getVariableValue("trafficSourceExponent", -0.7f);
trafficSourceMinDist = expctxGlobal.getVariableValue("trafficSourceMinDist", 3000.f);
showspeed = 0.f != expctxGlobal.getVariableValue("showspeed", 0.f);
showSpeedProfile = 0.f != expctxGlobal.getVariableValue("showSpeedProfile", 0.f);
inverseRouting = 0.f != expctxGlobal.getVariableValue("inverseRouting", 0.f);
@ -199,17 +190,7 @@ public final class RoutingContext {
public int ilatshortest;
public int ilonshortest;
public boolean countTraffic;
public boolean inverseDirection;
public DataOutput trafficOutputStream;
public double farTrafficWeight;
public double nearTrafficWeight;
public double farTrafficDecayLength;
public double nearTrafficDecayLength;
public double trafficDirectionFactor;
public double trafficSourceExponent;
public double trafficSourceMinDist;
public boolean showspeed;
public boolean showSpeedProfile;

View file

@ -1279,7 +1279,6 @@ public class RoutingEngine extends Thread {
}
if (path.airdistance == -1) {
path.unregisterUpTree(routingContext);
continue;
}
@ -1347,7 +1346,6 @@ public class RoutingEngine extends Thread {
OsmNode currentNode = path.getTargetNode();
if (currentLink.isLinkUnused()) {
path.unregisterUpTree(routingContext);
continue;
}
@ -1390,7 +1388,7 @@ public class RoutingEngine extends Thread {
+ path.elevationCorrection()
+ (costCuttingTrack.cost - pe.cost);
if (costEstimate <= maxTotalCost) {
matchPath = OsmPathElement.create(path, routingContext.countTraffic);
matchPath = OsmPathElement.create(path);
}
if (costEstimate < maxTotalCost) {
logInfo("maxcost " + maxTotalCost + " -> " + costEstimate);
@ -1400,7 +1398,6 @@ public class RoutingEngine extends Thread {
}
}
int keepPathAirdistance = path.airdistance;
OsmLinkHolder firstLinkHolder = currentLink.getFirstLinkHolder(sourceNode);
for (OsmLinkHolder linkHolder = firstLinkHolder; linkHolder != null; linkHolder = linkHolder.getNextForLink()) {
((OsmPath) linkHolder).airdistance = -1; // invalidate the entry in the open set;
@ -1419,7 +1416,6 @@ public class RoutingEngine extends Thread {
// recheck cutoff before doing expensive stuff
int addDiff = 100;
if (path.cost + path.airdistance > maxTotalCost + addDiff) {
path.unregisterUpTree(routingContext);
continue;
}
@ -1474,7 +1470,7 @@ public class RoutingEngine extends Thread {
if (routingContext.turnInstructionMode > 0) {
OsmPath detour = routingContext.createPath(path, link, refTrack, true);
if (detour.cost >= 0. && nextId != startNodeId1 && nextId != startNodeId2) {
guideTrack.registerDetourForId(currentNode.getIdFromPos(), OsmPathElement.create(detour, false));
guideTrack.registerDetourForId(currentNode.getIdFromPos(), OsmPathElement.create(detour));
}
}
continue;
@ -1510,16 +1506,14 @@ public class RoutingEngine extends Thread {
}
}
if (bestPath != null) {
boolean trafficSim = endPos == null;
bestPath.airdistance = trafficSim ? keepPathAirdistance : (isFinalLink ? 0 : nextNode.calcDistance(endPos));
bestPath.airdistance = isFinalLink ? 0 : nextNode.calcDistance(endPos);
boolean inRadius = boundary == null || boundary.isInBoundary(nextNode, bestPath.cost);
if (inRadius && (isFinalLink || bestPath.cost + bestPath.airdistance <= (lastAirDistanceCostFactor != 0. ? maxTotalCost * lastAirDistanceCostFactor : maxTotalCost) + addDiff)) {
// add only if this may beat an existing path for that link
OsmLinkHolder dominator = link.getFirstLinkHolder(currentNode);
while (!trafficSim && dominator != null) {
while (dominator != null) {
OsmPath dp = (OsmPath) dominator;
if (dp.airdistance != -1 && bestPath.definitlyWorseThan(dp)) {
break;
@ -1528,9 +1522,6 @@ public class RoutingEngine extends Thread {
}
if (dominator == null) {
if (trafficSim && boundary != null && path.cost == 0 && bestPath.cost > 0) {
bestPath.airdistance += boundary.getBoundaryDistance(nextNode);
}
bestPath.treedepth = path.treedepth + 1;
link.addLinkHolder(bestPath, currentNode);
addToOpenset(bestPath);
@ -1538,8 +1529,6 @@ public class RoutingEngine extends Thread {
}
}
}
path.unregisterUpTree(routingContext);
}
}
@ -1553,12 +1542,11 @@ public class RoutingEngine extends Thread {
private void addToOpenset(OsmPath path) {
if (path.cost >= 0) {
openSet.add(path.cost + (int) (path.airdistance * airDistanceCostFactor), path);
path.registerUpTree();
}
}
private OsmTrack compileTrack(OsmPath path, boolean verbose) {
OsmPathElement element = OsmPathElement.create(path, false);
OsmPathElement element = OsmPathElement.create(path);
// for final track, cut endnode
if (guideTrack != null && element.origin != null) {