Skip to content
Snippets Groups Projects
Commit 0f9eb570 authored by markn92's avatar markn92
Browse files

ugly fix tests

parent 5fb5d134
No related branches found
No related tags found
No related merge requests found
......@@ -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]])
......
......@@ -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
......
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