fixed node-costs in csv
This commit is contained in:
parent
0fe5d5144a
commit
4b084bd033
3 changed files with 79 additions and 37 deletions
48
brouter-core/src/main/java/btools/router/MessageData.java
Normal file
48
brouter-core/src/main/java/btools/router/MessageData.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* Information on matched way point
|
||||||
|
*
|
||||||
|
* @author ab
|
||||||
|
*/
|
||||||
|
package btools.router;
|
||||||
|
|
||||||
|
import btools.expressions.BExpressionContext;
|
||||||
|
|
||||||
|
|
||||||
|
final class MessageData
|
||||||
|
{
|
||||||
|
int linkdist = 0;
|
||||||
|
int linkelevationcost = 0;
|
||||||
|
int linkturncost = 0;
|
||||||
|
int linknodecost = 0;
|
||||||
|
int linkinitcost = 0;
|
||||||
|
|
||||||
|
float costfactor;
|
||||||
|
String wayKeyValues;
|
||||||
|
String nodeKeyValues;
|
||||||
|
|
||||||
|
int lon;
|
||||||
|
int lat;
|
||||||
|
short ele;
|
||||||
|
|
||||||
|
String toMessage()
|
||||||
|
{
|
||||||
|
if ( wayKeyValues == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iCost = (int)(costfactor*1000 + 0.5f);
|
||||||
|
return (lon-180000000) + "\t"
|
||||||
|
+ (lat-90000000) + "\t"
|
||||||
|
+ ele/4 + "\t"
|
||||||
|
+ linkdist + "\t"
|
||||||
|
+ iCost + "\t"
|
||||||
|
+ linkelevationcost
|
||||||
|
+ "\t" + linkturncost
|
||||||
|
+ "\t" + linknodecost
|
||||||
|
+ "\t" + linkinitcost
|
||||||
|
+ "\t" + wayKeyValues
|
||||||
|
+ "\t" + ( nodeKeyValues == null ? "" : nodeKeyValues );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -84,15 +84,11 @@ final class OsmPath implements OsmLinkHolder
|
||||||
short ele1 = origin.selev;
|
short ele1 = origin.selev;
|
||||||
|
|
||||||
int linkdisttotal = 0;
|
int linkdisttotal = 0;
|
||||||
int linkdist = 0;
|
|
||||||
int linkelevationcost = 0;
|
MessageData msgData = new MessageData();
|
||||||
int linkturncost = 0;
|
|
||||||
int linknodecost = 0;
|
|
||||||
int linkinitcost = 0;
|
|
||||||
|
|
||||||
OsmTransferNode transferNode = link.decodeFirsttransfer();
|
OsmTransferNode transferNode = link.decodeFirsttransfer();
|
||||||
OsmNode targetNode = link.targetNode;
|
OsmNode targetNode = link.targetNode;
|
||||||
String lastMessage = null;
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
originLon = lon1;
|
originLon = lon1;
|
||||||
|
@ -124,14 +120,10 @@ final class OsmPath implements OsmLinkHolder
|
||||||
boolean sameData = rc.expctxWay.evaluate( link.counterLinkWritten, description, rc.messageHandler );
|
boolean sameData = rc.expctxWay.evaluate( link.counterLinkWritten, description, rc.messageHandler );
|
||||||
|
|
||||||
// if way description changed, store message
|
// if way description changed, store message
|
||||||
if ( lastMessage != null && !sameData )
|
if ( msgData.wayKeyValues != null && !sameData )
|
||||||
{
|
{
|
||||||
originElement.message = lastMessage;
|
originElement.message = msgData.toMessage();
|
||||||
linkdist = 0;
|
msgData = new MessageData();
|
||||||
linkelevationcost = 0;
|
|
||||||
linkturncost = 0;
|
|
||||||
linknodecost = 0;
|
|
||||||
linkinitcost = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dist = rc.calcDistance( lon1, lat1, lon2, lat2 );
|
int dist = rc.calcDistance( lon1, lat1, lon2, lat2 );
|
||||||
|
@ -165,7 +157,7 @@ final class OsmPath implements OsmLinkHolder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linkdist += dist;
|
msgData.linkdist += dist;
|
||||||
linkdisttotal += dist;
|
linkdisttotal += dist;
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,7 +168,7 @@ final class OsmPath implements OsmLinkHolder
|
||||||
double cos = rc.calcCosAngle( lon0, lat0, lon1, lat1, lon2, lat2 );
|
double cos = rc.calcCosAngle( lon0, lat0, lon1, lat1, lon2, lat2 );
|
||||||
int turncost = (int)(cos * rc.expctxWay.getTurncost() + 0.2 ); // e.g. turncost=90 -> 90 degree = 90m penalty
|
int turncost = (int)(cos * rc.expctxWay.getTurncost() + 0.2 ); // e.g. turncost=90 -> 90 degree = 90m penalty
|
||||||
cost += turncost;
|
cost += turncost;
|
||||||
linkturncost += turncost;
|
msgData.linkturncost += turncost;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** penalty for elevation (penalty is for descend! in a way that slow descends give no penalty)
|
// *** penalty for elevation (penalty is for descend! in a way that slow descends give no penalty)
|
||||||
|
@ -212,7 +204,7 @@ final class OsmPath implements OsmLinkHolder
|
||||||
{
|
{
|
||||||
int elevationCost = reduce/rc.downhillcostdiv;
|
int elevationCost = reduce/rc.downhillcostdiv;
|
||||||
cost += elevationCost;
|
cost += elevationCost;
|
||||||
linkelevationcost += elevationCost;
|
msgData.linkelevationcost += elevationCost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( ehbd < 0 )
|
else if ( ehbd < 0 )
|
||||||
|
@ -242,7 +234,7 @@ final class OsmPath implements OsmLinkHolder
|
||||||
{
|
{
|
||||||
int elevationCost = reduce/rc.uphillcostdiv;
|
int elevationCost = reduce/rc.uphillcostdiv;
|
||||||
cost += elevationCost;
|
cost += elevationCost;
|
||||||
linkelevationcost += elevationCost;
|
msgData.linkelevationcost += elevationCost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( ehbu < 0 )
|
else if ( ehbu < 0 )
|
||||||
|
@ -276,23 +268,17 @@ final class OsmPath implements OsmLinkHolder
|
||||||
lastCostfactor = newcostfactor;
|
lastCostfactor = newcostfactor;
|
||||||
float initialcost = rc.expctxWay.getInitialcost();
|
float initialcost = rc.expctxWay.getInitialcost();
|
||||||
int iicost = (int)initialcost;
|
int iicost = (int)initialcost;
|
||||||
linkinitcost += iicost;
|
msgData.linkinitcost += iicost;
|
||||||
cost += iicost;
|
cost += iicost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( recordTransferNodes )
|
if ( recordTransferNodes )
|
||||||
{
|
{
|
||||||
int iCost = (int)(costfactor*1000 + 0.5f);
|
msgData.costfactor = costfactor;
|
||||||
lastMessage = (lon2-180000000) + "\t"
|
msgData.lon = lon2;
|
||||||
+ (lat2-90000000) + "\t"
|
msgData.lat = lat2;
|
||||||
+ ele2/4 + "\t"
|
msgData.ele = ele2;
|
||||||
+ linkdist + "\t"
|
msgData.wayKeyValues = rc.expctxWay.getKeyValueDescription( link.counterLinkWritten, description );
|
||||||
+ iCost + "\t"
|
|
||||||
+ linkelevationcost
|
|
||||||
+ "\t" + linkturncost
|
|
||||||
+ "\t" + linknodecost
|
|
||||||
+ "\t" + linkinitcost
|
|
||||||
+ rc.expctxWay.getKeyValueDescription( link.counterLinkWritten, description );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( stopAtEndpoint )
|
if ( stopAtEndpoint )
|
||||||
|
@ -301,7 +287,7 @@ final class OsmPath implements OsmLinkHolder
|
||||||
{
|
{
|
||||||
originElement = new OsmPathElement( rc.ilonshortest, rc.ilatshortest, ele2, originElement );
|
originElement = new OsmPathElement( rc.ilonshortest, rc.ilatshortest, ele2, originElement );
|
||||||
originElement.cost = cost;
|
originElement.cost = cost;
|
||||||
originElement.message = lastMessage;
|
originElement.message = msgData.toMessage();
|
||||||
}
|
}
|
||||||
if ( rc.nogomatch )
|
if ( rc.nogomatch )
|
||||||
{
|
{
|
||||||
|
@ -318,7 +304,6 @@ final class OsmPath implements OsmLinkHolder
|
||||||
int reftrackcost = linkdisttotal;
|
int reftrackcost = linkdisttotal;
|
||||||
cost += reftrackcost;
|
cost += reftrackcost;
|
||||||
}
|
}
|
||||||
message = lastMessage;
|
|
||||||
selev = ele2;
|
selev = ele2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -347,8 +332,9 @@ final class OsmPath implements OsmLinkHolder
|
||||||
// finally add node-costs for target node
|
// finally add node-costs for target node
|
||||||
if ( targetNode.nodeDescription != null )
|
if ( targetNode.nodeDescription != null )
|
||||||
{
|
{
|
||||||
|
boolean nodeAccessGranted = rc.expctxWay.getNodeAccessGranted() != 0.;
|
||||||
rc.messageHandler.setCurrentPos( targetNode.ilon, targetNode.ilat );
|
rc.messageHandler.setCurrentPos( targetNode.ilon, targetNode.ilat );
|
||||||
rc.expctxNode.evaluate( rc.expctxWay.getNodeAccessGranted() != 0. , targetNode.nodeDescription, rc.messageHandler );
|
rc.expctxNode.evaluate( nodeAccessGranted , targetNode.nodeDescription, rc.messageHandler );
|
||||||
float initialcost = rc.expctxNode.getInitialcost();
|
float initialcost = rc.expctxNode.getInitialcost();
|
||||||
if ( initialcost >= 1000000. )
|
if ( initialcost >= 1000000. )
|
||||||
{
|
{
|
||||||
|
@ -356,9 +342,18 @@ final class OsmPath implements OsmLinkHolder
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int iicost = (int)initialcost;
|
int iicost = (int)initialcost;
|
||||||
linknodecost += iicost;
|
msgData.linknodecost += iicost;
|
||||||
|
|
||||||
cost += iicost;
|
cost += iicost;
|
||||||
|
|
||||||
|
if ( recordTransferNodes )
|
||||||
|
{
|
||||||
|
msgData.nodeKeyValues = rc.expctxNode.getKeyValueDescription( nodeAccessGranted, targetNode.nodeDescription );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = msgData.toMessage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int elevationCorrection( RoutingContext rc )
|
public int elevationCorrection( RoutingContext rc )
|
||||||
|
|
|
@ -281,9 +281,6 @@ public final class BExpressionContext
|
||||||
|
|
||||||
public String getKeyValueDescription( boolean inverseDirection, byte[] ab )
|
public String getKeyValueDescription( boolean inverseDirection, byte[] ab )
|
||||||
{
|
{
|
||||||
int inverseBitByteIndex = meta.readVarLength ? 0 : 7;
|
|
||||||
// int abLen = ab.length;
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder( 200 );
|
StringBuilder sb = new StringBuilder( 200 );
|
||||||
decode( lookupData, inverseDirection, ab );
|
decode( lookupData, inverseDirection, ab );
|
||||||
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
||||||
|
@ -292,7 +289,8 @@ public final class BExpressionContext
|
||||||
String value = va[lookupData[inum]].toString();
|
String value = va[lookupData[inum]].toString();
|
||||||
if ( value != null && value.length() > 0 )
|
if ( value != null && value.length() > 0 )
|
||||||
{
|
{
|
||||||
sb.append( " " + lookupNames.get( inum ) + "=" + value );
|
if ( sb.length() > 0 ) sb.append( ' ' );
|
||||||
|
sb.append(lookupNames.get( inum ) + "=" + value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
@ -571,6 +569,7 @@ public final class BExpressionContext
|
||||||
lookupData[inum] = valueIndex;
|
lookupData[inum] = valueIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* special hack for yes/proposed relations:
|
* special hack for yes/proposed relations:
|
||||||
* add a lookup value if not yet a smaller, >1 value was added
|
* add a lookup value if not yet a smaller, >1 value was added
|
||||||
|
|
Loading…
Reference in a new issue