Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/network-improvments' into networ…
Browse files Browse the repository at this point in the history
…k-improvments
  • Loading branch information
rakow committed May 26, 2024
2 parents b249b4c + 47aa4bd commit 033f872
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 55 deletions.
121 changes: 73 additions & 48 deletions contribs/application/src/main/python/capacity/hbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import matplotlib.pyplot as plt
import plotly.graph_objects as go


def capacity_estimate(v):
# headway
tT = 1.2
Expand All @@ -10,16 +11,20 @@ def capacity_estimate(v):
Qc = v / (v * tT + lL)
return 3600 * Qc


def merge(qp=400):
tf = 3.5
tg = 6.36
return math.exp((-qp / 3600) * (tg - tf / 2)) * 3600 / tf


class Street:
def __init__(self, osm_type, lanes, speed):
def __init__(self, osm_type, lanes, speed, curvature):
self.osm_type = osm_type
self.lanes = lanes
self.speed = speed
self.curvature = curvature


def calc_capacity_stadtstrasse(street):
# Source: HSB S3
Expand All @@ -43,7 +48,8 @@ def calc_capacity_stadtstrasse(street):
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)
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
if street.speed == 50:
Expand All @@ -56,15 +62,16 @@ def calc_capacity_stadtstrasse(street):
a = -0.008
b = 80

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


def calc_capacity_landstrasse(street):
# Source: HSB table L3-4
if street.lanes == 1:
k = 20
a = 98.73
b = 0.8175
return 0.5 * (-b * math.pow(k, 3/2) * math.sqrt(4 * a + b * b * k) + 2 * a * k + b*b*k*k)
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
a = 55.5
Expand All @@ -73,6 +80,7 @@ def calc_capacity_landstrasse(street):
# 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
anzahl_fahrstreifen = 1
Expand All @@ -98,13 +106,15 @@ def calc_capacity_autobahn(street):
elif street.speed <= 120:
return 7400 / anzahl_fahrstreifen


osm_types = {
'residential': 'Stadtstraßen',
'unclassified': 'Landstraßen',
'motorway': 'Autobahnen'
}

speeds = [30, 50, 70, 80, 90, 100, 120, 130]
curvatures = [1, 2, 3, 4]

capacities = {}
streets = []
Expand All @@ -113,16 +123,20 @@ def calc_capacity_autobahn(street):
capacities[osm_type] = {}
for lanes in range(1, 5):
capacities[osm_type][lanes] = {}
for speed in speeds:
if (osm_type == 'residential' and speed > 70) or (osm_type == 'residential' and speed < 30) or (osm_type == 'residential' and lanes > 2):
continue
if (osm_type == 'unclassified' and speed > 100) or (osm_type == 'unclassified' and speed <= 50) or (osm_type == 'unclassified' and lanes > 2):
continue
if (osm_type == 'motorway' and lanes == 1) or (osm_type == 'motorway' and speed < 80):
continue
street = Street(osm_type, lanes, speed)
streets.append(street)
capacities[osm_type][lanes][speed] = 0
for curvature in curvatures:
capacities[osm_type][lanes][curvature] = {}
for speed in speeds:
if (osm_type == 'residential' and speed > 70) or (osm_type == 'residential' and speed < 30) or (
osm_type == 'residential' and lanes > 2):
continue
if (osm_type == 'unclassified' and speed > 100) or (osm_type == 'unclassified' and speed <= 50) or (
osm_type == 'unclassified' and lanes > 2):
continue
if (osm_type == 'motorway' and lanes == 1) or (osm_type == 'motorway' and speed < 80):
continue
street = Street(osm_type, lanes, speed, curvature)
streets.append(street)
capacities[osm_type][lanes][curvature][speed] = 0

for street in streets:
capacity = 0
Expand All @@ -132,18 +146,29 @@ def calc_capacity_autobahn(street):
capacity = calc_capacity_autobahn(street)
else:
capacity = calc_capacity_landstrasse(street)
capacities[street.osm_type][street.lanes][street.speed] = capacity
capacities[street.osm_type][street.lanes][street.curvature][street.speed] = capacity

for street_type, lanes_capacity in capacities.items():
for lanes, speeds_capacity in lanes_capacity.items():
print(f"{osm_types[street_type]}, Fahrstreifen: {lanes}:")
for speed, capacity in speeds_capacity.items():
print(f"Geschwindigkeit {speed} km/h: Verkehrskapazität {capacity}")
for curvature, capacity in speeds_capacity.items():
for speed, capacity in capacity.items():
print(f"Geschwindigkeit {speed} km/h: Kurvigkeit {curvature} Verkehrskapazität {capacity} ")

plt.figure(figsize=(14, 10))
for street_type, lanes_capacity in capacities.items():
for lanes, speeds_capacity in lanes_capacity.items():
plt.plot(list(speeds_capacity.keys()), list(speeds_capacity.values()), label=f"{osm_types[street_type]}, Fahrstreifen: {lanes}")
for curvature, capacity in speeds_capacity.items():
plt.plot(list(capacity.keys()), list(capacity.values()),
label=f"{osm_types[street_type]}, Fahrstreifen: {lanes} Kurvigkeit: {curvature}")

# plt.figure(figsize=(14, 10))
# for street_type, lanes_capacity in capacities.items():
# for lanes, speeds_capacity in lanes_capacity.items():
# for speed, curvatures_capacity in speeds_capacity.items():
# for curvature, capacity in curvatures_capacity.items():
# plt.plot(speed, capacity,
# label=f"{osm_types[street_type]}, Fahrstreifen: {lanes}, Kurvigkeit: {curvature}")

speeds_compare = []
capacity_compare = []
Expand All @@ -159,33 +184,33 @@ def calc_capacity_autobahn(street):
plt.subplots_adjust(bottom=0.3)
plt.show()

fig = go.Figure()

for street_type, lanes_capacity in capacities.items():
for lanes, speeds_capacity in lanes_capacity.items():
fig.add_trace(go.Scatter(x=list(speeds_capacity.keys()), y=list(speeds_capacity.values()),
mode='lines',
name=f"{osm_types[street_type]}, Fahrstreifen: {lanes}"))

speeds_compare = []
capacity_compare = []
for v in range(50, 140, 10):
speeds_compare.append(v)
capacity_compare.append(capacity_estimate(v))
fig.add_trace(go.Scatter(x=speeds_compare, y=capacity_compare, mode='lines', showlegend=True, name="REFERENZ"))

for qp in (0, 200, 400, 600):
kontenpunkt_y = []
kontenpunkt_y.append(merge(qp))
kontenpunkt_y.append(merge(qp))
fig.add_trace(go.Scatter(x=(30, 50), y=kontenpunkt_y, mode='lines', showlegend=True, name="Knotenpunkt %d" % qp))

fig.update_layout(
title='Verkehrskapazität nach Straßentyp, Fahrstreifen und Geschwindigkeit',
xaxis_title='Geschwindigkeit (km/h)',
yaxis_title='Verkehrskapazität',
legend=dict(x=0.5, y=-0.2, orientation='h'),
margin=dict(b=100)
)

fig.show()
# fig = go.Figure()
#
# for street_type, lanes_capacity in capacities.items():
# for lanes, speeds_capacity in lanes_capacity.items():
# fig.add_trace(go.Scatter(x=list(speeds_capacity.keys()), y=list(speeds_capacity.values()),
# mode='lines',
# name=f"{osm_types[street_type]}, Fahrstreifen: {lanes}"))
#
# speeds_compare = []
# capacity_compare = []
# for v in range(50, 140, 10):
# speeds_compare.append(v)
# capacity_compare.append(capacity_estimate(v))
# fig.add_trace(go.Scatter(x=speeds_compare, y=capacity_compare, mode='lines', showlegend=True, name="REFERENZ"))
#
# for qp in (0, 200, 400, 600):
# kontenpunkt_y = []
# kontenpunkt_y.append(merge(qp))
# kontenpunkt_y.append(merge(qp))
# fig.add_trace(go.Scatter(x=(30, 50), y=kontenpunkt_y, mode='lines', showlegend=True, name="Knotenpunkt %d" % qp))
#
# fig.update_layout(
# title='Verkehrskapazität nach Straßentyp, Fahrstreifen und Geschwindigkeit',
# xaxis_title='Geschwindigkeit (km/h)',
# yaxis_title='Verkehrskapazität',
# legend=dict(x=0.5, y=-0.2, orientation='h'),
# margin=dict(b=100)
# )
#
# fig.show()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SumoNetworkFeatureExtractor {
incomingEdges = new HashMap<>();

for (SumoNetworkHandler.Edge edge : this.handler.edges.values()) {
incomingEdges.computeIfAbsent(edge.to, (k) -> new ArrayList<>())
incomingEdges.computeIfAbsent(edge.to, k -> new ArrayList<>())
.add(edge);
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public List<String> getHeader() {
"is_secondary_or_higher", "is_primary_or_higher", "is_motorway",
"is_link", "has_merging_link", "is_merging_into",
"num_left", "num_right", "num_straight"
);
);
}

public void print(CSVPrinter out) {
Expand All @@ -165,7 +165,7 @@ public void print(CSVPrinter out, String linkId, SumoNetworkHandler.Edge edge) t
String highwayType = getHighwayType(edge.type);

SumoNetworkHandler.Junction junction = handler.junctions.get(edge.to);
List<SumoNetworkHandler.Connection> connections = handler.connections.computeIfAbsent(edge.id, (k) -> new ArrayList<>());
List<SumoNetworkHandler.Connection> connections = handler.connections.computeIfAbsent(edge.id, k -> new ArrayList<>());

Set<SumoNetworkHandler.Edge> toEdges = connections.stream()
.filter(c -> !c.dir.equals("t"))
Expand Down Expand Up @@ -232,12 +232,12 @@ public void print(CSVPrinter out, String linkId, SumoNetworkHandler.Edge edge) t
mergingHighest = m.get().getKey();
}

boolean geq_secondary = switch (highwayType) {
boolean geqSecondary = switch (highwayType) {
case "secondary", "primary", "trunk", "motorway" -> true;
default -> false;
};

boolean geq_primary = switch (highwayType) {
boolean geqPrimary = switch (highwayType) {
case "primary", "trunk", "motorway" -> true;
default -> false;
};
Expand All @@ -264,8 +264,8 @@ public void print(CSVPrinter out, String linkId, SumoNetworkHandler.Edge edge) t
out.print(bool("higher".equals(prio)));
out.print(bool("equal".equals(prio)));
out.print(bool("lower".equals(prio)));
out.print(bool(geq_secondary));
out.print(bool(geq_primary));
out.print(bool(geqSecondary));
out.print(bool(geqPrimary));
out.print(bool("motorway".equals(highwayType)));
out.print(bool(highwayType.contains("link")));
out.print(bool(merging));
Expand Down

0 comments on commit 033f872

Please sign in to comment.