Skip to content
Snippets Groups Projects
Commit 56e13140 authored by markn92's avatar markn92
Browse files

wip

parent f67a350b
No related branches found
No related tags found
No related merge requests found
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
......
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:
......
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