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
eb7f67b3
Commit
eb7f67b3
authored
5 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
add map for charging functions
parent
e35c8ca6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
evrouting/charge/routing.py
+8
-26
8 additions, 26 deletions
evrouting/charge/routing.py
evrouting/charge/utils.py
+32
-1
32 additions, 1 deletion
evrouting/charge/utils.py
with
40 additions
and
27 deletions
evrouting/charge/routing.py
+
8
−
26
View file @
eb7f67b3
...
@@ -8,7 +8,7 @@ from evrouting.charge import factories as factories
...
@@ -8,7 +8,7 @@ from evrouting.charge import factories as factories
from
..graph_tools
import
distance
from
..graph_tools
import
distance
from
.T
import
SoCFunction
,
Label
from
.T
import
SoCFunction
,
Label
from
.utils
import
LabelPriorityQueue
from
.utils
import
LabelPriorityQueue
,
ChargingFunctionMap
def
shortest_path
(
G
:
nx
.
Graph
,
charging_stations
:
set
,
s
:
Node
,
t
:
Node
,
def
shortest_path
(
G
:
nx
.
Graph
,
charging_stations
:
set
,
s
:
Node
,
t
:
Node
,
...
@@ -24,6 +24,8 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
...
@@ -24,6 +24,8 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
:param U: Capacity
:param U: Capacity
:return:
:return:
"""
"""
cf
=
ChargingFunctionMap
(
G
=
G
,
capacity
=
capacity
,
initial_soc
=
initial_soc
)
q
=
PriorityQueue
()
q
=
PriorityQueue
()
l_set
:
Dict
[
int
,
set
]
=
{
v
:
set
()
for
v
in
G
}
l_set
:
Dict
[
int
,
set
]
=
{
v
:
set
()
for
v
in
G
}
l_uns
:
Dict
[
int
,
LabelPriorityQueue
]
=
{
l_uns
:
Dict
[
int
,
LabelPriorityQueue
]
=
{
...
@@ -45,7 +47,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
...
@@ -45,7 +47,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
l_uns
[
s
].
insert
(
l_uns
[
s
].
insert
(
l
,
l
,
factories
.
charging_function
(
G
,
l
.
last_cs
,
capacity
,
initial_soc
)
cf
[
l
.
last_cs
]
)
)
q
.
insert
(
s
,
0
)
q
.
insert
(
s
,
0
)
...
@@ -64,28 +66,13 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
...
@@ -64,28 +66,13 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
if
minimum_node
==
t
:
if
minimum_node
==
t
:
return
SoCFunction
(
return
SoCFunction
(
label_minimum_node
,
label_minimum_node
,
factories
.
charging_function
(
cf
[
label_minimum_node
.
last_cs
]
G
,
label_minimum_node
.
last_cs
,
capacity
,
initial_soc
)
).
minimum
).
minimum
# handle charging stations
# handle charging stations
if
minimum_node
in
charging_stations
and
not
minimum_node
==
label_minimum_node
.
last_cs
:
if
minimum_node
in
charging_stations
and
not
minimum_node
==
label_minimum_node
.
last_cs
:
cf_last_cs
=
factories
.
charging_function
(
cf_last_cs
=
cf
[
label_minimum_node
.
last_cs
]
G
,
cf_minimum_node
=
cf
[
minimum_node
]
label_minimum_node
.
last_cs
,
capacity
,
initial_soc
# Use here in case cs is a dummy station
)
cf_minimum_node
=
factories
.
charging_function
(
G
,
minimum_node
,
capacity
,
initial_soc
# Use here in case cs is a dummy station
)
if
cf_minimum_node
.
c
>
cf_last_cs
.
c
:
if
cf_minimum_node
.
c
>
cf_last_cs
.
c
:
# Only charge the minimum at the last charge station
# Only charge the minimum at the last charge station
...
@@ -134,12 +121,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
...
@@ -134,12 +121,7 @@ def shortest_path(G: nx.Graph, charging_stations: set, s: Node, t: Node,
try
:
try
:
l_uns
[
n
].
insert
(
l_uns
[
n
].
insert
(
l_new
,
l_new
,
factories
.
charging_function
(
cf
[
l_new
.
last_cs
]
G
,
l_new
.
last_cs
,
capacity
,
initial_soc
)
)
)
except
ValueError
:
except
ValueError
:
# Infeasible because last_cs might be an
# Infeasible because last_cs might be an
...
...
This diff is collapsed.
Click to expand it.
evrouting/charge/utils.py
+
32
−
1
View file @
eb7f67b3
from
typing
import
Dict
from
math
import
inf
from
math
import
inf
import
networkx
as
nx
from
evrouting.utils
import
PriorityQueue
from
evrouting.utils
import
PriorityQueue
from
evrouting.T
import
SoC
,
Time
from
evrouting.T
import
SoC
,
Time
,
Node
from
.factories
import
charging_function
from
.T
import
Label
,
SoCFunction
,
ChargingFunction
from
.T
import
Label
,
SoCFunction
,
ChargingFunction
...
@@ -27,3 +30,31 @@ class LabelPriorityQueue(PriorityQueue):
...
@@ -27,3 +30,31 @@ class LabelPriorityQueue(PriorityQueue):
priority
=
t_min
,
priority
=
t_min
,
count
=
soc_min
count
=
soc_min
)
)
class
ChargingFunctionMap
:
"""
Maps Nodes to their charging functions.
"""
def
__init__
(
self
,
G
:
nx
.
Graph
,
capacity
:
SoC
,
initial_soc
:
SoC
=
None
):
self
.
map
:
Dict
[
Node
,
ChargingFunction
]
=
{}
self
.
G
:
nx
.
Graph
=
G
self
.
capacity
:
SoC
=
capacity
self
.
initial_soc
:
SoC
=
initial_soc
def
__getitem__
(
self
,
node
:
Node
)
->
ChargingFunction
:
"""
Try to get charging function from cache,
else create function and add to cache.
"""
try
:
cf
=
self
.
map
[
node
]
except
KeyError
:
cf
=
charging_function
(
G
=
self
.
G
,
n
=
node
,
capacity
=
self
.
capacity
,
initial_soc
=
self
.
initial_soc
)
self
.
map
[
node
]
=
cf
return
cf
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