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;
|
||||
|
@ -136,6 +136,11 @@ public class GeneralRouter implements VehicleRouter {
|
|||
tagRuleMask = new LinkedHashMap<String, BitSet>();
|
||||
ruleToValue = new ArrayList<Object>();
|
||||
parameters = new LinkedHashMap<String, GeneralRouter.RoutingParameter>();
|
||||
|
||||
priorityCache = new HashMap<>();
|
||||
speedCache = new HashMap<>();
|
||||
obstacleCache = new HashMap<>();
|
||||
penaltyCache = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
|
@ -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.get(region).containsKey(pointTypes)) {
|
||||
return obstacleCache.get(region).get(pointTypes);
|
||||
}
|
||||
} else {
|
||||
if (!obstacleCache.containsKey(region)) {
|
||||
obstacleCache.put(region, new HashMap<int[], Float>());
|
||||
}
|
||||
|
||||
if (obstacleCache.get(region).containsKey(pointTypes)) {
|
||||
return obstacleCache.get(region).get(pointTypes);
|
||||
}
|
||||
|
||||
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.get(regionName).get(road.types) != null) {
|
||||
return speedCache.get(regionName).get(road.types);
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
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.get(regionName).get(road.types) != null) {
|
||||
return priorityCache.get(regionName).get(road.types);
|
||||
}
|
||||
} else {
|
||||
if (!priorityCache.containsKey(regionName)) {
|
||||
priorityCache.put(regionName, new HashMap<int[], Float>());
|
||||
}
|
||||
float sp = getObjContext(RouteDataObjectAttribute.ROAD_PRIORITIES).evaluateFloat(road, 1f);
|
||||
|
||||
if (priorityCache.get(regionName).get(road.types) != null) {
|
||||
return priorityCache.get(regionName).get(road.types);
|
||||
}
|
||||
float sp = getObjContext(RouteDataObjectAttribute.ROAD_PRIORITIES).evaluateFloat(road, 1f);
|
||||
priorityCache.get(regionName).put(road.types, sp);
|
||||
return sp;
|
||||
}
|
||||
|
@ -487,28 +494,25 @@ public class GeneralRouter implements VehicleRouter {
|
|||
String regionPs = prev.getRoad().region.getName();
|
||||
float ts;
|
||||
float prevTs;
|
||||
if (penaltyCache.containsKey(regionS)) {
|
||||
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 {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (penaltyCache.containsKey(regionPs)) {
|
||||
if (penaltyCache.get(regionPs).get(prev.getRoad().types) != null) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue