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
869270ea
Commit
869270ea
authored
4 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
test
parent
1c096115
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/charge/routing.py
+5
-2
5 additions, 2 deletions
evrouting/charge/routing.py
evrouting/osm/imports.py
+1
-1
1 addition, 1 deletion
evrouting/osm/imports.py
tests/osm/test_osm_charge.py
+48
-2
48 additions, 2 deletions
tests/osm/test_osm_charge.py
with
54 additions
and
5 deletions
evrouting/charge/routing.py
+
5
−
2
View file @
869270ea
...
@@ -13,7 +13,7 @@ from math import inf
...
@@ -13,7 +13,7 @@ from math import inf
import
networkx
as
nx
import
networkx
as
nx
from
evrouting.T
import
Node
,
SoC
,
Time
,
Result
,
EmptyResult
,
ConsumptionFunction
from
evrouting.T
import
Node
,
SoC
,
Time
,
Result
,
EmptyResult
,
ConsumptionFunction
from
evrouting.utils
import
PriorityQueue
from
evrouting.utils
import
PriorityQueue
from
evrouting.graph_tools
import
distance
,
consumption
from
evrouting.graph_tools
import
distance
,
consumption
,
DISTANCE_KEY
,
CONSUMPTION_KEY
from
evrouting.charge.T
import
SoCFunction
,
Label
from
evrouting.charge.T
import
SoCFunction
,
Label
from
evrouting.charge.utils
import
LabelPriorityQueue
from
evrouting.charge.utils
import
LabelPriorityQueue
from
evrouting.charge.factories
import
(
from
evrouting.charge.factories
import
(
...
@@ -161,7 +161,10 @@ def _setup(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
...
@@ -161,7 +161,10 @@ def _setup(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
# left at t (final_soc). The node becomes the new final node.
# left at t (final_soc). The node becomes the new final node.
dummy_final_node
:
Node
=
len
(
G
)
dummy_final_node
:
Node
=
len
(
G
)
G
.
add_node
(
dummy_final_node
)
G
.
add_node
(
dummy_final_node
)
G
.
add_edge
(
t
,
dummy_final_node
,
weight
=
0
,
c
=
final_soc
)
G
.
add_edge
(
t
,
dummy_final_node
,
**
{
DISTANCE_KEY
:
0
,
CONSUMPTION_KEY
:
final_soc
})
t
=
dummy_final_node
t
=
dummy_final_node
# Init factories
# Init factories
...
...
This diff is collapsed.
Click to expand it.
evrouting/osm/imports.py
+
1
−
1
View file @
869270ea
...
@@ -72,7 +72,7 @@ class OSMGraph(nx.DiGraph):
...
@@ -72,7 +72,7 @@ class OSMGraph(nx.DiGraph):
lat
=
s
[
'
lat
'
]
lat
=
s
[
'
lat
'
]
n
=
self
.
find_nearest
((
lat
,
lon
),
distance_limit
=
500
)
n
=
self
.
find_nearest
((
lat
,
lon
),
distance_limit
=
500
)
if
n
is
not
None
:
if
n
is
not
None
:
self
.
nodes
[
n
][
CHARGING_COEFFICIENT_KEY
]
=
s
[
'
power
'
]
self
.
nodes
[
n
][
CHARGING_COEFFICIENT_KEY
]
=
s
[
'
power
'
]
/
3.6
# in Wh/s
S
.
add
(
n
)
S
.
add
(
n
)
self
.
charging_stations
=
S
self
.
charging_stations
=
S
...
...
This diff is collapsed.
Click to expand it.
tests/osm/test_osm_charge.py
+
48
−
2
View file @
869270ea
...
@@ -8,7 +8,7 @@ from evrouting.T import Result
...
@@ -8,7 +8,7 @@ from evrouting.T import Result
from
evrouting.osm.imports
import
read_osm
,
OSMGraph
,
HAVERSINE_KEY
from
evrouting.osm.imports
import
read_osm
,
OSMGraph
,
HAVERSINE_KEY
from
evrouting.osm.profiles
import
car
from
evrouting.osm.profiles
import
car
from
evrouting.osm.routing
import
shortest_path
from
evrouting.osm.routing
import
shortest_path
from
evrouting.graph_tools
import
CHARGING_COEFFICIENT_KEY
,
DISTANCE_KEY
from
evrouting.graph_tools
import
CHARGING_COEFFICIENT_KEY
,
DISTANCE_KEY
,
CONSUMPTION_KEY
@pytest.fixture
@pytest.fixture
...
@@ -99,6 +99,7 @@ def test_shortest_route_dimensions(map_graph):
...
@@ -99,6 +99,7 @@ def test_shortest_route_dimensions(map_graph):
def
test_charge_shortest_route_dimensions
(
map_graph
):
def
test_charge_shortest_route_dimensions
(
map_graph
):
"""
Full tank is enough to get there. Must be equal to shortest path.
"""
s
=
(
51.75041438844966
,
6.9332313537597665
)
s
=
(
51.75041438844966
,
6.9332313537597665
)
t
=
(
51.75657783347559
,
7.000350952148438
)
t
=
(
51.75657783347559
,
7.000350952148438
)
_s
=
map_graph
.
find_nearest
(
s
)
_s
=
map_graph
.
find_nearest
(
s
)
...
@@ -109,7 +110,10 @@ def test_charge_shortest_route_dimensions(map_graph):
...
@@ -109,7 +110,10 @@ def test_charge_shortest_route_dimensions(map_graph):
def
c
(
G
,
u
,
v
):
def
c
(
G
,
u
,
v
):
"""
Returns consumption in Wh from u to v.
"""
"""
Returns consumption in Wh from u to v.
"""
return
G
[
u
][
v
][
HAVERSINE_KEY
]
*
consumption
*
1000
try
:
return
G
[
u
][
v
][
HAVERSINE_KEY
]
*
consumption
except
KeyError
:
return
G
[
u
][
v
][
CONSUMPTION_KEY
]
result
=
charge
.
routing
.
shortest_path
(
result
=
charge
.
routing
.
shortest_path
(
G
=
map_graph
,
G
=
map_graph
,
...
@@ -122,4 +126,46 @@ def test_charge_shortest_route_dimensions(map_graph):
...
@@ -122,4 +126,46 @@ def test_charge_shortest_route_dimensions(map_graph):
c
=
c
c
=
c
)
)
path
=
shortest_path
(
map_graph
,
_s
,
_t
,
car
)
assert
type
(
result
)
is
Result
assert
[
n
for
n
,
t
in
result
.
charge_path
]
==
path
def
test_charge_shortest_route_stop
(
map_graph
):
"""
Full tank is enough to get there. Must be equal to shortest path.
"""
s
=
(
51.75041438844966
,
6.9332313537597665
)
t
=
(
51.75657783347559
,
7.000350952148438
)
_s
=
map_graph
.
find_nearest
(
s
)
_t
=
map_graph
.
find_nearest
(
t
)
consumption
=
1
# kWh/km
cost_path
=
6
*
consumption
*
1000
# distance * consumption in Wh
def
c
(
G
,
u
,
v
):
"""
Returns consumption in Wh from u to v.
"""
try
:
return
G
[
u
][
v
][
HAVERSINE_KEY
]
*
consumption
except
KeyError
:
return
G
[
u
][
v
][
CONSUMPTION_KEY
]
result
=
charge
.
routing
.
shortest_path
(
G
=
map_graph
,
charging_stations
=
map_graph
.
charging_stations
,
s
=
_s
,
t
=
_t
,
initial_soc
=
2000
,
# > cost_path
final_soc
=
0
,
capacity
=
10000
,
c
=
c
)
assert
type
(
result
)
is
Result
assert
type
(
result
)
is
Result
charge_at
=
[
t
for
n
,
t
in
result
.
charge_path
if
t
>
0
]
# charge once
assert
len
(
charge_at
)
==
1
# Charge about 10 min
assert
charge_at
[
0
]
<
600
assert
charge_at
[
0
]
>
500
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