diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py index 98253c81efdf15ce09ad9c3c229e12ede1be1a28..9feaa025d56f6d3239e095bf93f667350204db9d 100644 --- a/evrouting/charge/routing.py +++ b/evrouting/charge/routing.py @@ -1,8 +1,8 @@ -from typing import Dict, Union, Set +from typing import Dict, List from math import inf import networkx as nx -from evrouting.T import Node, SoC, Time +from evrouting.T import Node, SoC from evrouting.utils import PriorityQueue from evrouting.charge.factories import ( ChargingFunctionMap, @@ -11,11 +11,9 @@ from evrouting.charge.factories import ( ) from ..graph_tools import distance -from .T import ChargingFunction, SoCFunction, Label +from .T import SoCFunction, Label from .utils import LabelPriorityQueue, keys -__all__ = ['shortest_path'] - def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, initial_soc: SoC, final_soc: SoC, capacity: SoC): @@ -45,7 +43,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, soc_profile_factory = SoCProfileFactory(G, capacity) # Init maps to manage labels - l_set: Dict[int, Set[Label]] = {v: set() for v in G} + l_set: Dict[int, List[Label]] = {v: [] for v in G} l_uns: Dict[int, LabelPriorityQueue] = { v: LabelPriorityQueue(f_soc_factory, l_set[v]) for v in G } @@ -74,7 +72,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, node_min: Node = prio_queue.peak_min() label_node_min: Label = l_uns[node_min].delete_min() - l_set[node_min].add(label_node_min) + l_set[node_min].append(label_node_min) if node_min == t: return f_soc_factory(label_node_min).minimum diff --git a/evrouting/charge/utils.py b/evrouting/charge/utils.py index 6a58d695028829fcc3d6753c1f9588aa91142608..39bebcb41b66735b6ac8ba697df9af3921f49890 100644 --- a/evrouting/charge/utils.py +++ b/evrouting/charge/utils.py @@ -1,4 +1,4 @@ -from typing import Set, Any, Dict +from typing import Any, Dict, List from math import inf from evrouting.utils import PriorityQueue @@ -9,10 +9,10 @@ from .factories import SoCFunctionFactory class LabelPriorityQueue(PriorityQueue): - def __init__(self, f_soc: SoCFunctionFactory, l_set: Set[Label]): + def __init__(self, f_soc: SoCFunctionFactory, l_set: List[Label]): super().__init__() self.f_soc_factory: SoCFunctionFactory = f_soc - self.l_set: Set[Label] = l_set + self.l_set: List[Label] = l_set def insert(self, label: Label): """Breaking ties with lowest soc at t_min.""" @@ -34,10 +34,9 @@ class LabelPriorityQueue(PriorityQueue): soc = self.f_soc_factory(label) - for other_label in self.l_set: - if self.f_soc_factory(other_label) > soc: - self.remove_item(label) - return + # Remove item if it gets dominanted by any label in l_set + if any(self.f_soc_factory(label) > soc for label in self.l_set): + self.remove_item(label) def keys(f_soc: SoCFunction) -> Dict: