Merge pull request #697 from quaelnix/remove-traffic-simulation
Remove unused traffic simulation code
This commit is contained in:
commit
73e7873583
10 changed files with 19 additions and 432 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -93,10 +93,10 @@ public class OsmNodeP extends OsmLinkP {
|
|||
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) {
|
||||
|
@ -144,7 +144,7 @@ public class OsmNodeP extends OsmLinkP {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean writeNodeData2(MicroCache2 mc, OsmTrafficMap trafficMap) throws IOException {
|
||||
public boolean writeNodeData2(MicroCache2 mc) throws IOException {
|
||||
boolean hasLinks = false;
|
||||
|
||||
// write turn restrictions
|
||||
|
@ -212,11 +212,7 @@ public class OsmNodeP extends OsmLinkP {
|
|||
}
|
||||
}
|
||||
|
||||
// add traffic simulation, if present
|
||||
byte[] description = link0.descriptionBitmap;
|
||||
if (trafficMap != null) {
|
||||
description = trafficMap.addTrafficClass(linkNodes, description);
|
||||
}
|
||||
|
||||
// write link data
|
||||
int sizeoffset = mc.writeSizePlaceHolder();
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
/**
|
||||
* Container for link between two Osm nodes (pre-pocessor version)
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
package btools.mapcreator;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import btools.expressions.BExpressionContextWay;
|
||||
import btools.util.CheapRuler;
|
||||
import btools.util.CompactLongMap;
|
||||
import btools.util.FrozenLongMap;
|
||||
|
||||
|
||||
public class OsmTrafficMap {
|
||||
int minLon;
|
||||
int minLat;
|
||||
int maxLon;
|
||||
int maxLat;
|
||||
|
||||
private BExpressionContextWay expctxWay;
|
||||
|
||||
private OsmTrafficMap oldTrafficClasses;
|
||||
private DataOutputStream newTrafficDos;
|
||||
private File oldTrafficFile;
|
||||
private File newTrafficFile;
|
||||
|
||||
private int totalChanges = 0;
|
||||
private int supressedChanges = 0;
|
||||
|
||||
private boolean doNotAdd = false;
|
||||
private boolean debug = false;
|
||||
|
||||
public OsmTrafficMap(BExpressionContextWay expctxWay) {
|
||||
this.expctxWay = expctxWay;
|
||||
debug = Boolean.getBoolean("debugTrafficMap");
|
||||
}
|
||||
|
||||
public static class OsmTrafficElement {
|
||||
public long node2;
|
||||
public int traffic;
|
||||
public OsmTrafficElement next;
|
||||
}
|
||||
|
||||
private CompactLongMap<OsmTrafficElement> map = new CompactLongMap<>();
|
||||
|
||||
public void loadAll(File file, int minLon, int minLat, int maxLon, int maxLat, boolean includeMotorways) throws Exception {
|
||||
load(file, minLon, minLat, maxLon, maxLat, includeMotorways);
|
||||
|
||||
// check for old traffic data
|
||||
oldTrafficFile = new File(file.getParentFile(), file.getName() + "_old");
|
||||
if (oldTrafficFile.exists()) {
|
||||
oldTrafficClasses = new OsmTrafficMap(null);
|
||||
oldTrafficClasses.doNotAdd = true;
|
||||
oldTrafficClasses.load(oldTrafficFile, minLon, minLat, maxLon, maxLat, false);
|
||||
}
|
||||
|
||||
// check for old traffic data
|
||||
newTrafficFile = new File(file.getParentFile(), file.getName() + "_new");
|
||||
newTrafficDos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newTrafficFile)));
|
||||
}
|
||||
|
||||
public void finish() throws Exception {
|
||||
if (newTrafficDos != null) {
|
||||
newTrafficDos.close();
|
||||
newTrafficDos = null;
|
||||
oldTrafficFile.delete();
|
||||
newTrafficFile.renameTo(oldTrafficFile);
|
||||
System.out.println("TrafficMap: changes total=" + totalChanges + " supressed=" + supressedChanges);
|
||||
}
|
||||
}
|
||||
|
||||
public void load(File file, int minLon, int minLat, int maxLon, int maxLat, boolean includeMotorways) throws Exception {
|
||||
this.minLon = minLon;
|
||||
this.minLat = minLat;
|
||||
this.maxLon = maxLon;
|
||||
this.maxLat = maxLat;
|
||||
|
||||
int trafficElements = 0;
|
||||
DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
|
||||
try {
|
||||
for (; ; ) {
|
||||
long n1 = is.readLong();
|
||||
long n2 = is.readLong();
|
||||
int traffic = is.readInt();
|
||||
if (traffic == -1 && !includeMotorways) {
|
||||
continue;
|
||||
}
|
||||
if (isInsideBounds(n1) || isInsideBounds(n2)) {
|
||||
if (addElement(n1, n2, traffic)) {
|
||||
trafficElements++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (EOFException eof) {
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
|
||||
map = new FrozenLongMap<>(map);
|
||||
System.out.println("read traffic-elements: " + trafficElements);
|
||||
}
|
||||
|
||||
|
||||
public boolean addElement(long n1, long n2, int traffic) {
|
||||
OsmTrafficElement e = getElement(n1, n2);
|
||||
if (e == null) {
|
||||
e = new OsmTrafficElement();
|
||||
e.node2 = n2;
|
||||
e.traffic = traffic;
|
||||
|
||||
OsmTrafficElement e0 = map.get(n1);
|
||||
if (e0 != null) {
|
||||
while (e0.next != null) {
|
||||
e0 = e0.next;
|
||||
}
|
||||
e0.next = e;
|
||||
} else {
|
||||
map.fastPut(n1, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (doNotAdd) {
|
||||
e.traffic = Math.max(e.traffic, traffic);
|
||||
} else {
|
||||
e.traffic = e.traffic == -1 || traffic == -1 ? -1 : e.traffic + traffic;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isInsideBounds(long id) {
|
||||
int ilon = (int) (id >> 32);
|
||||
int ilat = (int) (id & 0xffffffff);
|
||||
|
||||
return ilon >= minLon && ilon < maxLon && ilat >= minLat && ilat < maxLat;
|
||||
}
|
||||
|
||||
public int getTrafficClass(long n1, long n2) {
|
||||
// used for the old data, where we stpre traffic-classes, not volumes
|
||||
OsmTrafficElement e = getElement(n1, n2);
|
||||
return e == null ? 0 : e.traffic;
|
||||
}
|
||||
|
||||
public int getTrafficClassForTraffic(int traffic) {
|
||||
if (traffic < 0) return -1;
|
||||
if (traffic < 40000) return 0;
|
||||
if (traffic < 80000) return 2;
|
||||
if (traffic < 160000) return 3;
|
||||
if (traffic < 320000) return 4;
|
||||
if (traffic < 640000) return 5;
|
||||
if (traffic < 1280000) return 6;
|
||||
return 7;
|
||||
}
|
||||
|
||||
private int getTraffic(long n1, long n2) {
|
||||
OsmTrafficElement e1 = getElement(n1, n2);
|
||||
int traffic1 = e1 == null ? 0 : e1.traffic;
|
||||
OsmTrafficElement e2 = getElement(n2, n1);
|
||||
int traffic2 = e2 == null ? 0 : e2.traffic;
|
||||
return traffic1 == -1 || traffic2 == -1 ? -1 : traffic1 > traffic2 ? traffic1 : traffic2;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
}
|
||||
|
||||
private OsmTrafficElement getElement(long n1, long n2) {
|
||||
OsmTrafficElement e = map.get(n1);
|
||||
while (e != null) {
|
||||
if (e.node2 == n2) {
|
||||
return e;
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OsmTrafficElement getElement(long n) {
|
||||
return map.get(n);
|
||||
}
|
||||
|
||||
public byte[] addTrafficClass(List<OsmNodeP> linkNodes, byte[] description) throws IOException {
|
||||
double distance = 0.;
|
||||
double sum = 0.;
|
||||
|
||||
for (int i = 0; i < linkNodes.size() - 1; i++) {
|
||||
OsmNodeP n1 = linkNodes.get(i);
|
||||
OsmNodeP n2 = linkNodes.get(i + 1);
|
||||
int traffic = getTraffic(n1.getIdFromPos(), n2.getIdFromPos());
|
||||
double dist = CheapRuler.distance(n1.ilon, n1.ilat, n2.ilon, n2.ilat);
|
||||
distance += dist;
|
||||
sum += dist * traffic;
|
||||
}
|
||||
|
||||
if (distance == 0.) {
|
||||
return description;
|
||||
}
|
||||
int traffic = (int) (sum / distance + 0.5);
|
||||
|
||||
long id0 = linkNodes.get(0).getIdFromPos();
|
||||
long id1 = linkNodes.get(linkNodes.size() - 1).getIdFromPos();
|
||||
|
||||
int trafficClass = getTrafficClassForTraffic(traffic);
|
||||
|
||||
// delta suppression: keep old traffic classes within some buffer range
|
||||
if (oldTrafficClasses != null) {
|
||||
int oldTrafficClass = oldTrafficClasses.getTrafficClass(id0, id1);
|
||||
if (oldTrafficClass != trafficClass) {
|
||||
totalChanges++;
|
||||
boolean supressChange =
|
||||
oldTrafficClass == getTrafficClassForTraffic((int) (traffic * 1.3))
|
||||
|| oldTrafficClass == getTrafficClassForTraffic((int) (traffic * 0.77));
|
||||
|
||||
if (debug) {
|
||||
System.out.println("traffic class change " + oldTrafficClass + "->" + trafficClass + " supress=" + supressChange);
|
||||
}
|
||||
if (supressChange) {
|
||||
trafficClass = oldTrafficClass;
|
||||
supressedChanges++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (trafficClass > 0) {
|
||||
newTrafficDos.writeLong(id0);
|
||||
newTrafficDos.writeLong(id1);
|
||||
newTrafficDos.writeInt(trafficClass);
|
||||
|
||||
expctxWay.decode(description);
|
||||
expctxWay.addLookupValue("estimated_traffic_class", trafficClass + 1);
|
||||
return expctxWay.encode();
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,6 @@ import btools.util.LazyArrayOfLists;
|
|||
public class WayLinker extends MapCreatorBase implements Runnable {
|
||||
private File nodeTilesIn;
|
||||
private File wayTilesIn;
|
||||
private File trafficTilesIn;
|
||||
private File dataTilesOut;
|
||||
private File borderFileIn;
|
||||
|
||||
|
@ -45,7 +44,6 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
private boolean readingBorder;
|
||||
|
||||
private CompactLongMap<OsmNodeP> nodesMap;
|
||||
private OsmTrafficMap trafficMap;
|
||||
private List<OsmNodeP> nodesList;
|
||||
private CompactLongSet borderSet;
|
||||
private short lookupVersion;
|
||||
|
@ -155,7 +153,6 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
String dataTilesSuffix) throws Exception {
|
||||
this.nodeTilesIn = nodeTilesIn;
|
||||
this.wayTilesIn = wayTilesIn;
|
||||
this.trafficTilesIn = new File("../traffic");
|
||||
this.dataTilesOut = dataTilesOut;
|
||||
this.borderFileIn = borderFileIn;
|
||||
this.dataTilesSuffix = dataTilesSuffix;
|
||||
|
@ -216,8 +213,6 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
}
|
||||
|
||||
|
||||
File trafficFile = fileFromTemplate(wayfile, trafficTilesIn, "trf");
|
||||
|
||||
// process corresponding node-file, if any
|
||||
elevationType = 3;
|
||||
File nodeFile = fileFromTemplate(wayfile, nodeTilesIn, "u5d_1");
|
||||
|
@ -274,11 +269,6 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
nodesList = nodesMapFrozen.getValueList();
|
||||
}
|
||||
|
||||
// read a traffic-file, if any
|
||||
if (trafficFile.exists()) {
|
||||
trafficMap = new OsmTrafficMap(expctxWay);
|
||||
trafficMap.loadAll(trafficFile, minLon, minLat, minLon + 5000000, minLat + 5000000, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -493,7 +483,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
}
|
||||
|
||||
for (OsmNodeP n : sortedList.values()) {
|
||||
n.writeNodeData(mc, trafficMap);
|
||||
n.writeNodeData(mc);
|
||||
}
|
||||
if (mc.getSize() > 0) {
|
||||
byte[] subBytes;
|
||||
|
@ -557,10 +547,6 @@ public class WayLinker extends MapCreatorBase implements Runnable {
|
|||
ra.write(abFileIndex, 0, abFileIndex.length);
|
||||
ra.close();
|
||||
}
|
||||
if (trafficMap != null) {
|
||||
trafficMap.finish();
|
||||
trafficMap = null;
|
||||
}
|
||||
System.out.println("**** codec stats: *******\n" + StatCoderContext.getBitReport());
|
||||
}
|
||||
|
||||
|
|
|
@ -62,22 +62,6 @@ ${JAVA} -cp ${BROUTER_JAR} -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapc
|
|||
mkdir segments
|
||||
${JAVA} -cp ${BROUTER_JAR} -DuseDenseMaps=true btools.mapcreator.WayLinker unodes55 waytiles55 bordernodes.dat restrictions.dat ${BROUTER_PROFILES}/lookups.dat ${BROUTER_PROFILES}/all.brf segments rd5
|
||||
|
||||
mkdir traffic
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 8.593025 49.724868 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 8.609011 50.527861 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 12.867994 51.239889 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 11.128099 49.501845 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 16.532815 49.169541 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -jar ${BROUTER_JAR} segments 16.917636 51.040949 seed 0 ${BROUTER_PROFILES}/car-traffic_analysis.brf
|
||||
|
||||
${JAVA} -cp ${BROUTER_JAR} -DuseDenseMaps=true btools.mapcreator.WayLinker unodes55 waytiles55 bordernodes.dat restrictions.dat ${BROUTER_PROFILES}/lookups.dat ${BROUTER_PROFILES}/all.brf segments rd5
|
||||
|
||||
cd ..
|
||||
rm -rf segments
|
||||
mv tmp/segments segments
|
||||
|
|
Loading…
Reference in a new issue