From 10931da3a7869ffed83f35af72a2e1610ecb9a78 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Thu, 31 May 2018 23:08:24 +0200 Subject: [PATCH] destination access logic --- .../src/main/java/btools/router/OsmPath.java | 70 +++++++++++++++++-- .../java/btools/router/RoutingEngine.java | 5 +- misc/profiles2/car-eco.brf | 12 +++- misc/profiles2/car-fast.brf | 12 +++- 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/OsmPath.java b/brouter-core/src/main/java/btools/router/OsmPath.java index b01fcbe..e50bf24 100644 --- a/brouter-core/src/main/java/btools/router/OsmPath.java +++ b/brouter-core/src/main/java/btools/router/OsmPath.java @@ -46,9 +46,34 @@ abstract class OsmPath implements OsmLinkHolder // the classifier of the segment just before this paths position protected float lastClassifier; + protected float lastInitialCost; protected int priorityclassifier; + private static final int PATH_START_BIT = 1; + private static final int CAN_LEAVE_DESTINATION_BIT = 2; + private static final int IS_ON_DESTINATION_BIT = 4; + private static final int HAD_DESTINATION_START_BIT = 8; + protected int bitfield = PATH_START_BIT; + + private boolean getBit( int mask ) + { + return (bitfield & mask ) != 0; + } + + private void setBit( int mask, boolean bit ) + { + if ( getBit( mask ) != bit ) + { + bitfield ^= mask; + } + } + + public boolean didEnterDestinationArea() + { + return !getBit( HAD_DESTINATION_START_BIT ) && getBit( IS_ON_DESTINATION_BIT ); + } + public MessageData message; public void unregisterUpTree( RoutingContext rc ) @@ -99,6 +124,8 @@ abstract class OsmPath implements OsmLinkHolder this.targetNode = link.getTarget( sourceNode ); this.cost = origin.cost; this.lastClassifier = origin.lastClassifier; + this.lastInitialCost = origin.lastInitialCost; + this.bitfield = origin.bitfield; init( origin ); addAddionalPenalty(refTrack, detailMode, origin, link, rc ); } @@ -140,15 +167,20 @@ abstract class OsmPath implements OsmLinkHolder boolean isTrafficBackbone = cost == 0 && rc.expctxWay.getIsTrafficBackbone() > 0.f; int lastpriorityclassifier = priorityclassifier; priorityclassifier = (int)rc.expctxWay.getPriorityClassifier(); - int classifiermask = (int)rc.expctxWay.getClassifierMask(); // *** add initial cost if the classifier changed float newClassifier = rc.expctxWay.getInitialClassifier(); + float newInitialCost = rc.expctxWay.getInitialcost(); float classifierDiff = newClassifier - lastClassifier; - if ( classifierDiff > 0.0005 || classifierDiff < -0.0005 ) + if ( newClassifier != 0. && lastClassifier != 0. && ( classifierDiff > 0.0005 || classifierDiff < -0.0005 ) ) { - lastClassifier = newClassifier; - float initialcost = rc.expctxWay.getInitialcost(); + float initialcost = rc.inverseDirection ? lastInitialCost : newInitialCost; + if ( initialcost >= 1000000. ) + { + cost = -1; + return; + } + int iicost = (int)initialcost; if ( message != null ) { @@ -156,6 +188,36 @@ abstract class OsmPath implements OsmLinkHolder } cost += iicost; } + lastClassifier = newClassifier; + lastInitialCost = newInitialCost; + + // *** destination logic: no destination access in between + int classifiermask = (int)rc.expctxWay.getClassifierMask(); + boolean newDestination = (classifiermask & 64) != 0; + boolean oldDestination = getBit( IS_ON_DESTINATION_BIT ); + if ( getBit( PATH_START_BIT ) ) + { + setBit( PATH_START_BIT, false ); + setBit( CAN_LEAVE_DESTINATION_BIT, newDestination ); + setBit( HAD_DESTINATION_START_BIT, newDestination ); + } + else + { + if ( oldDestination && !newDestination ) + { + if ( getBit( CAN_LEAVE_DESTINATION_BIT ) ) + { + setBit( CAN_LEAVE_DESTINATION_BIT, false ); + } + else + { + cost = -1; + return; + } + } + } + setBit( IS_ON_DESTINATION_BIT, newDestination ); + OsmTransferNode transferNode = link.geometry == null ? null : rc.geometryDecoder.decodeGeometry( link.geometry, sourceNode, targetNode, isReverse ); diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 4c28dde..bb2ad9e 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -903,7 +903,10 @@ public class RoutingEngine extends Thread long currentNodeId = currentNode.getIdFromPos(); long sourceNodeId = sourceNode.getIdFromPos(); - islandNodePairs.addTempPair( sourceNodeId, currentNodeId ); + if ( !path.didEnterDestinationArea() ) + { + islandNodePairs.addTempPair( sourceNodeId, currentNodeId ); + } if ( path.treedepth != 1 ) { diff --git a/misc/profiles2/car-eco.brf b/misc/profiles2/car-eco.brf index bc7a10d..f1ab2e6 100644 --- a/misc/profiles2/car-eco.brf +++ b/misc/profiles2/car-eco.brf @@ -52,6 +52,15 @@ assign caraccess motor_vehicle=yes|permissive|designated|destination motorcar=yes|permissive|designated|destination +assign caraccess_destination + switch motorcar= + switch motor_vehicle= + switch vehicle= + access=destination + vehicle=destination + motor_vehicle=destination + motorcar=destination + assign accessspeedlimit = if caraccess then 999 else 0 assign isbadoneway = if reversedirection=yes then ( if oneway= then junction=roundabout else oneway=yes|true|1 ) else oneway=-1 @@ -150,7 +159,8 @@ assign classifiermask add isbadoneway add multiply isroundabout 4 add multiply islinktype 8 add multiply isgoodforcars 16 - multiply highway=residential|living_street 32 + add multiply highway=residential|living_street 32 + multiply caraccess_destination 64 ---context:node # following code refers to node tags diff --git a/misc/profiles2/car-fast.brf b/misc/profiles2/car-fast.brf index ab6a494..797213a 100644 --- a/misc/profiles2/car-fast.brf +++ b/misc/profiles2/car-fast.brf @@ -52,6 +52,15 @@ assign caraccess motor_vehicle=yes|permissive|designated|destination motorcar=yes|permissive|designated|destination +assign caraccess_destination + switch motorcar= + switch motor_vehicle= + switch vehicle= + access=destination + vehicle=destination + motor_vehicle=destination + motorcar=destination + assign accessspeedlimit = if caraccess then 999 else 0 assign isbadoneway = if reversedirection=yes then ( if oneway= then junction=roundabout else oneway=yes|true|1 ) else oneway=-1 @@ -150,7 +159,8 @@ assign classifiermask add isbadoneway add multiply isroundabout 4 add multiply islinktype 8 add multiply isgoodforcars 16 - multiply highway=residential|living_street 32 + add multiply highway=residential|living_street 32 + multiply caraccess_destination 64 ---context:node # following code refers to node tags