Skip to content
Snippets Groups Projects
Commit 9392932e authored by markn92's avatar markn92
Browse files

add key to label datastructure

parent 3c7f74c7
No related branches found
No related tags found
No related merge requests found
...@@ -103,7 +103,7 @@ class ChargingFunction: ...@@ -103,7 +103,7 @@ class ChargingFunction:
if self.initial_soc is None: if self.initial_soc is None:
raise ValueError( raise ValueError(
'Charging coefficient is 0 but no initial SoC given.' 'Charging coefficient is 0 but no initial SoC given.'
) )
soc = self.initial_soc soc = self.initial_soc
else: else:
soc = initial_soc + self.c * t soc = initial_soc + self.c * t
...@@ -160,6 +160,11 @@ class Label(NamedTuple): ...@@ -160,6 +160,11 @@ class Label(NamedTuple):
last_cs: Node last_cs: Node
soc_profile_cs_v: SoCProfile soc_profile_cs_v: SoCProfile
@property
def key(self):
"""Key for sorting."""
return self.t_trip
class SoCFunction: class SoCFunction:
""" """
...@@ -206,7 +211,7 @@ class SoCFunction: ...@@ -206,7 +211,7 @@ class SoCFunction:
return self.soc_profile_cs_v( return self.soc_profile_cs_v(
self.cf_cs(t - self.t_trip, self.soc_last_cs) self.cf_cs(t - self.t_trip, self.soc_last_cs)
) )
@property @property
def minimum(self) -> Time: def minimum(self) -> Time:
......
...@@ -116,7 +116,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, ...@@ -116,7 +116,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
# l_uns[v] empty # l_uns[v] empty
q.delete_min() q.delete_min()
else: else:
q.insert(minimum_node, key(label_minimum_node)) q.insert(minimum_node, label_minimum_node.key)
# scan outgoing arcs # scan outgoing arcs
for n in G.neighbors(minimum_node): for n in G.neighbors(minimum_node):
...@@ -145,8 +145,4 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, ...@@ -145,8 +145,4 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
pass pass
else: else:
if l_new == l_uns[n].peak_min(): if l_new == l_uns[n].peak_min():
q.insert(n, key(l_new)) q.insert(n, l_new.key)
def key(l: Label) -> Time:
return l.t_trip
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment