dijkstra: add statistics for time and co2
This commit is contained in:
17
graph.py
17
graph.py
@@ -50,7 +50,6 @@ def calc_time(
|
||||
if distance <= 25:
|
||||
return distance / TransportMethod.OEPNV.value.speed
|
||||
else:
|
||||
# NOTE: should we subtract here?
|
||||
return (distance / TransportMethod.ICE.value.speed)
|
||||
case TransportKind.FLYING:
|
||||
assert(flights != None)
|
||||
@@ -100,10 +99,15 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
print(f"Added new INDIVIDUAL connection from {start} to {dest}")
|
||||
|
||||
# Train
|
||||
if locations[start].type == LocationType.HALTESTELLE:
|
||||
is_haltestelle = locations[start].type == LocationType.HALTESTELLE
|
||||
is_same_continent = locations[start].is_same_continent(locations[dest])
|
||||
# trains only drive from haltestelle and same continent
|
||||
if is_haltestelle and is_same_continent:
|
||||
dest_type = locations[dest].type
|
||||
# there are only trains between haltestellen or airports
|
||||
if dest_type == LocationType.HALTESTELLE or dest_type == LocationType.FLUGHAFEN:
|
||||
is_dest_haltestelle = dest_type == LocationType.HALTESTELLE
|
||||
is_dest_flughafen = dest_type == LocationType.FLUGHAFEN
|
||||
if is_dest_haltestelle or is_dest_flughafen:
|
||||
dist = distance + distance * TransportKind.TRAIN.value
|
||||
time = calc_time(dist, TransportKind.TRAIN)
|
||||
co2 = calc_co2(dist, TransportKind.TRAIN)
|
||||
@@ -121,10 +125,11 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
start = flight
|
||||
dest = flights[flight]["to"]
|
||||
distance = locations[start].distance(locations[dest])
|
||||
time = calc_time(distance * TransportKind.FLYING.value, TransportKind.FLYING, flights, start)
|
||||
co2 = calc_co2(distance * TransportKind.FLYING.value, TransportKind.FLYING)
|
||||
dist = distance + distance * TransportKind.FLYING.value
|
||||
time = calc_time(dist, TransportKind.FLYING, flights, start)
|
||||
co2 = calc_co2(dist, TransportKind.FLYING)
|
||||
new_connection: dict = {dest:
|
||||
{"kind": TransportKind.TRAIN,
|
||||
{"kind": TransportKind.FLYING,
|
||||
"co2": co2,
|
||||
"time": time}}
|
||||
graph[start].append(new_connection)
|
||||
|
||||
Reference in New Issue
Block a user