From 0f9eb57071a264ad705cfb1301b5616d15907447 Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Mon, 27 Apr 2020 17:15:12 +0200
Subject: [PATCH] ugly fix tests

---
 evrouting/gasstation/routing.py          | 11 +++++------
 tests/gasstation/test_transformations.py | 12 ++++++++----
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py
index a898669..214d3b2 100644
--- a/evrouting/gasstation/routing.py
+++ b/evrouting/gasstation/routing.py
@@ -88,13 +88,12 @@ def insert_final_node(t: Node,
 
 
 def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
-                   dist: DistFunction = dijkstra) -> nx.Graph:
+                   c=1) -> nx.Graph:
     """
     :param G: Original graph
     :param charging_stations: Charging stations
     :param capacity: Maximum battery capacity
-    :param dist: Minimum distance function, necessary if G is not a fully
-        connected Graph to calculate consumptions between charging stations.
+    :param c: Linear coefficient to calc consumption from (Time) distance
     :returns: Graph only consisting of Charging Stations whose neighbours must
         be within the capacity U. If so, their edge has consumption and
         distance of the minimum path.
@@ -110,14 +109,14 @@ def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
         H.add_node(cs, **G.nodes[cs])
         # Iterate unvisited charging stations
         for n_cs in all_cs[i + 1:]:
-            min_path: List[Node] = dist(G, cs, n_cs)
-            w_cs_n: SoC = fold_path(G, min_path, weight=CONSUMPTION_KEY)
+            t_min = nx.algorithms.shortest_path_length(G, cs, n_cs, weight=DISTANCE_KEY)
+            w_cs_n: SoC = c * t_min
             if w_cs_n <= capacity:
                 H.add_edge(
                     cs, n_cs,
                     **{
                         CONSUMPTION_KEY: w_cs_n,
-                        DISTANCE_KEY: fold_path(G, min_path, weight=DISTANCE_KEY)
+                        DISTANCE_KEY: t_min
                     }
                 )
     H.add_node(all_cs[-1], **G.nodes[all_cs[-1]])
diff --git a/tests/gasstation/test_transformations.py b/tests/gasstation/test_transformations.py
index e6c5c9f..51a7858 100644
--- a/tests/gasstation/test_transformations.py
+++ b/tests/gasstation/test_transformations.py
@@ -51,12 +51,14 @@ class TestContraction:
     @pytest.mark.parametrize('u,v,weight,value', [
         ('s', 'a', CONSUMPTION_KEY, 1),
         ('s', 'a', DISTANCE_KEY, 1),
-        ('s', 'f', '', None),  # Not exist
+        ('s', 'f', CONSUMPTION_KEY, 1),  # Not exist
+        ('s', 'f', DISTANCE_KEY, 1),  # Not exist
         ('s', 'b', '', None),  # Not exist
         ('s', 'd', '', None),  # Not exist
         ('s', 'c', CONSUMPTION_KEY, 2),
         ('s', 'c', DISTANCE_KEY, 2),
-        ('s', 'e', '', None)
+        ('s', 'e', CONSUMPTION_KEY, 2),
+        ('s', 'e', DISTANCE_KEY, 2)
     ])
     def test_contraction_edges(self, u, v, weight, value):
         """
@@ -69,7 +71,8 @@ class TestContraction:
         """
         conf: dict = init_config(gasstation)
         H: nx.Graph = contract_graph(conf['G'],
-                                     conf['charging_stations'], conf['capacity'])
+                                     conf['charging_stations'],
+                                     conf['capacity'], c=1)
 
         label_map = self.label_map(H)
         try:
@@ -255,7 +258,8 @@ class Integration:
         return contract_graph(
             G=graph_config['G'],
             charging_stations=graph_config['charging_stations'],
-            capacity=graph_config['capacity']
+            capacity=graph_config['capacity'],
+            c=.5
         )
 
     @pytest.fixture
-- 
GitLab