Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused traffic simulation code #697

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/FormatGpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public OsmTrack read(String filename) throws Exception {
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();
Expand Down
42 changes: 5 additions & 37 deletions brouter-core/src/main/java/btools/router/OsmPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package btools.router;

import java.io.IOException;

import btools.mapaccess.OsmLink;
import btools.mapaccess.OsmLinkHolder;
import btools.mapaccess.OsmNode;
Expand All @@ -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;
Expand Down Expand Up @@ -72,25 +68,6 @@ public boolean didEnterDestinationArea() {

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);
Expand All @@ -102,7 +79,7 @@ public void init(OsmLink link) {

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;
Expand Down Expand Up @@ -143,7 +120,7 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
return;
}

boolean recordTransferNodes = detailMode || rc.countTraffic;
boolean recordTransferNodes = detailMode;

rc.nogoCost = 0.;

Expand Down Expand Up @@ -272,7 +249,7 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
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
}
Expand Down Expand Up @@ -333,13 +310,6 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath

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);

Expand All @@ -357,7 +327,7 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath

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;
Expand All @@ -383,10 +353,8 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
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;
Expand Down
11 changes: 4 additions & 7 deletions brouter-core/src/main/java/btools/router/OsmPathElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public final int calcDistance(OsmPos p) {
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;
Expand All @@ -101,9 +101,6 @@ public static final OsmPathElement create(int ilon, int ilat, short selev, OsmPa
protected OsmPathElement() {
}

public void addTraffic(float traffic) {
}

public String toString() {
return ilon + "_" + ilat;
}
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions brouter-core/src/main/java/btools/router/RoutingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package btools.router;

import java.io.DataOutput;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -141,14 +140,6 @@ public void readGlobalConfig() {
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);
Expand Down Expand Up @@ -199,17 +190,7 @@ public void readGlobalConfig() {
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;
Expand Down
22 changes: 5 additions & 17 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,6 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
}

if (path.airdistance == -1) {
path.unregisterUpTree(routingContext);
continue;
}

Expand Down Expand Up @@ -1347,7 +1346,6 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
OsmNode currentNode = path.getTargetNode();

if (currentLink.isLinkUnused()) {
path.unregisterUpTree(routingContext);
continue;
}

Expand Down Expand Up @@ -1390,7 +1388,7 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
+ 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);
Expand All @@ -1400,7 +1398,6 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
}
}

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;
Expand All @@ -1419,7 +1416,6 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
// recheck cutoff before doing expensive stuff
int addDiff = 100;
if (path.cost + path.airdistance > maxTotalCost + addDiff) {
path.unregisterUpTree(routingContext);
continue;
}

Expand Down Expand Up @@ -1474,7 +1470,7 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
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;
Expand Down Expand Up @@ -1510,16 +1506,14 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
}
}
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;
Expand All @@ -1528,18 +1522,13 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
}

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);
}
}
}
}

path.unregisterUpTree(routingContext);
}
}

Expand All @@ -1553,12 +1542,11 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public RestrictionData getFirstRestriction() {
return null;
}

public void writeNodeData(MicroCache mc, OsmTrafficMap trafficMap) throws IOException {
public void writeNodeData(MicroCache mc) throws IOException {
boolean valid = true;
if (mc instanceof MicroCache2) {
valid = writeNodeData2((MicroCache2) mc, trafficMap);
valid = writeNodeData2((MicroCache2) mc);
} else
throw new IllegalArgumentException("unknown cache version: " + mc.getClass());
if (valid) {
Expand Down Expand Up @@ -144,7 +144,7 @@ private void unifyLink(OsmLinkP link) {
}
}

public boolean writeNodeData2(MicroCache2 mc, OsmTrafficMap trafficMap) throws IOException {
public boolean writeNodeData2(MicroCache2 mc) throws IOException {
boolean hasLinks = false;

// write turn restrictions
Expand Down Expand Up @@ -212,11 +212,7 @@ public boolean writeNodeData2(MicroCache2 mc, OsmTrafficMap trafficMap) throws I
}
}

// add traffic simulation, if present
byte[] description = link0.descriptionBitmap;
if (trafficMap != null) {
description = trafficMap.addTrafficClass(linkNodes, description);
}

// write link data
int sizeoffset = mc.writeSizePlaceHolder();
Expand Down
Loading
Loading