Skip to content
Snippets Groups Projects
Commit 07c8fc3c authored by markn92's avatar markn92
Browse files

test

parent 22a1894f
Branches
No related tags found
No related merge requests found
......@@ -166,10 +166,47 @@ def state_graph(G: nx.Graph, capacity: SoC) -> nx.DiGraph:
return H
<<<<<<< refs/remotes/origin/dev
def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph, path: List[Tuple[Node, Node]],
dist=dijkstra) -> Result:
trip_time = sum([extended_graph.edges[u, v]['weight'] for u, v in zip(path[:-1], path[1:])])
=======
def init(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
dist: DistFunction = dijkstra) -> nx.Graph:
H: nx.DiGraph = nx.DiGraph()
for v in charging_stations:
c_v = charging_cofficient(G, v)
H.add_node((v, 0))
# Iterate unvisited charging stations
for u in charging_stations:
if u == v:
continue
min_path: List[Node] = dist(G, v, u)
w: SoC = fold_path(G, min_path, weight=CONSUMPTION_KEY)
if w <= capacity: # neighbour
g = capacity - w
c_u = charging_cofficient(G, u)
if c_u < c_v: # c_u cheaper
H.add_node((v, g))
if c_v <= c_u and g < w: # c_v at least as cheap as c_u
weight = (w - g) * c_u + distance(G, u, v)
H.add_edge((u, g), (v, 0), weight=weight)
elif c_v > c_u: # c_u cheaper
weight = (capacity - g) * c_u + distance(G, u, v)
H.add_edge((u, g), (v, capacity - w), weight=weight)
return H
def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph,
path: List[State], dist=dijkstra) -> Result:
trip_time: Time = 0
>>>>>>> local
charge_path = []
for i in range(len(path) - 1):
u, g_u = path[i]
......
......@@ -11,7 +11,8 @@ config_list = [
'edge_case',
'edge_case_start_node_no_cs',
'edge_case_a_slow',
'gasstation'
'gasstation',
'gasstation_complete'
]
edge_case = {
......@@ -100,10 +101,10 @@ gasstation_complete = {
's': 0,
't': 3,
'nodes': [
TemplateNode(),
TemplateNode(charging_coeff=1),
TemplateNode(charging_coeff=2),
TemplateNode(),
TemplateNode('0'),
TemplateNode('1', charging_coeff=1),
TemplateNode('2', charging_coeff=2),
TemplateNode('3'),
],
'edges': [
TemplateEdge(0, 1, distance=6, consumption=3),
......
......@@ -9,7 +9,8 @@ from evrouting.gasstation.routing import (
state_graph,
insert_final_node,
insert_start_node,
compose_result
compose_result,
init
)
from evrouting.graph_tools import (
label,
......@@ -289,6 +290,21 @@ class Integration:
)
class TestInit(Integration):
def test_init(self, extended_graph, graph_config):
h = init(
graph_config['G'],
charging_stations=graph_config['charging_stations'],
capacity=graph_config['capacity']
)
assert len(extended_graph.nodes) == len(h.nodes)
assert set(extended_graph.nodes) == set(h.nodes)
assert len(extended_graph.edges) == len(h.edges)
assert set(extended_graph.edges) == set(h.edges)
class TestIntegration(Integration):
def test_contracted_graph(self, contracted_graph):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment