Skip to content

Commit

Permalink
Merge pull request abrensch#728 from afischerdev/startway
Browse files Browse the repository at this point in the history
Start way check added
  • Loading branch information
afischerdev authored Sep 12, 2024
2 parents 6b4d989 + d2d6396 commit 1e6c409
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
3 changes: 2 additions & 1 deletion brouter-codec/src/main/java/btools/codec/MicroCache2.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public MicroCache2(StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int
int ilontarget = ilon + dlon_remaining;
int ilattarget = ilat + dlat_remaining;
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface TagValueValidator {
boolean isLookupIdxUsed(int idx);

void setDecodeForbidden(boolean decodeForbidden);

boolean checkStartWay(byte[] ab);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* matches to the waypoints
*/
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);

Expand Down
4 changes: 4 additions & 0 deletions brouter-core/src/main/java/btools/router/RoutingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public void readGlobalConfig() {
defaultC_r = expctxGlobal.getVariableValue("C_r", 0.01f);
// Constant power of the biker (in W)
bikerPower = expctxGlobal.getVariableValue("bikerPower", 100.f);

boolean test = expctxGlobal.getVariableValue("check_start_way", 1f) == 1f;
if (!test) expctxGlobal.freeNoWays();

}

public List<OsmNodeNamed> poipoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public abstract class BExpressionContext implements IByteArrayUnifier {

private BExpressionContext foreignContext;

public int[] noStartWays = new int[0];

protected void setInverseVars() {
currentVarOffset = nBuildInVars;
}
Expand Down Expand Up @@ -187,7 +189,7 @@ public void decode(byte[] ab) {
/**
* 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;
ctx.reset(ab);

Expand Down Expand Up @@ -954,6 +956,7 @@ String parseToken() throws Exception {

private String _parseToken() throws Exception {
StringBuilder sb = new StringBuilder(32);
StringBuilder sbcom = new StringBuilder(32);
boolean inComment = false;
for (; ; ) {
int ic = _readerDone ? -1 : _br.read();
Expand All @@ -966,7 +969,33 @@ private String _parseToken() throws Exception {
if (c == '\n') linenr++;

if (inComment) {
sbcom.append(c);
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;
}
if (Character.isWhitespace(c)) {
Expand All @@ -983,4 +1012,21 @@ float assign(int variableIdx, float 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];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ public int accessType(byte[] description) {
public void setDecodeForbidden(boolean decodeForbidden) {
this.decodeForbidden = decodeForbidden;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public DirectWeaver(StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, in
int ilontarget = ilon + dlon_remaining;
int ilattarget = ilat + dlat_remaining;
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
private boolean anyUpdate;
private int lonLast;
private int latLast;
boolean useAsStartWay = true;

private Comparator<MatchedWaypoint> comparator;

Expand Down Expand Up @@ -78,6 +79,7 @@ private void checkSegment(int lon1, int lat1, int lon2, int lat2) {

//for ( MatchedWaypoint mwp : waypoints )
for (int i = 0; i < waypoints.size(); i++) {
if (!useAsStartWay && i==0) continue;
MatchedWaypoint mwp = waypoints.get(i);

if (mwp.direct &&
Expand Down Expand Up @@ -141,7 +143,7 @@ private void checkSegment(int lon1, int lat1, int lon2, int lat2) {
}

@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) {
long n1 = ((long) ilonStart) << 32 | ilatStart;
long n2 = ((long) ilonTarget) << 32 | ilatTarget;
Expand All @@ -154,6 +156,7 @@ public boolean start(int ilonStart, int ilatStart, int ilonTarget, int ilatTarge
lonTarget = ilonTarget;
latTarget = ilatTarget;
anyUpdate = false;
this.useAsStartWay = useAsStartWay;
return true;
}

Expand Down

0 comments on commit 1e6c409

Please sign in to comment.