From 745b397e300311bc41294806ded2dcf07fdb24b3 Mon Sep 17 00:00:00 2001 From: "niehues.mark@gmail.com" <niehues.mark@gmail.com> Date: Thu, 19 Mar 2020 18:21:49 +0100 Subject: [PATCH] prevent exception --- evrouting/charge/routing.py | 31 ++++++++++++++----------------- evrouting/charge/utils.py | 6 ------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py index 9feaa02..247bb1a 100644 --- a/evrouting/charge/routing.py +++ b/evrouting/charge/routing.py @@ -78,8 +78,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, return f_soc_factory(label_node_min).minimum # Handle charging stations - if node_min in charging_stations and \ - not node_min == label_node_min.last_cs: + if node_min in charging_stations and node_min != label_node_min.last_cs: f_soc: SoCFunction = f_soc_factory(label_node_min) t_charge = f_soc.calc_optimal_t_charge(cf_map[node_min]) @@ -112,29 +111,27 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node, soc_profile_factory(node_min, n) if soc_profile(capacity) != -inf: - l_new = Label( + if cf_map[label_node_min.last_cs].is_dummy \ + and soc_profile.path_cost > label_node_min.soc_last_cs: + # Dummy charging stations cannot increase SoC. + # Therefore paths that consume more energy than the SoC + # when arriving at the (dummy) station are unfeasible. + continue + + label_neighbour: Label = Label( t_trip=label_node_min.t_trip + distance(G, node_min, n), soc_last_cs=label_node_min.soc_last_cs, last_cs=label_node_min.last_cs, soc_profile_cs_v=soc_profile ) - try: - l_uns[n].insert(l_new) - except ValueError: - # Infeasible because last_cs might be an - # dummy charging station. Therefore, the path might - # be infeasible even though one could reach it with a full - # battery, because charging is not possible at dummy - # stations. - # - # That means, the SoC and thereby the range is restricted - # to the SoC at the last cs (soc_last_cs). - continue + l_uns[n].insert(label_neighbour) + # Update queue if entered label is the new minimum label + # of the neighbour. try: - is_new_min_label: bool = l_new == l_uns[n].peak_min() + is_new_min_label: bool = label_neighbour == l_uns[n].peak_min() except KeyError: continue if is_new_min_label: - prio_queue.insert(n, **keys(f_soc_factory(l_new))) + prio_queue.insert(n, **keys(f_soc_factory(label_neighbour))) diff --git a/evrouting/charge/utils.py b/evrouting/charge/utils.py index 39bebcb..19e405d 100644 --- a/evrouting/charge/utils.py +++ b/evrouting/charge/utils.py @@ -41,11 +41,5 @@ class LabelPriorityQueue(PriorityQueue): def keys(f_soc: SoCFunction) -> Dict: t_min: Time = f_soc.minimum - - # Might happen because of dummy charge stations - if t_min == -inf: - raise ValueError('Infeasible label.') - soc_min: SoC = f_soc(t_min) - return {'priority': t_min, 'count': soc_min} -- GitLab