From d29c08a411391df8fd86c7acf0fe4dae38108a38 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Wed, 27 Jul 2022 18:18:44 +0200 Subject: [PATCH] dijkstra: fix invalid stats --- dijsktra.py | 10 +++------- main.py | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dijsktra.py b/dijsktra.py index dd2c010..206d6ad 100644 --- a/dijsktra.py +++ b/dijsktra.py @@ -52,17 +52,13 @@ class Dijkstra(): # start at destination sequence.append(dest) - total_time = 0 - total_co2 = 0 - + # go through all possibilities until we're back at start while start not in sequence: current = self.table[sequence[-1]] # last element of list prev = current["prev"] - total_time += current["distance"][0] - total_co2 += current["distance"][1] sequence.append(prev) sequence.reverse() print(sequence) - print("Total Time:", total_time) - print("Total CO2:", total_co2) + print("Total Time:", self.table[dest]["distance"][0]) + print("Total CO2:", self.table[dest]["distance"][1]) diff --git a/main.py b/main.py index 1e4d5e6..1a2446a 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ def main(): graph: dict = create_graph(dataset) # solve dijkstra = Dijkstra(graph, dataset.connection) - dijkstra.algorithm("time") + dijkstra.algorithm("co2") dijkstra.print_result(dataset.connection)