Skip to content
Snippets Groups Projects
Commit 745b397e authored by markn92's avatar markn92
Browse files

prevent exception

parent 56e13140
No related branches found
No related tags found
No related merge requests found
......@@ -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)))
......@@ -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}
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