From 805eeea41f51ab40cc4e47ff7508f725c1f65c7b Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Mon, 30 Mar 2020 18:23:47 +0200
Subject: [PATCH] adding t

---
 evrouting/gasstation/routing.py          | 19 ++++++++++++++++++-
 tests/gasstation/test_transformations.py |  4 ++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py
index db9697b..2dc84ce 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 988c923..a5e0b46 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):
-- 
GitLab