diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py index db9697b5f442f10c20b094566f3fbc68fb4bc4ab..2dc84ce58fc0e668f7a30b6bf3db025867894fcd 100644 --- a/evrouting/gasstation/routing.py +++ b/evrouting/gasstation/routing.py @@ -69,9 +69,26 @@ def insert_final_node(t: Node, gas_stations: Set[Node], graph_extended: nx.DiGraph, capacity: SoC, - initial_soc: SoC, + final_soc: SoC, dist: DistFunction = dijkstra ) -> nx.DiGraph: + for u in gas_stations: + shortest_p = dist(graph_core, t, u, weight=CONSUMPTION_KEY) + w = fold_path(graph_core, shortest_p, weight=CONSUMPTION_KEY) + if w + final_soc > capacity: + continue + + d_u_t = fold_path(graph_core, shortest_p, weight=DISTANCE_KEY) + c_u = charging_cofficient(graph_core, u) + for g in [g for n, g in graph_extended.nodes if n == u]: + if g > w + final_soc: + continue + graph_extended.add_edge( + (u, g), + (t, final_soc), + weight=(w + final_soc - g) * c_u + d_u_t + ) + return graph_extended diff --git a/tests/gasstation/test_transformations.py b/tests/gasstation/test_transformations.py index 988c923d242418ddb59e82e2829aea7db0daee86..a5e0b46d9c5848edc984602f853c7f0af0ea2aca 100644 --- a/tests/gasstation/test_transformations.py +++ b/tests/gasstation/test_transformations.py @@ -282,14 +282,14 @@ class TestIntegration: ) @pytest.fixture - def inserted_t(self, inserted_s, graph_config): + def inserted_t(self, inserted_s, contracted_graph, graph_config): return insert_final_node( t=3, graph_core=graph_config['G'], gas_stations=graph_config['charging_stations'], graph_extended=inserted_s, capacity=graph_config['capacity'], - initial_soc=4 + final_soc=0 ) def test_contracted_graph(self, contracted_graph):