Skip to content

Commit

Permalink
update calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed May 14, 2024
1 parent 9392b05 commit 9da5216
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,33 @@
*/
public class HBSRoadCapacity implements Predictor {
/**
* Capacity on primary roads (Landstraße)
* Capacity on "Landstraße", often osm secondary
*/
private static double capacityHighway(int lanes) {

// There is currently no way to differentiate Landstraße and Stadtstraße which can both have up to 70km/h
private static double capacityLandStr(int lanes) {

if (lanes == 1)
return 2846.990116534646;
return 1369.532383465354;

if (lanes == 2)
return 3913.3439999999996 / 2;
return 1956.6719999999998 / 2;

// Own assumption of increasing capacity with more lanes
// This is not covered by the HBS and is a very rare case
return (3913.3439999999996 * 1.3) / lanes;
return (1956.6719999999998 * 1.3) / lanes;
}

/**
* Bundesstraße with at least 70km/h, often osm primary or trunk
*/
private static double capacityBundesStr(int lanes) {

if (lanes == 1)
return 2033.868926820213;

if (lanes == 2)
return 3902.4390243902435 / 2;

return (3902.4390243902435 * 1.3) / lanes;
}

/**
Expand Down Expand Up @@ -53,9 +65,11 @@ private static double capacityMerging(double qP) {
*/
private static double capacityMerging(String roadType, String mainType) {

if (mainType.equals("primary"))
if (mainType.equals("trunk") || mainType.equals("primary") || roadType.contains("residential"))
// ~600 veh/h
return capacityMerging(600);

// ~800 veh/h
return capacityMerging(400);
}

Expand All @@ -65,16 +79,22 @@ public double predict(Object2DoubleMap<String> features, Object2ObjectMap<String
// Speed in km/h
int speed = (int) Math.round(features.getDouble("speed") * 3.6);
int lanes = (int) features.getOrDefault("lanes", 1);

if (speed >= 70) {
return capacityHighway(lanes);
String type = categories.get("highway_type");

// Primary and trunk roads are often Bundesstraßen,
// but only if they have a speed limit of 70 or more, this calculation is valid
// From OSM alone it is not possible to distinguish anbaufreie Hauptverkehrsstraßen and Landstraße clearly
if (speed >= 90 || ( (type.contains("primary") || type.contains("trunk")) && speed >= 70)) {
return capacityBundesStr(lanes);
} else if (speed >= 70) {
return capacityLandStr(lanes);
}

String merging = categories.get("is_merging_into");

// Only merging with a single lane road is considered
if (!merging.isEmpty() && lanes == 1) {
return capacityMerging(categories.get("highway_type"), merging);
return capacityMerging(type, merging);
}

// Capacity for city roads
Expand Down
13 changes: 8 additions & 5 deletions contribs/application/src/main/python/capacity/hbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def calc_capacity_stadtstrasse(street):
k = 40
a = 89
b = 0.846

return (-1.0 * b * math.pow(k, 3/2) * math.sqrt(4 * a * f + b * b * k) + 2 * a * f * k + b * b * k * k)/(2 * f * f)
elif street.lanes == 2:
f = 0.7
Expand All @@ -50,25 +51,27 @@ def calc_capacity_stadtstrasse(street):
a = -0.009
b = 55.58
elif street.speed == 70:
f = 0.5
k = 40
a = -0.008
b = 80

return (b * k)/(f - a * k)

def calc_capacity_landstrasse(street):
# Source: HSB L3
# Source: HSB table L3-4
if street.lanes == 1:
k = 20
a = 98.73
b = 0.8175
m = 1.0
return 0.5 * (b * math.pow(k, 3/2) * math.pow(m, 3/2) * math.sqrt(4 * a + b * b * k * m) - k * m * (b * b * -1.0 * k * m - 2 * a))
return 0.5 * (-b * math.pow(k, 3/2) * math.sqrt(4 * a + b * b * k) + 2 * a * k + b*b*k*k)
if street.lanes == 2:
k = 48
m = 1.0
a = 55.5
b = -0.614
return k * m * (2 * a + b * k * m)

# Divide by 2 because the formula is for both directions
return k * (2 * a + b * k) / 2

def calc_capacity_autobahn(street):
# Source: HSB A3
Expand Down

0 comments on commit 9da5216

Please sign in to comment.