diff --git a/evrouting/charge/T.py b/evrouting/charge/T.py index 079bcfc4395003393a598f10dd14da0366d29e7d..292e6b3d8e43511bed7925812598e5c74718b5df 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 8935107a6b52cda9992c7d46a84e8adfd2f6fc98..033b37e412ad647486b0ab902b262b7e62aa8f55 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)