Tweak routing

This commit is contained in:
Victor Shcherb 2012-08-29 01:50:30 +02:00
parent 5740943955
commit 144328766e
7 changed files with 66 additions and 31 deletions

View file

@ -559,25 +559,17 @@ public class BinaryRoutePlanner {
// 2.1 calculate possible obstacle plus time
if(positive){
double obstacle = ctx.getRouter().defineObstacle(road, segmentEnd);
if(obstacle < 0){
if(obstacle == -1) {
plusAllowed = false;
continue;
} else {
obstacle = -obstacle;
}
double obstacle = ctx.getRouter().defineRoutingObstacle(road, segmentEnd);
if (obstacle < 0) {
plusAllowed = false;
continue;
}
obstaclePlusTime += obstacle;
} else {
double obstacle = ctx.getRouter().defineObstacle(road, segmentEnd);
if(obstacle < 0){
if(obstacle == -1) {
minusAllowed = false;
continue;
} else {
obstacle = -obstacle;
}
double obstacle = ctx.getRouter().defineRoutingObstacle(road, segmentEnd);
if (obstacle < 0) {
minusAllowed = false;
continue;
}
obstacleMinusTime += obstacle;
}
@ -846,7 +838,7 @@ public class BinaryRoutePlanner {
distance += d;
double obstacle = ctx.getRouter().defineObstacle(road, j);
if(obstacle < 0) {
obstacle = 30; // configurable ?
obstacle = 0;
}
distOnRoadToPass += d / speed + obstacle;

View file

@ -21,6 +21,7 @@ public class GeneralRouter extends VehicleRouter {
Map<String, Double> highwayFuturePriorities ;
Map<String, Double> avoid ;
Map<String, Double> obstacles;
Map<String, Double> routingObstacles;
Map<String, String> attributes;
@ -50,6 +51,7 @@ public class GeneralRouter extends VehicleRouter {
highwayFuturePriorities = new LinkedHashMap<String, Double>();
avoid = new LinkedHashMap<String, Double>();
obstacles = new LinkedHashMap<String, Double>();
routingObstacles = new LinkedHashMap<String, Double>();
}
public GeneralRouter(GeneralRouter pr) {
@ -58,6 +60,7 @@ public class GeneralRouter extends VehicleRouter {
this.highwayFuturePriorities = new LinkedHashMap<String, Double>(pr.highwayFuturePriorities);
this.avoid = new LinkedHashMap<String, Double>(pr.avoid);
this.obstacles = new LinkedHashMap<String, Double>(pr.obstacles);
this.routingObstacles = new LinkedHashMap<String, Double>(pr.routingObstacles);
this.attributes = new LinkedHashMap<String, String>(pr.attributes);
this.profile = pr.profile;
}
@ -110,8 +113,33 @@ public class GeneralRouter extends VehicleRouter {
int sz = pointTypes.length;
for(int i=0; i<sz; i++) {
RouteTypeRule r = reg.quickGetEncodingRule(pointTypes[i]);
String key = r.getTag() + "$" + r.getValue();
Double v = obstacles.get(key);
Double v = obstacles.get(r.getTag() + "$" + r.getValue());
if(v != null ){
return v;
}
v = obstacles.get(r.getTag() + "$");
if(v != null ){
return v;
}
}
return 0;
}
@Override
public double defineRoutingObstacle(RouteDataObject road, int point) {
int[] pointTypes = road.getPointTypes(point);
if(pointTypes == null) {
return 0;
}
RouteRegion reg = road.region;
int sz = pointTypes.length;
for(int i=0; i<sz; i++) {
RouteTypeRule r = reg.quickGetEncodingRule(pointTypes[i]);
Double v = routingObstacles.get(r.getTag() + "$" + r.getValue());
if(v != null ){
return v;
}
v = routingObstacles.get(r.getTag() + "$");
if(v != null ){
return v;
}
@ -288,6 +316,7 @@ public class GeneralRouter extends VehicleRouter {
gr.specialize(specializationTag, gr.highwaySpeed);
gr.specialize(specializationTag, gr.avoid);
gr.specialize(specializationTag, gr.obstacles);
gr.specialize(specializationTag, gr.routingObstacles);
return gr;
}

View file

@ -167,7 +167,10 @@ public class RoutingConfiguration {
if (previousKey != null) {
String k = in + ":" + previousKey;
if (attributes.getValue("penalty") != null) {
currentRouter.obstacles.put(k, parseSilentDouble(attributes.getValue("penalty"), 0));
double penalty = parseSilentDouble(attributes.getValue("penalty"), 0);
currentRouter.obstacles.put(k, penalty);
double routingPenalty = parseSilentDouble(attributes.getValue("routingPenalty"), penalty );
currentRouter.routingObstacles.put(k, routingPenalty);
}
if (attributes.getValue("priority") != null) {
currentRouter.highwayPriorities.put(k, parseSilentDouble(attributes.getValue("priority"), 0));
@ -200,8 +203,10 @@ public class RoutingConfiguration {
} else if("obstacle".equals(name)) {
previousTag = name;
previousKey = attributes.getValue("tag") + "$" + attributes.getValue("value");
currentRouter.obstacles.put(previousKey, parseSilentDouble(attributes.getValue("penalty"),
0));
double penalty = parseSilentDouble(attributes.getValue("penalty"), 0);
currentRouter.obstacles.put(previousKey, penalty);
double routingPenalty = parseSilentDouble(attributes.getValue("routingPenalty"), penalty );
currentRouter.routingObstacles.put(previousKey, routingPenalty);
} else if("avoid".equals(name)) {
previousTag = name;
previousKey = attributes.getValue("tag") + "$" + attributes.getValue("value");

View file

@ -37,6 +37,11 @@ public abstract class VehicleRouter {
// no obstacles
return 0;
}
public double defineRoutingObstacle(RouteDataObject road, int point) {
// no obstacles
return 0;
}
/**
* return speed in m/s for vehicle for specified road

View file

@ -90,14 +90,18 @@
<road tag="route" value="ferry" speed="15" priority="1.0" dynamicPriority="0.7">
<specialization input="avoid_ferries" speed="0"/>
</road>
<obstacle tag="highway" value="traffic_signals" penalty="15"/>
<!-- usually traffic_signals are not that bad.
It is usuall better to pass via secondary route with TS then residential -->
<obstacle tag="traffic_calming" value="" routingPenalty="10" penalty="8"/>
<obstacle tag="highway" value="traffic_signals" penalty="25" routingPenalty="5"/>
<obstacle tag="railway" value="crossing" penalty="25"/>
<obstacle tag="railway" value="level_crossing" penalty="25"/>
<obstacle tag="motorcar" value="no" penalty="-1"/>
<obstacle tag="barrier" value="lift_gate" penalty="-1000"/>
<obstacle tag="barrier" value="gate" penalty="-1000"/>
<obstacle tag="barrier" value="bollard" penalty="-1000"/>
<obstacle tag="barrier" value="lift_gate" routingPenalty="1000" penalty="25"/>
<obstacle tag="barrier" value="gate" routingPenalty="1000" penalty="25"/>
<obstacle tag="barrier" value="bollard" routingPenalty="1000" penalty="25"/>
<avoid tag="tracktype" value="grade5" decreasedPriority="0.6"/>
<avoid tag="access" value="no"/>

View file

@ -130,6 +130,7 @@ public class NativeSwingRendering extends NativeLibrary {
}
rctx.zoom = zoom;
rctx.tileDivisor = (float) MapUtils.getPowZoom(31 - zoom);
long search = time + System.currentTimeMillis();
final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler,
false, request, true);

View file

@ -1445,13 +1445,12 @@ BinaryMapFile* initBinaryMapFile(std::string inputName) {
}
BinaryMapFile* mapFile = new BinaryMapFile();
mapFile->fd = fileDescriptor;
struct stat stat;
fstat(fileDescriptor, &stat);
mapFile->routefd = routeDescriptor;
bool readFromCache = cache != NULL;
FileIndex* fo = NULL;
if (readFromCache) {
if (cache != NULL) {
struct stat stat;
fstat(fileDescriptor, &stat);
for (int i = 0; i < cache->fileindex_size(); i++) {
FileIndex fi = cache->fileindex(i);
if (hasEnding(inputName, fi.filename()) && fi.size() == stat.st_size) {