From 56e131408afe97eac97b24b0a6ccd59ef1e1fc9d Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Thu, 19 Mar 2020 18:08:17 +0100
Subject: [PATCH]  wip

---
 evrouting/charge/routing.py | 12 +++++-------
 evrouting/charge/utils.py   | 13 ++++++-------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py
index 98253c8..9feaa02 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 6a58d69..39bebcb 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:
-- 
GitLab