From 9392932efb2ea0e35c93a6dd096473ca5908020d Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Wed, 18 Mar 2020 12:18:29 +0100
Subject: [PATCH] add key to label datastructure

---
 evrouting/charge/T.py       | 9 +++++++--
 evrouting/charge/routing.py | 8 ++------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/evrouting/charge/T.py b/evrouting/charge/T.py
index 079bcfc..292e6b3 100644
--- a/evrouting/charge/T.py
+++ b/evrouting/charge/T.py
@@ -103,7 +103,7 @@ class ChargingFunction:
             if self.initial_soc is None:
                 raise ValueError(
                     'Charging coefficient is 0 but no initial SoC given.'
-                    )
+                )
             soc = self.initial_soc
         else:
             soc = initial_soc + self.c * t
@@ -160,6 +160,11 @@ class Label(NamedTuple):
     last_cs: Node
     soc_profile_cs_v: SoCProfile
 
+    @property
+    def key(self):
+        """Key for sorting."""
+        return self.t_trip
+
 
 class SoCFunction:
     """
@@ -206,7 +211,7 @@ class SoCFunction:
 
         return self.soc_profile_cs_v(
             self.cf_cs(t - self.t_trip, self.soc_last_cs)
-            )
+        )
 
     @property
     def minimum(self) -> Time:
diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py
index 8935107..033b37e 100644
--- a/evrouting/charge/routing.py
+++ b/evrouting/charge/routing.py
@@ -116,7 +116,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
             # l_uns[v] empty
             q.delete_min()
         else:
-            q.insert(minimum_node, key(label_minimum_node))
+            q.insert(minimum_node, label_minimum_node.key)
 
         # scan outgoing arcs
         for n in G.neighbors(minimum_node):
@@ -145,8 +145,4 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
                     pass
                 else:
                     if l_new == l_uns[n].peak_min():
-                        q.insert(n, key(l_new))
-
-
-def key(l: Label) -> Time:
-    return l.t_trip
+                        q.insert(n, l_new.key)
-- 
GitLab