Skip to content
Snippets Groups Projects
Commit 7f491b61 authored by markn92's avatar markn92
Browse files

using a star for paths in gasstation

parent 5c8852ec
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ def insert_start_node(s: Node,
v: Node
for v in gas_stations:
try:
shortest_p: List[Node] = nx.shortest_path(graph_core, s, v, weight=DISTANCE_KEY)
shortest_p: List[Node] = f.shortest_path(graph_core, s, v)
except nx.NetworkXNoPath:
continue
......@@ -70,7 +70,7 @@ def insert_final_node(t: Node,
u: Node
for u in gas_stations:
try:
shortest_p: List[Node] = nx.shortest_path(graph_core, t, u, weight=DISTANCE_KEY)
shortest_p: List[Node] = f.shortest_path(graph_core, t, u)
except nx.NetworkXNoPath:
continue
......@@ -115,7 +115,7 @@ def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
# Iterate unvisited charging stations
for n_cs in all_cs[i + 1:]:
try:
path = nx.algorithms.shortest_path(G, cs, n_cs, weight=DISTANCE_KEY)
path = f.shortest_path(G, cs, n_cs)
except nx.NetworkXNoPath:
continue
w_cs_n: SoC = f.path_consumption(G, path)
......@@ -183,11 +183,10 @@ def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph,
v, g_v = path[i + 1]
t: Time = extended_graph.edges[(u, g_u), (v, g_v)]['weight']
trip_time += t
path_in_between = nx.shortest_path(
path_in_between = f.shortest_path(
graph_core,
u,
v,
weight=DISTANCE_KEY
v
)
charge_time_u: Time = t - f.path_distance(graph_core, path_in_between)
charge_path.append((u, charge_time_u))
......@@ -223,7 +222,7 @@ def shortest_path(G: nx.Graph,
"""
# Check if t is reachable from s
try:
_path = nx.shortest_path(G, s, t, weight=DISTANCE_KEY)
_path = f.shortest_path(G, s, t)
except nx.NetworkXNoPath:
return EmptyResult()
......
......@@ -116,3 +116,21 @@ class AccessFunctions:
def path_consumption(self, G, path):
""":returns: consumption of given path."""
return sum_weights(G, path, weight=CONSUMPTION_KEY)
def shortest_path(self, G, u, v):
return nx.algorithms.shortest_path(G, u, v, weight=DISTANCE_KEY)
class GasstationAccessFunctions(AccessFunctions):
def __init__(self, consumption_coefficient):
super().__init__()
self.c = consumption_coefficient
def consumption(self, G, u, v):
return self.c * self._distance(G, u, v)
def charging_coefficient(self, G, v):
return 1 / self._charging_coefficient(G, v)
def path_consumption(self, G, path):
return self.c * self.path_distance(G, path)
......@@ -174,7 +174,7 @@ class Way(object):
def slice_array(waypoints, node_pass_count):
slices = []
start_last_slice = 0
for i, w in range(1, len(waypoints) - 1):
for i in range(1, len(waypoints) - 1):
if node_pass_count[waypoints[i]] > 1:
slices.append(waypoints[start_last_slice: i + 1])
start_last_slice = i
......
......@@ -8,6 +8,7 @@ from evrouting.graph_tools import (
DISTANCE_KEY, sum_weights, AccessFunctions
)
from evrouting.osm.const import ms_to_kmh
from evrouting.osm.profiles import car
lat = float
lon = float
......@@ -96,3 +97,6 @@ class GasstationAccessFunctions(AccessFunctions):
def path_consumption(self, G, path):
return self.c * self.path_distance(G, path)
def shortest_path(self, G, u, v):
return nx.astar_path(G, u, v, heuristic=a_start_heuristic(G, profile=car))
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