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
07c8fc3c
Commit
07c8fc3c
authored
5 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
test
parent
22a1894f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
evrouting/gasstation/routing.py
+37
-0
37 additions, 0 deletions
evrouting/gasstation/routing.py
tests/config.py
+6
-5
6 additions, 5 deletions
tests/config.py
tests/gasstation/test_transformations.py
+17
-1
17 additions, 1 deletion
tests/gasstation/test_transformations.py
with
60 additions
and
6 deletions
evrouting/gasstation/routing.py
+
37
−
0
View file @
07c8fc3c
...
@@ -166,10 +166,47 @@ def state_graph(G: nx.Graph, capacity: SoC) -> nx.DiGraph:
...
@@ -166,10 +166,47 @@ def state_graph(G: nx.Graph, capacity: SoC) -> nx.DiGraph:
return
H
return
H
<<<<<<<
refs
/
remotes
/
origin
/
dev
def
compose_result
(
graph_core
:
nx
.
Graph
,
extended_graph
:
nx
.
DiGraph
,
path
:
List
[
Tuple
[
Node
,
Node
]],
def
compose_result
(
graph_core
:
nx
.
Graph
,
extended_graph
:
nx
.
DiGraph
,
path
:
List
[
Tuple
[
Node
,
Node
]],
dist
=
dijkstra
)
->
Result
:
dist
=
dijkstra
)
->
Result
:
trip_time
=
sum
([
extended_graph
.
edges
[
u
,
v
][
'
weight
'
]
for
u
,
v
in
zip
(
path
[:
-
1
],
path
[
1
:])])
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
=
[]
charge_path
=
[]
for
i
in
range
(
len
(
path
)
-
1
):
for
i
in
range
(
len
(
path
)
-
1
):
u
,
g_u
=
path
[
i
]
u
,
g_u
=
path
[
i
]
...
...
This diff is collapsed.
Click to expand it.
tests/config.py
+
6
−
5
View file @
07c8fc3c
...
@@ -11,7 +11,8 @@ config_list = [
...
@@ -11,7 +11,8 @@ config_list = [
'
edge_case
'
,
'
edge_case
'
,
'
edge_case_start_node_no_cs
'
,
'
edge_case_start_node_no_cs
'
,
'
edge_case_a_slow
'
,
'
edge_case_a_slow
'
,
'
gasstation
'
'
gasstation
'
,
'
gasstation_complete
'
]
]
edge_case
=
{
edge_case
=
{
...
@@ -100,10 +101,10 @@ gasstation_complete = {
...
@@ -100,10 +101,10 @@ gasstation_complete = {
'
s
'
:
0
,
'
s
'
:
0
,
'
t
'
:
3
,
'
t
'
:
3
,
'
nodes
'
:
[
'
nodes
'
:
[
TemplateNode
(),
TemplateNode
(
'
0
'
),
TemplateNode
(
charging_coeff
=
1
),
TemplateNode
(
'
1
'
,
charging_coeff
=
1
),
TemplateNode
(
charging_coeff
=
2
),
TemplateNode
(
'
2
'
,
charging_coeff
=
2
),
TemplateNode
(),
TemplateNode
(
'
3
'
),
],
],
'
edges
'
:
[
'
edges
'
:
[
TemplateEdge
(
0
,
1
,
distance
=
6
,
consumption
=
3
),
TemplateEdge
(
0
,
1
,
distance
=
6
,
consumption
=
3
),
...
...
This diff is collapsed.
Click to expand it.
tests/gasstation/test_transformations.py
+
17
−
1
View file @
07c8fc3c
...
@@ -9,7 +9,8 @@ from evrouting.gasstation.routing import (
...
@@ -9,7 +9,8 @@ from evrouting.gasstation.routing import (
state_graph
,
state_graph
,
insert_final_node
,
insert_final_node
,
insert_start_node
,
insert_start_node
,
compose_result
compose_result
,
init
)
)
from
evrouting.graph_tools
import
(
from
evrouting.graph_tools
import
(
label
,
label
,
...
@@ -289,6 +290,21 @@ class Integration:
...
@@ -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
):
class
TestIntegration
(
Integration
):
def
test_contracted_graph
(
self
,
contracted_graph
):
def
test_contracted_graph
(
self
,
contracted_graph
):
...
...
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