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
b6f40a18
Commit
b6f40a18
authored
5 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
adding soc function map and fixing teste
parent
3d9be99b
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Dev
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
evrouting/charge/factories.py
+10
-0
10 additions, 0 deletions
evrouting/charge/factories.py
evrouting/charge/routing.py
+20
-20
20 additions, 20 deletions
evrouting/charge/routing.py
tests/charge/test_utils.py
+6
-4
6 additions, 4 deletions
tests/charge/test_utils.py
with
36 additions
and
24 deletions
evrouting/charge/factories.py
+
10
−
0
View file @
b6f40a18
...
...
@@ -59,6 +59,16 @@ class ChargingFunctionMap:
return
cf
class
SoCFunctionMap
:
"""
Maps Nodes to their charging functions.
"""
def
__init__
(
self
,
cf
:
ChargingFunctionMap
):
self
.
cf
:
ChargingFunctionMap
=
cf
def
__getitem__
(
self
,
label
:
Label
)
->
SoCFunction
:
return
SoCFunction
(
label
,
self
.
cf
[
label
.
last_cs
])
class
LabelsFactory
:
def
__init__
(
self
,
...
...
This diff is collapsed.
Click to expand it.
evrouting/charge/routing.py
+
20
−
20
View file @
b6f40a18
...
...
@@ -5,11 +5,14 @@ import networkx as nx
from
evrouting.T
import
Node
,
SoC
from
evrouting.utils
import
PriorityQueue
from
evrouting.charge.factories
import
(
LabelsFactory
,
ChargingFunctionMap
,
soc_profile_factory
LabelsFactory
,
ChargingFunctionMap
,
SoCFunctionMap
,
soc_profile_factory
)
from
..graph_tools
import
distance
from
.T
import
SoCFunction
,
SoCProfile
,
Label
from
.T
import
SoCProfile
,
Label
from
.utils
import
LabelPriorityQueue
__all__
=
[
'
shortest_path
'
]
...
...
@@ -20,17 +23,19 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
"""
Calculates shortest path using the CHarge algorithm.
:param G: Input Graph
:param s: Start Node identifier
:param t: End Node identifier
:param beta_s: Start SoC
:param beta_t: End SoC
:param U: Capacity
:param G:
:param charging_stations:
:param s:
:param t:
:param initial_soc:
:param final_soc:
:param capacity:
:return:
"""
t
=
_apply_final_constraints
(
G
,
t
,
final_soc
)
cf
=
ChargingFunctionMap
(
G
=
G
,
capacity
=
capacity
,
initial_soc
=
initial_soc
)
f_soc
=
SoCFunctionMap
(
cf
)
label_factory
=
LabelsFactory
(
G
,
capacity
,
cf
,
initial_soc
)
# Init maps to manage labels
...
...
@@ -58,9 +63,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
l_set
[
minimum_node
].
add
(
label_minimum_node
)
if
minimum_node
==
t
:
return
SoCFunction
(
label_minimum_node
,
cf
[
label_minimum_node
.
last_cs
]
).
minimum
return
f_soc
[
label_minimum_node
].
minimum
# handle charging stations
if
minimum_node
in
charging_stations
and
\
...
...
@@ -72,7 +75,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
# Update priority queue. This node might have gotten a new
# minimum label spawned is th previous step.
_update_priority_queue
(
c
f
,
prio_queue
,
l_uns
,
minimum_node
)
_update_priority_queue
(
f
_soc
,
prio_queue
,
l_uns
,
minimum_node
)
# scan outgoing arcs
for
n
in
G
.
neighbors
(
minimum_node
):
...
...
@@ -101,15 +104,12 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
pass
else
:
if
l_new
==
l_uns
[
n
].
peak_min
():
key
,
count
=
_key
(
l_new
,
cf
[
l_new
.
last_cs
]
)
key
,
count
=
_key
(
l_new
,
f_soc
)
prio_queue
.
insert
(
n
,
priority
=
key
,
count
=
count
)
def
_key
(
label
,
cf
):
soc_function
=
SoCFunction
(
label
,
cf
)
def
_key
(
label
,
f_soc
):
soc_function
=
f_soc
[
label
]
t_min
=
soc_function
.
minimum
soc_min
=
soc_function
(
t_min
)
...
...
@@ -156,7 +156,7 @@ def _is_feasible_path(soc_profile: SoCProfile, capacity: SoC) -> bool:
def
_update_priority_queue
(
cf
:
Charging
FunctionMap
,
f_soc
:
SoC
FunctionMap
,
prio_queue
:
PriorityQueue
,
l_uns
:
Dict
[
int
,
LabelPriorityQueue
],
node
:
Node
):
...
...
@@ -170,7 +170,7 @@ def _update_priority_queue(
# l_uns[v] empty
prio_queue
.
delete_min
()
else
:
key
,
count
=
_key
(
minimum_label
,
cf
[
minimum_label
.
last_cs
]
)
key
,
count
=
_key
(
minimum_label
,
f_soc
)
prio_queue
.
insert
(
node
,
priority
=
key
,
count
=
count
)
...
...
This diff is collapsed.
Click to expand it.
tests/charge/test_utils.py
+
6
−
4
View file @
b6f40a18
...
...
@@ -6,8 +6,9 @@ from evrouting.charge.T import Label
@pytest.fixture
def
q
(
label
,
ch_function
):
_
,
_
,
cf
=
ch_function
q
=
LabelPriorityQueue
()
q
.
insert
(
label
,
cf
)
dummy_cf
=
{
label
.
last_cs
:
cf
}
q
=
LabelPriorityQueue
(
dummy_cf
)
q
.
insert
(
label
)
# create min
label
=
Label
(
...
...
@@ -17,7 +18,8 @@ def q(label, ch_function):
last_cs
=
1
)
q
.
insert
(
label
,
cf
)
dummy_cf
[
label
.
last_cs
]
=
cf
q
.
insert
(
label
)
yield
q
del
q
...
...
@@ -39,4 +41,4 @@ class TestProrityQueue:
_
,
_
,
cf
=
ch_function
label
=
q
.
peak_min
()
q
.
remove_item
(
label
)
q
.
insert
(
label
,
cf
)
q
.
insert
(
label
)
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