Skip to content
Snippets Groups Projects
Commit 3475815f authored by markn92's avatar markn92
Browse files

refactor

parent 5c664e34
No related branches found
No related tags found
1 merge request!2Dev
......@@ -29,6 +29,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
cf = ChargingFunctionMap(G=G, capacity=capacity, initial_soc=initial_soc)
label_factory = LabelsFactory(G, capacity, cf, initial_soc)
# Init maps to manage labels
l_set: Dict[int, set] = {v: set() for v in G}
l_uns: Dict[int, LabelPriorityQueue] = {v: LabelPriorityQueue() for v in G}
......@@ -36,12 +37,14 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
entry_label = _create_entry_label(G, charging_stations, s, initial_soc, capacity)
l_uns[s].insert(entry_label, cf[entry_label.last_cs])
q = PriorityQueue()
q.insert(s, 0)
# A priority queue defines which node to visit next.
# The key is the trip time.
prio_queue = PriorityQueue()
prio_queue.insert(s, 0)
while True:
try:
minimum_node: Node = q.peak_min()
minimum_node: Node = prio_queue.peak_min()
except KeyError:
# empty queue
break
......@@ -62,7 +65,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
# Update priority queue. This node might have gotten a new
# minimum label spawned is th previous step.
_update_priority_queue(q, l_uns, minimum_node)
_update_priority_queue(prio_queue, l_uns, minimum_node)
# scan outgoing arcs
for n in G.neighbors(minimum_node):
......@@ -91,7 +94,7 @@ 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, l_new.key)
prio_queue.insert(n, l_new.key)
def _create_entry_label(
......@@ -133,7 +136,7 @@ def _is_feasible_path(soc_profile: SoCProfile, capacity: SoC) -> bool:
def _update_priority_queue(
q: PriorityQueue,
prio_queue: PriorityQueue,
l_uns: Dict[int, LabelPriorityQueue],
node: Node):
"""
......@@ -144,6 +147,6 @@ def _update_priority_queue(
minimum_label = l_uns[node].peak_min()
except KeyError:
# l_uns[v] empty
q.delete_min()
prio_queue.delete_min()
else:
q.insert(node, minimum_label.key)
prio_queue.insert(node, minimum_label.key)
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