Merge pull request #728 from afischerdev/startway

Start way check added
This commit is contained in:
afischerdev 2024-09-12 10:04:01 +02:00 committed by GitHub
commit 1e6c40973e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 64 additions and 5 deletions

View File

@ -161,7 +161,8 @@ public final class MicroCache2 extends MicroCache {
int ilontarget = ilon + dlon_remaining; int ilontarget = ilon + dlon_remaining;
int ilattarget = ilat + dlat_remaining; int ilattarget = ilat + dlat_remaining;
if (matcher != null) { if (matcher != null) {
if (!matcher.start(ilon, ilat, ilontarget, ilattarget)) { boolean useAsStartWay = wayValidator.checkStartWay(wayTags.data);
if (!matcher.start(ilon, ilat, ilontarget, ilattarget, useAsStartWay)) {
matcher = null; matcher = null;
} }
} }

View File

@ -13,4 +13,6 @@ public interface TagValueValidator {
boolean isLookupIdxUsed(int idx); boolean isLookupIdxUsed(int idx);
void setDecodeForbidden(boolean decodeForbidden); void setDecodeForbidden(boolean decodeForbidden);
boolean checkStartWay(byte[] ab);
} }

View File

@ -6,7 +6,7 @@ package btools.codec;
* matches to the waypoints * matches to the waypoints
*/ */
public interface WaypointMatcher { public interface WaypointMatcher {
boolean start(int ilonStart, int ilatStart, int ilonTarget, int ilatTarget); boolean start(int ilonStart, int ilatStart, int ilonTarget, int ilatTarget, boolean useAsStartWay);
void transferNode(int ilon, int ilat); void transferNode(int ilon, int ilat);

View File

@ -167,6 +167,10 @@ public final class RoutingContext {
defaultC_r = expctxGlobal.getVariableValue("C_r", 0.01f); defaultC_r = expctxGlobal.getVariableValue("C_r", 0.01f);
// Constant power of the biker (in W) // Constant power of the biker (in W)
bikerPower = expctxGlobal.getVariableValue("bikerPower", 100.f); bikerPower = expctxGlobal.getVariableValue("bikerPower", 100.f);
boolean test = expctxGlobal.getVariableValue("check_start_way", 1f) == 1f;
if (!test) expctxGlobal.freeNoWays();
} }
public List<OsmNodeNamed> poipoints; public List<OsmNodeNamed> poipoints;

View File

@ -80,6 +80,8 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
private BExpressionContext foreignContext; private BExpressionContext foreignContext;
public int[] noStartWays = new int[0];
protected void setInverseVars() { protected void setInverseVars() {
currentVarOffset = nBuildInVars; currentVarOffset = nBuildInVars;
} }
@ -187,7 +189,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
/** /**
* decode a byte-array into a lookup data array * decode a byte-array into a lookup data array
*/ */
private void decode(int[] ld, boolean inverseDirection, byte[] ab) { public void decode(int[] ld, boolean inverseDirection, byte[] ab) {
BitCoderContext ctx = ctxDecode; BitCoderContext ctx = ctxDecode;
ctx.reset(ab); ctx.reset(ab);
@ -954,6 +956,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
private String _parseToken() throws Exception { private String _parseToken() throws Exception {
StringBuilder sb = new StringBuilder(32); StringBuilder sb = new StringBuilder(32);
StringBuilder sbcom = new StringBuilder(32);
boolean inComment = false; boolean inComment = false;
for (; ; ) { for (; ; ) {
int ic = _readerDone ? -1 : _br.read(); int ic = _readerDone ? -1 : _br.read();
@ -966,7 +969,33 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
if (c == '\n') linenr++; if (c == '\n') linenr++;
if (inComment) { if (inComment) {
sbcom.append(c);
if (c == '\r' || c == '\n') inComment = false; if (c == '\r' || c == '\n') inComment = false;
if (!inComment) {
Integer num = variableNumbers.get("check_start_way");
if (num != null && noStartWays.length == 0 && sbcom.toString().contains("noStartWay")) {
String var = sbcom.toString().trim();
String[] savar = var.split("\\|");
if (savar.length == 4) {
var = savar[3].substring(savar[3].indexOf("=")+1).trim();
String[] sa = var.split(";");
for (String s: sa) {
String[] sa2 = s.split(",");
String name = sa2[0];
String value = sa2[1];
int nidx = getLookupNameIdx(name);
if (nidx == -1) break;
int vidx = getLookupValueIdx(nidx, value);
int[] tmp = new int[noStartWays.length + 2];
if (noStartWays.length > 0) System.arraycopy(noStartWays, 0, tmp, 0, noStartWays.length);
noStartWays = tmp;
noStartWays[noStartWays.length-2] = nidx;
noStartWays[noStartWays.length-1] = vidx;
}
}
}
sbcom.setLength(0);
}
continue; continue;
} }
if (Character.isWhitespace(c)) { if (Character.isWhitespace(c)) {
@ -983,4 +1012,21 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
return value; return value;
} }
int[] ld2 = new int[512];
public boolean checkStartWay(byte[] ab) {
if (ab == null) return true;
Arrays.fill(ld2, 0);
decode(ld2, false, ab);
for (int i = 0; i < noStartWays.length; i += 2) {
int key = noStartWays[i];
int value = noStartWays[i+1];
if (ld2[key] == value) return false;
}
return true;
}
public void freeNoWays() {
noStartWays = new int[0];
}
} }

View File

@ -129,4 +129,6 @@ public final class BExpressionContextWay extends BExpressionContext implements T
public void setDecodeForbidden(boolean decodeForbidden) { public void setDecodeForbidden(boolean decodeForbidden) {
this.decodeForbidden = decodeForbidden; this.decodeForbidden = decodeForbidden;
} }
} }

View File

@ -116,7 +116,8 @@ public final class DirectWeaver extends ByteDataWriter {
int ilontarget = ilon + dlon_remaining; int ilontarget = ilon + dlon_remaining;
int ilattarget = ilat + dlat_remaining; int ilattarget = ilat + dlat_remaining;
if (matcher != null) { if (matcher != null) {
if (!matcher.start(ilon, ilat, ilontarget, ilattarget)) { boolean useAsStartWay = wayTags==null || wayValidator.checkStartWay(wayTags.data);
if (!matcher.start(ilon, ilat, ilontarget, ilattarget, useAsStartWay)) {
matcher = null; matcher = null;
} }
} }

View File

@ -28,6 +28,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
private boolean anyUpdate; private boolean anyUpdate;
private int lonLast; private int lonLast;
private int latLast; private int latLast;
boolean useAsStartWay = true;
private Comparator<MatchedWaypoint> comparator; private Comparator<MatchedWaypoint> comparator;
@ -78,6 +79,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
//for ( MatchedWaypoint mwp : waypoints ) //for ( MatchedWaypoint mwp : waypoints )
for (int i = 0; i < waypoints.size(); i++) { for (int i = 0; i < waypoints.size(); i++) {
if (!useAsStartWay && i==0) continue;
MatchedWaypoint mwp = waypoints.get(i); MatchedWaypoint mwp = waypoints.get(i);
if (mwp.direct && if (mwp.direct &&
@ -141,7 +143,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
} }
@Override @Override
public boolean start(int ilonStart, int ilatStart, int ilonTarget, int ilatTarget) { public boolean start(int ilonStart, int ilatStart, int ilonTarget, int ilatTarget, boolean useAsStartWay) {
if (islandPairs.size() > 0) { if (islandPairs.size() > 0) {
long n1 = ((long) ilonStart) << 32 | ilatStart; long n1 = ((long) ilonStart) << 32 | ilatStart;
long n2 = ((long) ilonTarget) << 32 | ilatTarget; long n2 = ((long) ilonTarget) << 32 | ilatTarget;
@ -154,6 +156,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
lonTarget = ilonTarget; lonTarget = ilonTarget;
latTarget = ilatTarget; latTarget = ilatTarget;
anyUpdate = false; anyUpdate = false;
this.useAsStartWay = useAsStartWay;
return true; return true;
} }