refactoring
This commit is contained in:
parent
40737935ea
commit
b43fb6332a
1 changed files with 42 additions and 38 deletions
|
@ -53,10 +53,10 @@ public class GeneralRouter implements VehicleRouter {
|
|||
private String filename = null;
|
||||
private String profileName = "";
|
||||
|
||||
Map<String, Map<int[], Float>> priorityCache = new HashMap<>();
|
||||
Map<String, Map<int[], Float>> speedCache = new HashMap<>();
|
||||
Map<String, Map<int[], Float>> obstacleCache = new HashMap<>();
|
||||
Map<String, Map<int[], Float>> penaltyCache = new HashMap<>();
|
||||
Map<String, Map<int[], Float>> priorityCache;
|
||||
Map<String, Map<int[], Float>> speedCache;
|
||||
Map<String, Map<int[], Float>> obstacleCache;
|
||||
Map<String, Map<int[], Float>> penaltyCache;
|
||||
|
||||
int count = 0;
|
||||
int count2 = 0;
|
||||
|
@ -137,6 +137,11 @@ public class GeneralRouter implements VehicleRouter {
|
|||
ruleToValue = new ArrayList<Object>();
|
||||
parameters = new LinkedHashMap<String, GeneralRouter.RoutingParameter>();
|
||||
|
||||
priorityCache = new HashMap<>();
|
||||
speedCache = new HashMap<>();
|
||||
obstacleCache = new HashMap<>();
|
||||
penaltyCache = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
|
@ -189,6 +194,11 @@ public class GeneralRouter implements VehicleRouter {
|
|||
if (params.containsKey(MAX_SPEED)) {
|
||||
maxSpeed = parseSilentFloat(params.get(MAX_SPEED), maxSpeed);
|
||||
}
|
||||
|
||||
priorityCache = new HashMap<>();
|
||||
speedCache = new HashMap<>();
|
||||
obstacleCache = new HashMap<>();
|
||||
penaltyCache = new HashMap<>();
|
||||
}
|
||||
|
||||
public GeneralRouterProfile getProfile() {
|
||||
|
@ -353,19 +363,20 @@ public class GeneralRouter implements VehicleRouter {
|
|||
public float defineRoutingObstacle(RouteDataObject road, int point) {
|
||||
int[] pointTypes = road.getPointTypes(point);
|
||||
String region = road.region.getName();
|
||||
if (obstacleCache.containsKey(region)) {
|
||||
if (!obstacleCache.containsKey(region)) {
|
||||
obstacleCache.put(region, new HashMap<int[], Float>());
|
||||
}
|
||||
|
||||
if (obstacleCache.get(region).containsKey(pointTypes)) {
|
||||
return obstacleCache.get(region).get(pointTypes);
|
||||
}
|
||||
} else {
|
||||
obstacleCache.put(region, new HashMap<int[], Float>());
|
||||
}
|
||||
|
||||
if(pointTypes != null){
|
||||
float obst = getObjContext(RouteDataObjectAttribute.ROUTING_OBSTACLES).evaluateFloat(road.region, pointTypes, 0);
|
||||
obstacleCache.get(region).put(pointTypes, obst);
|
||||
return obst;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -418,16 +429,14 @@ public class GeneralRouter implements VehicleRouter {
|
|||
@Override
|
||||
public float defineRoutingSpeed(RouteDataObject road) {
|
||||
String regionName = road.region.getName();
|
||||
if (speedCache.containsKey(regionName)) {
|
||||
if (!speedCache.containsKey(regionName)) {
|
||||
speedCache.put(regionName, new HashMap<int[], Float>());
|
||||
}
|
||||
if (speedCache.get(regionName).get(road.types) != null) {
|
||||
return speedCache.get(regionName).get(road.types);
|
||||
}
|
||||
} else {
|
||||
speedCache.put(regionName, new HashMap<int[], Float>());
|
||||
}
|
||||
float spd = getObjContext(RouteDataObjectAttribute.ROAD_SPEED).evaluateFloat(road, defaultSpeed);
|
||||
float definedSpd = Math.max(Math.min(spd, maxSpeed), minSpeed);
|
||||
|
||||
speedCache.get(regionName).put(road.types, definedSpd);
|
||||
return definedSpd;
|
||||
}
|
||||
|
@ -441,15 +450,13 @@ public class GeneralRouter implements VehicleRouter {
|
|||
@Override
|
||||
public float defineSpeedPriority(RouteDataObject road) {
|
||||
String regionName = road.region.getName();
|
||||
if (priorityCache.containsKey(regionName)) {
|
||||
if (!priorityCache.containsKey(regionName)) {
|
||||
priorityCache.put(regionName, new HashMap<int[], Float>());
|
||||
}
|
||||
if (priorityCache.get(regionName).get(road.types) != null) {
|
||||
return priorityCache.get(regionName).get(road.types);
|
||||
}
|
||||
} else {
|
||||
priorityCache.put(regionName, new HashMap<int[], Float>());
|
||||
}
|
||||
float sp = getObjContext(RouteDataObjectAttribute.ROAD_PRIORITIES).evaluateFloat(road, 1f);
|
||||
|
||||
priorityCache.get(regionName).put(road.types, sp);
|
||||
return sp;
|
||||
}
|
||||
|
@ -487,31 +494,28 @@ public class GeneralRouter implements VehicleRouter {
|
|||
String regionPs = prev.getRoad().region.getName();
|
||||
float ts;
|
||||
float prevTs;
|
||||
if (penaltyCache.containsKey(regionS)) {
|
||||
|
||||
if (!penaltyCache.containsKey(regionS)) {
|
||||
penaltyCache.put(regionS, new HashMap<int[], Float>());
|
||||
}
|
||||
//maybe we don't need it? region should already be present in cache
|
||||
if (!penaltyCache.containsKey(regionPs)) {
|
||||
penaltyCache.put(regionPs, new HashMap<int[], Float>());
|
||||
}
|
||||
|
||||
if (penaltyCache.get(regionS).get(segment.getRoad().types) != null) {
|
||||
ts = penaltyCache.get(regionS).get(segment.getRoad().types);
|
||||
} else {
|
||||
ts = getPenaltyTransition(segment.getRoad());
|
||||
penaltyCache.get(regionS).put(segment.getRoad().types, ts);
|
||||
}
|
||||
} else {
|
||||
penaltyCache.put(regionS, new HashMap<int[], Float>());
|
||||
ts = getPenaltyTransition(segment.getRoad());
|
||||
penaltyCache.get(regionS).put(segment.getRoad().types, ts);
|
||||
}
|
||||
|
||||
if (penaltyCache.containsKey(regionPs)) {
|
||||
if (penaltyCache.get(regionPs).get(prev.getRoad().types) != null) {
|
||||
prevTs = penaltyCache.get(regionPs).get(prev.getRoad().types);
|
||||
} else {
|
||||
prevTs = getPenaltyTransition(prev.getRoad());
|
||||
penaltyCache.get(regionPs).put(prev.getRoad().types, prevTs);
|
||||
}
|
||||
} else {
|
||||
penaltyCache.put(regionPs, new HashMap<int[], Float>());
|
||||
prevTs = getPenaltyTransition(prev.getRoad());
|
||||
penaltyCache.get(regionPs).put(prev.getRoad().types, prevTs);
|
||||
}
|
||||
|
||||
if(prevTs != ts) {
|
||||
return Math.abs(ts - prevTs) / 2;
|
||||
|
|
Loading…
Reference in a new issue