27
27
* @author Andrzej Oles
28
28
*/
29
29
public class LimitedAccessWeighting extends AbstractAdjustedWeighting {
30
+ public static final double MIN_FACTOR = 1 ;// ensure that we do not need to change getMinWeight, i.e. road_access_factor >= 1
31
+ public static final double MAX_FACTOR = 10 ;
30
32
public static final double DEFAULT_DESTINATION_FACTOR = 1 ;
31
33
public static final double VEHICLE_DESTINATION_FACTOR = 10 ;
32
34
public static final double DEFAULT_PRIVATE_FACTOR = 1.2 ;
33
35
public static final double VEHICLE_PRIVATE_FACTOR = 10 ;
34
36
public static final double DEFAULT_CUSTOMERS_FACTOR = 1.2 ;
35
37
public static final double VEHICLE_CUSTOMERS_FACTOR = 1.5 ;
36
38
37
- static double MIN_DESTINATION_FACTOR = 1 ;
38
- static double MAX_DESTINATION_FACTOR = 10 ;
39
- static double MIN_PRIVATE_FACTOR = 1 ;
40
- static double MAX_PRIVATE_FACTOR = 10 ;
41
- static double MIN_CUSTOMERS_FACTOR = 1 ;
42
- static double MAX_CUSTOMERS_FACTOR = 10 ;
43
-
44
39
private final EnumEncodedValue <RoadAccess > roadAccessEnc ;
45
40
// this factor puts a penalty on roads with a "destination"-only or private access, see GH#733 and GH#1936
46
41
private final double destinationPenalty ;
47
42
private final double privatePenalty ;
43
+ // this factor puts a penalty on roads with a "customers"-only access, see ORS#1981
48
44
private final double customersPenalty ;
49
45
50
46
public LimitedAccessWeighting (Weighting superWeighting , PMap map ) {
@@ -53,16 +49,18 @@ public LimitedAccessWeighting(Weighting superWeighting, PMap map) {
53
49
if (!encoder .hasEncodedValue (RoadAccess .KEY ))
54
50
throw new IllegalArgumentException ("road_access is not available" );
55
51
56
- // ensure that we do not need to change getMinWeight, i.e. road_access_factor >= 1
57
- double defaultDestinationFactor = encoder .getTransportationMode ().isMotorVehicle () ? VEHICLE_DESTINATION_FACTOR : DEFAULT_DESTINATION_FACTOR ;
58
- destinationPenalty = checkBounds ("road_access_destination_factor" , map .getDouble ("road_access_destination_factor" , defaultDestinationFactor ), MIN_DESTINATION_FACTOR , MAX_DESTINATION_FACTOR );
59
- double defaultPrivateFactor = encoder .getTransportationMode ().isMotorVehicle () ? VEHICLE_PRIVATE_FACTOR : DEFAULT_PRIVATE_FACTOR ;
60
- privatePenalty = checkBounds ("road_access_private_factor" , map .getDouble ("road_access_private_factor" , defaultPrivateFactor ), MIN_PRIVATE_FACTOR , MAX_PRIVATE_FACTOR );
61
- double defaultCustomersFactor = encoder .getTransportationMode ().isMotorVehicle () ? VEHICLE_CUSTOMERS_FACTOR : DEFAULT_CUSTOMERS_FACTOR ;
62
- customersPenalty = checkBounds ("road_access_customers_factor" , map .getDouble ("road_access_customers_factor" , defaultCustomersFactor ), MIN_CUSTOMERS_FACTOR , MAX_CUSTOMERS_FACTOR );
52
+ destinationPenalty = getFactorValue (encoder , map , "road_access_destination_factor" , DEFAULT_DESTINATION_FACTOR , VEHICLE_DESTINATION_FACTOR );
53
+ privatePenalty = getFactorValue (encoder , map , "road_access_private_factor" , DEFAULT_PRIVATE_FACTOR , VEHICLE_PRIVATE_FACTOR );
54
+ customersPenalty = getFactorValue (encoder , map , "road_access_customers_factor" , DEFAULT_CUSTOMERS_FACTOR , VEHICLE_CUSTOMERS_FACTOR );
55
+
63
56
roadAccessEnc = destinationPenalty > 1 || privatePenalty > 1 || customersPenalty > 1 ? encoder .getEnumEncodedValue (RoadAccess .KEY , RoadAccess .class ) : null ;
64
57
}
65
58
59
+ static double getFactorValue (FlagEncoder encoder , PMap map , String key , double defaultFactor , double vehicleFactor ) {
60
+ double defaultValue = encoder .getTransportationMode ().isMotorVehicle () ? vehicleFactor : defaultFactor ;
61
+ return checkBounds (key , map .getDouble (key , defaultValue ), MIN_FACTOR , MAX_FACTOR );
62
+ }
63
+
66
64
static double checkBounds (String key , double val , double from , double to ) {
67
65
if (val < from || val > to )
68
66
throw new IllegalArgumentException (key + " has invalid range should be within [" + from + ", " + to + "]" );
0 commit comments