Skip to content
Open
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/FormatCsv.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String format(OsmTrack t) {
}

public void writeMessages(BufferedWriter bw, OsmTrack t) throws Exception {
dumpLine(bw, MESSAGES_HEADER);
dumpLine(bw, MESSAGES_HEADER.replace("\tUserOutput", rc.expctxWay.getUserOutputHeader()));
for (String m : t.aggregateMessages()) {
dumpLine(bw, m);
}
Expand Down
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/FormatJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String format(OsmTrack t) {
// ... traditional message list
{
sb.append(" \"messages\": [\n");
sb.append(" [\"").append(MESSAGES_HEADER.replaceAll("\t", "\", \"")).append("\"],\n");
sb.append(" [\"").append(MESSAGES_HEADER.replace("\tUserOutput", rc.userOutputHeader).replaceAll("\t", "\", \"")).append("\"],\n");
for (String m : t.aggregateMessages()) {
sb.append(" [\"").append(m.replaceAll("\t", "\", \"")).append("\"],\n");
}
Expand Down
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public abstract class Formatter {

static final String MESSAGES_HEADER = "Longitude\tLatitude\tElevation\tDistance\tCostPerKm\tElevCost\tTurnCost\tNodeCost\tInitialCost\tWayTags\tNodeTags\tTime\tEnergy";
static final String MESSAGES_HEADER = "Longitude\tLatitude\tElevation\tDistance\tCostPerKm\tElevCost\tTurnCost\tNodeCost\tUserOutput\tInitialCost\tWayTags\tNodeTags\tTime\tEnergy";

RoutingContext rc;

Expand Down
13 changes: 13 additions & 0 deletions brouter-core/src/main/java/btools/router/MessageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package btools.router;


import java.util.ArrayList;
import java.util.List;

final class MessageData implements Cloneable {
int linkdist = 0;
int linkelevationcost = 0;
Expand Down Expand Up @@ -35,12 +38,21 @@ final class MessageData implements Cloneable {
int vnode1 = 999;
int extraTime = 0;

// user output variables:
int userOutputCount = 0;
List<Float> userOutput = new ArrayList<>();

String toMessage() {
if (wayKeyValues == null) {
return null;
}

int iCost = (int) (costfactor * 1000 + 0.5f);
String userOutputBlock="";
for (int i=0; i<userOutputCount; ++i) {
userOutputBlock += "\t" + (int) (userOutput.get(i) + 0.5f);
}

return (lon - 180000000) + "\t"
+ (lat - 90000000) + "\t"
+ ele / 4 + "\t"
Expand All @@ -49,6 +61,7 @@ String toMessage() {
+ linkelevationcost
+ "\t" + linkturncost
+ "\t" + linknodecost
+ userOutputBlock
+ "\t" + linkinitcost
+ "\t" + wayKeyValues
+ "\t" + (nodeKeyValues == null ? "" : nodeKeyValues)
Expand Down
4 changes: 4 additions & 0 deletions brouter-core/src/main/java/btools/router/ProfileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class ProfileCache {

private BExpressionContextWay expctxWay;
private BExpressionContextNode expctxNode;
private String userOutputHeader;
private File lastProfileFile;
private long lastProfileTimestamp;
private boolean profilesBusy;
Expand Down Expand Up @@ -67,6 +68,7 @@ public static synchronized boolean parseProfile(RoutingContext rc) {
if (rc.profileTimestamp == pc.lastProfileTimestamp) {
rc.expctxWay = pc.expctxWay;
rc.expctxNode = pc.expctxNode;
rc.userOutputHeader = pc.userOutputHeader;
rc.readGlobalConfig();
pc.profilesBusy = true;
return true;
Expand All @@ -93,6 +95,7 @@ public static synchronized boolean parseProfile(RoutingContext rc) {

rc.expctxWay.parseFile(profileFile, "global", rc.keyValues);
rc.expctxNode.parseFile(profileFile, "global", rc.keyValues);
rc.userOutputHeader = rc.expctxWay.getUserOutputHeader();

rc.readGlobalConfig();

Expand All @@ -118,6 +121,7 @@ public static synchronized boolean parseProfile(RoutingContext rc) {
lru.lastProfileFile = profileFile;
lru.expctxWay = rc.expctxWay;
lru.expctxNode = rc.expctxNode;
lru.userOutputHeader = rc.userOutputHeader;
lru.profilesBusy = true;
lru.lastUseTime = System.currentTimeMillis();
return false;
Expand Down
2 changes: 2 additions & 0 deletions brouter-core/src/main/java/btools/router/RoutingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public String getProfileName() {
public BExpressionContextWay expctxWay;
public BExpressionContextNode expctxNode;

public String userOutputHeader;

public GeometryDecoder geometryDecoder = new GeometryDecoder();

public int memoryclass = 64;
Expand Down
4 changes: 4 additions & 0 deletions brouter-core/src/main/java/btools/router/StdPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ protected double processWaySection(RoutingContext rc, double distance, double de

if (message != null) {
message.costfactor = costfactor;
message.userOutputCount = rc.expctxWay.getUserOutputCount();
for (int i=0; i<message.userOutputCount; ++i) {
message.userOutput.add(rc.expctxWay.getUserOutput(i));
}
}

sectionCost += dist * costfactor + 0.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,28 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
private int[] buildInVariableIdx;
private int nBuildInVars;

private int nUserOutputVars;

private List<String> userOutputNames=new ArrayList<>();

private float[] currentVars;
private int currentVarOffset;

private BExpressionContext foreignContext;

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

public int getUserOutputCount() {
return nUserOutputVars;
}
public String getUserOutputHeader() {
String header="";
for (int i=0; i<nUserOutputVars; ++i) {
header+="\t"+userOutputNames.get(i);
}
return header;
}

protected void setInverseVars() {
currentVarOffset = nBuildInVars;
}
Expand All @@ -92,6 +107,11 @@ public final float getBuildInVariable(int idx) {
return currentVars[idx + currentVarOffset];
}

public final float getUserVariable(int idx) {
return currentVars[idx];
}


private int linenr;

public BExpressionMetaData meta;
Expand Down Expand Up @@ -800,11 +820,22 @@ public void parseFile(File file, String readOnlyContext, Map<String, String> key
lastAssignedExpression = null;

// determine the build-in variable indices
String[] varNames = getBuildInVariableNames();
nBuildInVars = varNames.length;
List<String> varNames = new ArrayList<>(Arrays.asList(getBuildInVariableNames()));
nBuildInVars = varNames.size();
// find all userOutput variables and insert them to buildInVariables:
final String userOutputKeyword="userOutput";
for (String key : variableNumbers.keySet()) {
if (key.startsWith(userOutputKeyword)) {
varNames.add(key);
nBuildInVars++;
userOutputNames.add(key.substring(userOutputKeyword.length()));
nUserOutputVars++;
}
}

buildInVariableIdx = new int[nBuildInVars];
for (int vi = 0; vi < varNames.length; vi++) {
buildInVariableIdx[vi] = getVariableIdx(varNames[vi], false);
for (int vi = 0; vi < varNames.size(); vi++) {
buildInVariableIdx[vi] = getVariableIdx(varNames.get(vi), false);
}

float[] readOnlyData = variableData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public float getDownhillmaxslopecost() {
return getBuildInVariable(19);
}

public float getUserOutput(int idx) {
return getBuildInVariable(20+idx);
}



public BExpressionContextWay(BExpressionMetaData meta) {
super("way", meta);
}
Expand Down
8 changes: 8 additions & 0 deletions docs/developers/profile_developers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ calculations per way-section in the *Data*-tab.
For profile debugging activate `assign processUnusedTags = true` to see all
present OSM tags on the Data tab, not just those used in the tested profile.

It can be useful to create user variables, beginning with the keyword
"userOutput", which are shown in the data table of brouter-web, e.g.

assign userOutputTraffic trafficcost
assign userOutputSurface surfacecost

adds two columns "Traffic" and "Surface" with the respective values
for each sector between the "node$"- and "initial$"-column.

Lookup-Table evolution and the the *major* and *minor* versions
---------------------------------------------------------------
Expand Down