Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
markn92
ba
Commits
0f9eb570
Commit
0f9eb570
authored
4 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
ugly fix tests
parent
5fb5d134
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
evrouting/gasstation/routing.py
+5
-6
5 additions, 6 deletions
evrouting/gasstation/routing.py
tests/gasstation/test_transformations.py
+8
-4
8 additions, 4 deletions
tests/gasstation/test_transformations.py
with
13 additions
and
10 deletions
evrouting/gasstation/routing.py
+
5
−
6
View file @
0f9eb570
...
...
@@ -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
]])
...
...
This diff is collapsed.
Click to expand it.
tests/gasstation/test_transformations.py
+
8
−
4
View file @
0f9eb570
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment