Implement increasing road priority algorithm (so in the middle routing does not attempt to work with low priorities roads

This commit is contained in:
Victor Shcherb 2011-07-05 10:22:33 +02:00
parent 8c47374245
commit 01d7a74f2c
5 changed files with 48 additions and 5 deletions

View file

@ -84,6 +84,7 @@ public class BicycleRouter extends VehicleRouter {
} }
return false; return false;
} }
public boolean isOneWay(int highwayAttributes) { public boolean isOneWay(int highwayAttributes) {
return MapRenderingTypes.isOneWayWay(highwayAttributes) || MapRenderingTypes.isRoundabout(highwayAttributes); return MapRenderingTypes.isOneWayWay(highwayAttributes) || MapRenderingTypes.isRoundabout(highwayAttributes);

View file

@ -203,11 +203,13 @@ public class BinaryRoutePlanner {
// Extract & analyze segment with min(f(x)) from queue while final segment is not found // Extract & analyze segment with min(f(x)) from queue while final segment is not found
boolean inverse = false; boolean inverse = false;
double roadDirectPriority = 0;
double roadOppositePriority = 0;
PriorityQueue<RouteSegment> graphSegments = inverse ? graphReverseSegments : graphDirectSegments; PriorityQueue<RouteSegment> graphSegments = inverse ? graphReverseSegments : graphDirectSegments;
while(!graphSegments.isEmpty()){ while(!graphSegments.isEmpty()){
RouteSegment segment = graphSegments.poll(); RouteSegment segment = graphSegments.poll();
ctx.visitedSegments ++; ctx.visitedSegments ++;
// for debug purposes // for debug purposes
if (ctx.visitor != null) { if (ctx.visitor != null) {
@ -234,7 +236,8 @@ public class BinaryRoutePlanner {
break; break;
} }
inverse = nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) > 0; inverse = nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) > 0;
// inverse = !inverse; // different strategy : use onedirectional graph
// inverse = true;
graphSegments = inverse ? graphReverseSegments : graphDirectSegments; graphSegments = inverse ? graphReverseSegments : graphDirectSegments;
} }
@ -388,9 +391,18 @@ public class BinaryRoutePlanner {
oppSegment.segmentEnd = next.segmentStart; oppSegment.segmentEnd = next.segmentStart;
return oppSegment; return oppSegment;
} }
boolean processRoad = true;
if (ctx.useStrategyOfIncreasingRoadPriorities) {
double roadPriority = ctx.router.getRoadPriority(segment.road);
double nextRoadPriority = ctx.router.getRoadPriority(segment.road);
if (nextRoadPriority < roadPriority) {
processRoad = false;
}
}
/* next.road.getId() >> 3 (1) != road.getId() >> 3 (1) - used that line for debug with osm map */ /* next.road.getId() >> 3 (1) != road.getId() >> 3 (1) - used that line for debug with osm map */
// road.id could be equal on roundabout, but we should accept them // road.id could be equal on roundabout, but we should accept them
if (!visitedSegments.contains(nts)) { if (!visitedSegments.contains(nts) && processRoad) {
int type = -1; int type = -1;
for (int i = 0; i < road.getRestrictionCount(); i++) { for (int i = 0; i < road.getRestrictionCount(); i++) {
if (road.getRestriction(i) == next.road.getId()) { if (road.getRestriction(i) == next.road.getId()) {
@ -621,6 +633,7 @@ public class BinaryRoutePlanner {
public static class RoutingContext { public static class RoutingContext {
// parameters of routing // parameters of routing
public int heuristicCoefficient = DEFAULT_HEURISTIC_COEFFICIENT; public int heuristicCoefficient = DEFAULT_HEURISTIC_COEFFICIENT;
public boolean useStrategyOfIncreasingRoadPriorities = true;
public VehicleRouter router = new CarRouter(); public VehicleRouter router = new CarRouter();
// //

View file

@ -95,6 +95,25 @@ public class CarRouter extends VehicleRouter {
} }
return 0; return 0;
} }
@Override
public double getRoadPriority(BinaryMapDataObject road) {
TagValuePair pair = road.getTagValue(0);
boolean highway = "highway".equals(pair.tag);
double priority = highway && autoPriorityValues.containsKey(pair.value) ? autoPriorityValues.get(pair.value) : 0.5d;
if("motorway_link".equals(pair.value) || "trunk".equals(pair.value) ||
"trunk_link".equals(pair.value) || "motorway".equals(pair.value)) {
return 1.3d;
} else if(priority >= 1){
return 1;
} else if(priority >= 0.7){
return 0.7;
} else if(priority >= 0.5){
return 0.5;
} else {
return 0.3;
}
}
/** /**
* return speed in m/s * return speed in m/s
@ -103,7 +122,7 @@ public class CarRouter extends VehicleRouter {
TagValuePair pair = road.getTagValue(0); TagValuePair pair = road.getTagValue(0);
double speed = MapRenderingTypes.getMaxSpeedIfDefined(road.getHighwayAttributes()) / 3.6d; double speed = MapRenderingTypes.getMaxSpeedIfDefined(road.getHighwayAttributes()) / 3.6d;
boolean highway = "highway".equals(pair.tag); boolean highway = "highway".equals(pair.tag);
double priority = highway && autoPriorityValues.containsKey(pair.value) ? autoPriorityValues.get(pair.value) : 1d; double priority = highway && autoPriorityValues.containsKey(pair.value) ? autoPriorityValues.get(pair.value) : 0.5d;
if (speed == 0 && highway) { if (speed == 0 && highway) {
Double value = autoNotDefinedValues.get(pair.value); Double value = autoNotDefinedValues.get(pair.value);
if (value == null) { if (value == null) {

View file

@ -28,6 +28,16 @@ public abstract class VehicleRouter {
int attributes = road.getHighwayAttributes(); int attributes = road.getHighwayAttributes();
return MapRenderingTypes.isOneWayWay(attributes) || MapRenderingTypes.isRoundabout(attributes); return MapRenderingTypes.isOneWayWay(attributes) || MapRenderingTypes.isRoundabout(attributes);
} }
/**
* Used for algorithm of increasing road priorities (actually make sense only for car routing)
* other routers can increase/decrease road priorities in the middle of route
* @param road
* @return
*/
public double getRoadPriority(BinaryMapDataObject road) {
return 1;
}
/** /**
* return delay in seconds * return delay in seconds

View file

@ -49,7 +49,7 @@ import org.xml.sax.SAXException;
public class MapRouterLayer implements MapPanelLayer { public class MapRouterLayer implements MapPanelLayer {
private /*final */ static boolean ANIMATE_CALCULATING_ROUTE = false; private /*final */ static boolean ANIMATE_CALCULATING_ROUTE = false;
private /*final */ static int SIZE_OF_ROUTES_TO_ANIMATE = 50; private /*final */ static int SIZE_OF_ROUTES_TO_ANIMATE = 250;
private MapPanel map; private MapPanel map;