Skip to content
Snippets Groups Projects
Commit 6b964b6b authored by markn92's avatar markn92
Browse files

s insertion

parent d2d333d8
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ from evrouting.graph_tools import (
)
Path = List[Node]
DistFunction = Callable[[nx.Graph, Node, Node], Path]
DistFunction = Callable[[nx.Graph, Node, Node, str], Path]
def dijkstra(G: nx.Graph, u: Any, v: Any, weight: str = 'weight') -> Path:
......@@ -25,12 +25,42 @@ def fold_path(G: nx.Graph, path: Path, weight: str):
def insert_start_node(s: Node,
graph_core: nx.Graph,
graph_contracted: nx.Graph,
gas_stations: Set[Node],
graph_extended: nx.DiGraph,
capacity: SoC,
initial_soc: SoC,
dist: DistFunction = dijkstra
) -> nx.DiGraph:
"""Insert s into extended graph an create states and edges as necessary."""
for v in gas_stations:
shortest_p = dist(graph_core, s, v, weight=CONSUMPTION_KEY)
w = fold_path(graph_core, shortest_p, weight=CONSUMPTION_KEY)
if w > initial_soc:
continue
d = fold_path(graph_core, shortest_p, weight=DISTANCE_KEY)
c_v = charging_cofficient(graph_core, v)
g = initial_soc - w
graph_extended.add_edge((s, initial_soc), (v, g), weight=d)
for u in graph_contracted.neighbors(v):
c_u = charging_cofficient(graph_contracted, u)
w_v_u = consumption(graph_contracted, u, v)
d_v_u = distance(graph_contracted, u, v)
if c_v < c_u:
graph_extended.add_edge(
(v, g),
(u, capacity - w_v_u),
weight=(capacity - g) * c_v + d_v_u
)
elif g < w_v_u:
graph_extended.add_edge(
(v, g),
(u, 0),
weight=(w_v_u - g) * c_v + d_v_u
)
return graph_extended
......
......@@ -270,10 +270,11 @@ class TestIntegration:
)
@pytest.fixture
def inserted_s(self, extended_graph, graph_config):
def inserted_s(self, extended_graph, contracted_graph, graph_config):
return insert_start_node(
s=0,
graph_core=graph_config['G'],
graph_contracted=contracted_graph,
gas_stations=graph_config['charging_stations'],
graph_extended=extended_graph,
capacity=graph_config['capacity'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment