removed some old stuff, added profiler, minor performance tuning

This commit is contained in:
Arndt 2016-08-20 18:53:50 +02:00
parent 42e9ddbdd1
commit f70dd3c3ac
22 changed files with 234 additions and 802 deletions

View file

@ -108,10 +108,11 @@ final class OsmPath implements OsmLinkHolder
private void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath origin, OsmLink link, RoutingContext rc )
{
if ( link.descriptionBitmap == null ) throw new IllegalArgumentException( "null description for: " + link );
byte[] description = link.descriptionBitmap;
if ( description == null ) throw new IllegalArgumentException( "null description for: " + link );
boolean recordTransferNodes = detailMode || rc.countTraffic;
boolean recordMessageData = detailMode;
boolean recordTransferNodes = detailMode || rc.countTraffic;
boolean recordMessageData = detailMode;
rc.nogomatch = false;
@ -126,7 +127,7 @@ final class OsmPath implements OsmLinkHolder
int linkdisttotal = 0;
MessageData msgData = new MessageData();
MessageData msgData = recordMessageData ? new MessageData() : null;
OsmTransferNode transferNode = link.decodeFirsttransfer( p1 );
OsmNode targetNode = link.targetNode;
@ -138,27 +139,21 @@ final class OsmPath implements OsmLinkHolder
int lon2;
int lat2;
short ele2;
byte[] description;
if ( transferNode == null )
{
lon2 = targetNode.ilon;
lat2 = targetNode.ilat;
ele2 = targetNode.selev;
description = link.descriptionBitmap;
if ( description == null ) throw new IllegalArgumentException( "null description for class: " + link.getClass() );
}
else
{
lon2 = transferNode.ilon;
lat2 = transferNode.ilat;
ele2 = transferNode.selev;
description = transferNode.descriptionBitmap;
if ( description == null ) throw new IllegalArgumentException( "null description for class: " + transferNode.getClass() + "/" + link.getClass() + " counterlinkwritten=" + link.counterLinkWritten );
}
rc.messageHandler.setCurrentPos( lon2, lat2 );
boolean sameData = rc.expctxWay.evaluate( rc.inverseDirection ^ link.counterLinkWritten, description, rc.messageHandler );
boolean sameData = rc.expctxWay.evaluate( rc.inverseDirection ^ link.counterLinkWritten, description );
// if way description changed, store message
if ( recordMessageData && msgData.wayKeyValues != null )
@ -198,7 +193,10 @@ final class OsmPath implements OsmLinkHolder
}
}
msgData.linkdist += dist;
if ( recordMessageData )
{
msgData.linkdist += dist;
}
linkdisttotal += dist;
boolean isTrafficBackbone = cost == 0 && rc.expctxWay.getIsTrafficBackbone() > 0.f;
@ -210,9 +208,9 @@ final class OsmPath implements OsmLinkHolder
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
cost += turncost;
msgData.linkturncost += turncost;
if ( recordMessageData )
{
msgData.linkturncost += turncost;
msgData.turnangle = (float)rc.calcAngle( lon0, lat0, lon1, lat1, lon2, lat2 );
}
}
@ -250,7 +248,10 @@ final class OsmPath implements OsmLinkHolder
{
int elevationCost = reduce/rc.downhillcostdiv;
cost += elevationCost;
msgData.linkelevationcost += elevationCost;
if ( recordMessageData )
{
msgData.linkelevationcost += elevationCost;
}
}
}
else if ( ehbd < 0 )
@ -280,7 +281,10 @@ final class OsmPath implements OsmLinkHolder
{
int elevationCost = reduce/rc.uphillcostdiv;
cost += elevationCost;
msgData.linkelevationcost += elevationCost;
if ( recordMessageData )
{
msgData.linkelevationcost += elevationCost;
}
}
}
else if ( ehbu < 0 )
@ -313,6 +317,7 @@ final class OsmPath implements OsmLinkHolder
cost += waycost;
// calculate traffic
if ( rc.countTraffic )
{
int minDist = (int)rc.trafficSourceMinDist;
int cost2 = cost < minDist ? minDist : cost;
@ -330,7 +335,10 @@ final class OsmPath implements OsmLinkHolder
lastClassifier = newClassifier;
float initialcost = rc.expctxWay.getInitialcost();
int iicost = (int)initialcost;
msgData.linkinitcost += iicost;
if ( recordMessageData )
{
msgData.linkinitcost += iicost;
}
cost += iicost;
}
@ -402,8 +410,7 @@ final class OsmPath implements OsmLinkHolder
if ( targetNode.nodeDescription != null )
{
boolean nodeAccessGranted = rc.expctxWay.getNodeAccessGranted() != 0.;
rc.messageHandler.setCurrentPos( targetNode.ilon, targetNode.ilat );
rc.expctxNode.evaluate( nodeAccessGranted , targetNode.nodeDescription, rc.messageHandler );
rc.expctxNode.evaluate( nodeAccessGranted , targetNode.nodeDescription );
float initialcost = rc.expctxNode.getInitialcost();
if ( initialcost >= 1000000. )
{
@ -411,12 +418,12 @@ final class OsmPath implements OsmLinkHolder
return;
}
int iicost = (int)initialcost;
msgData.linknodecost += iicost;
cost += iicost;
if ( recordMessageData )
{
msgData.linknodecost += iicost;
msgData.nodeKeyValues = rc.expctxNode.getKeyValueDescription( nodeAccessGranted, targetNode.nodeDescription );
}
}

View file

@ -111,8 +111,6 @@ public final class RoutingContext implements DistanceChecker
turnInstructionRoundabouts = expctxGlobal.getVariableValue( "turnInstructionRoundabouts", 1.f ) != 0.f;
}
public RoutingMessageHandler messageHandler = new RoutingMessageHandler();
public List<OsmNodeNamed> nogopoints = null;
private List<OsmNodeNamed> keepnogopoints = null;
@ -222,10 +220,11 @@ public final class RoutingContext implements DistanceChecker
shortestmatch = false;
if ( d > 0. && nogopoints != null )
if ( nogopoints != null && !nogopoints.isEmpty() && d > 0. )
{
for( OsmNodeNamed nogo : nogopoints )
for( int ngidx = 0; ngidx < nogopoints.size(); ngidx++ )
{
OsmNodeNamed nogo = nogopoints.get(ngidx);
double x1 = (lon1 - nogo.ilon) * coslat6;
double y1 = (lat1 - nogo.ilat) * 0.000001;
double x2 = (lon2 - nogo.ilon) * coslat6;

View file

@ -16,6 +16,7 @@ import btools.mapaccess.OsmLinkHolder;
import btools.mapaccess.OsmNode;
import btools.mapaccess.OsmNodesMap;
import btools.util.SortedHeap;
import btools.util.StackSampler;
public class RoutingEngine extends Thread
{
@ -43,6 +44,7 @@ public class RoutingEngine extends Thread
private String logfileBase;
private boolean infoLogEnabled;
private Writer infoLogWriter;
private StackSampler stackSampler;
protected RoutingContext routingContext;
public double airDistanceCostFactor;
@ -66,9 +68,10 @@ public class RoutingEngine extends Thread
this.infoLogEnabled = outfileBase != null;
this.routingContext = rc;
File baseFolder = new File( routingContext.localFunction ).getParentFile().getParentFile();
try
{
File debugLog = new File( new File( routingContext.localFunction ).getParentFile(), "../debug.txt" );
File debugLog = new File( baseFolder, "debug.txt" );
if ( debugLog.exists() )
{
infoLogWriter = new FileWriter( debugLog, true );
@ -80,6 +83,15 @@ public class RoutingEngine extends Thread
{
throw new RuntimeException( "cannot open debug-log:" + ioe );
}
File stackLog = new File( baseFolder, "stacks.txt" );
if ( stackLog.exists() )
{
stackSampler = new StackSampler( stackLog, 1000 );
stackSampler.start();
logInfo( "********** started stacksampling" );
}
boolean cachedProfile = ProfileCache.parseProfile( rc );
if ( hasInfo() )
{
@ -229,6 +241,13 @@ public class RoutingEngine extends Thread
try { infoLogWriter.close(); } catch( Exception e ) {}
infoLogWriter = null;
}
if ( stackSampler != null )
{
try { stackSampler.close(); } catch( Exception e ) {}
stackSampler = null;
}
}
}
@ -378,16 +397,6 @@ public class RoutingEngine extends Thread
{
preloadPosition( mwp.waypoint );
}
// preliminary-hack: use old stuff if not yet matched
for( int i=0; i<unmatchedWaypoints.size(); i++)
{
MatchedWaypoint mwp = unmatchedWaypoints.get(i);
if ( mwp.crosspoint == null )
{
unmatchedWaypoints.set(i, matchNodeForPosition( mwp.waypoint ) );
}
}
}
private void preloadPosition( OsmNode n )
@ -408,93 +417,6 @@ public class RoutingEngine extends Thread
}
// geometric position matching finding the nearest routable way-section
private MatchedWaypoint matchNodeForPosition( OsmNodeNamed wp )
{
try
{
routingContext.setWaypoint( wp, false );
int minRingWith = 1;
for(;;)
{
MatchedWaypoint mwp = _matchNodeForPosition( wp, minRingWith );
if ( mwp.node1 != null )
{
int mismatch = wp.calcDistance( mwp.crosspoint );
if ( mismatch < 50*minRingWith )
{
return mwp;
}
}
if ( minRingWith == 1 && nodesCache.first_file_access_failed )
{
throw new IllegalArgumentException( "datafile " + nodesCache.first_file_access_name + " not found" );
}
if ( minRingWith++ == 5 )
{
throw new IllegalArgumentException( wp.name + "-position not mapped in existing datafile" );
}
}
}
finally
{
routingContext.unsetWaypoint();
}
}
private MatchedWaypoint _matchNodeForPosition( OsmNodeNamed wp, int minRingWidth )
{
wp.radius = 1e9;
resetCache();
preloadPosition( wp, minRingWidth, 2000 );
nodesCache.distanceChecker = routingContext;
List<OsmNode> nodeList = nodesCache.getAllNodes();
MatchedWaypoint mwp = new MatchedWaypoint();
mwp.waypoint = wp;
// first loop just to expand reverse links
for( OsmNode n : nodeList )
{
if ( !nodesCache.obtainNonHollowNode( n ) )
{
continue;
}
expandHollowLinkTargets( n );
OsmLink startLink = new OsmLink();
startLink.targetNode = n;
OsmPath startPath = new OsmPath( startLink );
startLink.addLinkHolder( startPath );
for( OsmLink link = n.firstlink; link != null; link = link.next )
{
if ( link.descriptionBitmap == null ) continue; // reverse link not found
OsmNode nextNode = link.targetNode;
if ( nextNode.isHollow() ) continue; // border node?
if ( nextNode.firstlink == null ) continue; // don't care about dead ends
if ( nextNode == n ) continue; // ?
double oldRadius = wp.radius;
OsmPath testPath = new OsmPath( n, startPath, link, null, false, routingContext );
if ( wp.radius < oldRadius )
{
if ( testPath.cost < 0 )
{
wp.radius = oldRadius; // no valid way
}
else
{
mwp.node1 = n;
mwp.node2 = nextNode;
mwp.radius = wp.radius;
mwp.crosspoint = new OsmNodeNamed();
mwp.crosspoint.ilon = routingContext.ilonshortest;
mwp.crosspoint.ilat = routingContext.ilatshortest;
}
}
}
}
return mwp;
}
// expand hollow link targets and resolve reverse links
private void expandHollowLinkTargets( OsmNode n )

View file

@ -1,28 +0,0 @@
/**
* Container for routig configs
*
* @author ab
*/
package btools.router;
import btools.expressions.BExpressionReceiver;
final class RoutingMessageHandler implements BExpressionReceiver
{
private int ilon;
private int ilat;
public void setCurrentPos( int lon, int lat)
{
ilon = lon;
ilat = lat;
}
@Override
public void expressionWarning( String context, String message )
{
System.out.println( "message (lon=" + (ilon-180000000) + " lat=" + (ilat-90000000)
+ " context " + context + "): " + message );
}
}