Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
resite_ip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
smart_grids
public
resite_ip
Commits
68b641a3
Commit
68b641a3
authored
4 years ago
by
David Radu
Browse files
Options
Downloads
Patches
Plain Diff
Updated set-ups Pan
parent
e2b8bd48
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config_model.yml
+7
-7
7 additions, 7 deletions
config_model.yml
src/jl/main_heuristics.jl
+1
-1
1 addition, 1 deletion
src/jl/main_heuristics.jl
src/jl/optimisation_models.jl
+2
-2
2 additions, 2 deletions
src/jl/optimisation_models.jl
src/main.py
+58
-44
58 additions, 44 deletions
src/main.py
with
68 additions
and
54 deletions
config_model.yml
+
7
−
7
View file @
68b641a3
...
...
@@ -25,7 +25,7 @@ legacy_layer: False
distance_layer
:
False
# Start time and end time of the analysis.
time_slice
:
[
'
2009-01-01T00:00'
,
'
2018-
3
1-31T23:00'
]
time_slice
:
[
'
2009-01-01T00:00'
,
'
2018-1
2
-31T23:00'
]
# List of regions to be considered in the optimization.
#regions: ['DE', 'FR', 'ES', 'UK', 'IT', 'SE', 'PL', 'NL', 'PT', 'AT', 'EL', 'IE', 'DK', 'FI',
# 'RO', 'BE', 'BG', 'LT', 'CZ', 'EE', 'LV', 'HR', 'NO']
...
...
@@ -51,22 +51,22 @@ name_prefix: 'off_'
# Solution method: BB or HEU or RAND.
solution_method
:
BB
:
set
:
Tru
e
set
:
Fals
e
c
:
8
solver
:
'
gurobi'
mipgap
:
0.02
timelimit
:
1800
threads
:
0
HEU
:
set
:
Fals
e
c
:
[
8
,
1
2
,
24
]
set
:
Tru
e
c
:
[
1
,
1
06
,
212
,
318
,
424
,
530
]
neighborhood
:
1
no_iterations
:
15
0
no_iterations
:
20
0
no_epochs
:
500
initial_temp
:
200.
no_runs
:
5
no_runs
:
100
algorithm
:
'
SALS'
#'GLS'
which_sol
:
'
max
'
#'rand'
which_sol
:
'
rand
'
#'rand'
seed
:
1
RAND
:
set
:
False
...
...
This diff is collapsed.
Click to expand it.
src/jl/main_heuristics.jl
+
1
−
1
View file @
68b641a3
...
...
@@ -41,6 +41,6 @@ function main_call(index_dict, deployment_dict, D, c, N, I, E, T_init, R, run)
throw
(
ArgumentError
)
end
return
x_sol
,
LB_sol
return
x_sol
,
LB_sol
,
obj_sol
end
This diff is collapsed.
Click to expand it.
src/jl/optimisation_models.jl
+
2
−
2
View file @
68b641a3
...
...
@@ -7,7 +7,7 @@ function solve_MILP(D::Array{Float64, 2}, c::Float64, n::Float64, solver::String
L
=
size
(
D
)[
2
]
if
solver
==
"Gurobi"
MILP_model
=
Model
(
optimizer_with_attributes
(
Gurobi
.
Optimizer
,
"TimeLimit"
=>
18
00.
,
"MIPGap"
=>
0.05
))
MILP_model
=
Model
(
optimizer_with_attributes
(
Gurobi
.
Optimizer
,
"TimeLimit"
=>
72
00.
,
"MIPGap"
=>
0.05
))
else
println
(
"Please use Cbc or Gurobi"
)
throw
(
ArgumentError
)
...
...
@@ -50,7 +50,7 @@ function solve_MILP_partitioning(D::Array{Float64, 2}, c::Float64, n::Array{Int6
# Selects solver
if
solver
==
"Gurobi"
MILP_model
=
Model
(
optimizer_with_attributes
(
Gurobi
.
Optimizer
,
"TimeLimit"
=>
18
00.
,
"MIPGap"
=>
0.01
))
MILP_model
=
Model
(
optimizer_with_attributes
(
Gurobi
.
Optimizer
,
"TimeLimit"
=>
72
00.
,
"MIPGap"
=>
0.01
))
else
println
(
"Please use Cbc or Gurobi"
)
throw
(
ArgumentError
)
...
...
This diff is collapsed.
Click to expand it.
src/main.py
+
58
−
44
View file @
68b641a3
...
...
@@ -5,7 +5,7 @@ from random import sample
from
pyomo.opt
import
SolverFactory
from
numpy
import
zeros
,
argmax
import
argparse
import
time
from
src.helpers
import
read_inputs
,
init_folder
,
custom_log
,
remove_garbage
,
generate_jl_output
from
src.models
import
preprocess_input_data
,
build_model
...
...
@@ -15,8 +15,8 @@ def parse_args():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Command line arguments.
'
)
parser
.
add_argument
(
'
-c
'
,
'
--global_thresh
'
,
type
=
floa
t
,
help
=
'
Global threshold
'
)
parser
.
add_argument
(
'
-tl
'
,
'
--time_limit
'
,
type
=
floa
t
,
help
=
'
Solver time limit
'
)
parser
.
add_argument
(
'
-c
'
,
'
--global_thresh
'
,
type
=
in
t
,
help
=
'
Global threshold
'
)
parser
.
add_argument
(
'
-tl
'
,
'
--time_limit
'
,
type
=
in
t
,
help
=
'
Solver time limit
'
)
parser
.
add_argument
(
'
-th
'
,
'
--threads
'
,
type
=
int
,
help
=
'
Number of threads
'
)
parsed_args
=
vars
(
parser
.
parse_args
())
...
...
@@ -33,8 +33,8 @@ if parameters['solution_method']['BB']['set']:
args
=
parse_args
()
parameters
[
'
solution_method
'
][
'
BB
'
][
'
timelimit
'
]
=
args
[
'
time_limit
'
]
parameters
[
'
solution_method
'
][
'
BB
'
][
'
threads
'
]
=
args
[
'
thread
'
]
parameters
[
'
solution_method
'
][
'
BB
'
][
'
c
'
]
=
args
[
'
thre
ad
'
]
parameters
[
'
solution_method
'
][
'
BB
'
][
'
threads
'
]
=
args
[
'
thread
s
'
]
parameters
[
'
solution_method
'
][
'
BB
'
][
'
c
'
]
=
args
[
'
global_
thre
sh
'
]
custom_log
(
'
BB chosen to solve the IP.
'
)
...
...
@@ -60,7 +60,7 @@ if parameters['solution_method']['BB']['set']:
instance
,
indices
=
build_model
(
parameters
,
input_dict
,
output_folder
,
write_lp
=
False
)
custom_log
(
'
Sending model to solver.
'
)
results
=
opt
.
solve
(
instance
,
tee
=
Tru
e
,
keepfiles
=
False
,
report_timing
=
False
,
results
=
opt
.
solve
(
instance
,
tee
=
Fals
e
,
keepfiles
=
False
,
report_timing
=
False
,
logfile
=
join
(
output_folder
,
'
solver_log.log
'
))
objective
=
instance
.
objective
()
...
...
@@ -152,44 +152,58 @@ elif parameters['solution_method']['HEU']['set']:
for
c
in
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
c
'
]:
print
(
'
Running heuristic for c value of
'
,
c
)
jl_selected
,
jl_objective
=
fn
(
jl_dict
[
'
index_dict
'
],
jl_dict
[
'
deployment_dict
'
],
jl_dict
[
'
criticality_matrix
'
],
c
,
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
neighborhood
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_iterations
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_epochs
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
initial_temp
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_runs
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
algorithm
'
])
if
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
which_sol
'
]
==
'
max
'
:
jl_objective_seed
=
max
(
jl_objective
)
jl_selected_seed
=
jl_selected
[
argmax
(
jl_objective
),
:]
output_folder
=
init_folder
(
parameters
,
input_dict
,
suffix
=
'
_c
'
+
str
(
c
))
with
open
(
join
(
output_folder
,
'
config_model.yaml
'
),
'
w
'
)
as
outfile
:
yaml
.
dump
(
parameters
,
outfile
,
default_flow_style
=
False
,
sort_keys
=
False
)
jl_locations
=
retrieve_location_dict_jl
(
jl_selected_seed
,
parameters
,
input_dict
,
indices
)
retrieve_site_data
(
parameters
,
input_dict
,
output_folder
,
jl_locations
,
jl_objective_seed
)
else
:
#'rand'
seed
=
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
seed
'
]
for
i
in
range
(
jl_selected
.
shape
[
0
]):
output_folder
=
init_folder
(
parameters
,
input_dict
,
suffix
=
'
_c
'
+
str
(
c
)
+
'
_seed
'
+
str
(
seed
))
seed
+=
1
with
open
(
join
(
output_folder
,
'
config_model.yaml
'
),
'
w
'
)
as
outfile
:
yaml
.
dump
(
parameters
,
outfile
,
default_flow_style
=
False
,
sort_keys
=
False
)
jl_selected_seed
=
jl_selected
[
i
,
:]
jl_objective_seed
=
jl_objective
[
i
]
jl_locations
=
retrieve_location_dict_jl
(
jl_selected_seed
,
parameters
,
input_dict
,
indices
)
retrieve_site_data
(
c
,
parameters
,
input_dict
,
output_folder
,
jl_locations
,
jl_objective_seed
)
start
=
time
.
time
()
jl_selected
,
jl_objective
,
jl_traj
=
fn
(
jl_dict
[
'
index_dict
'
],
jl_dict
[
'
deployment_dict
'
],
jl_dict
[
'
criticality_matrix
'
],
c
,
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
neighborhood
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_iterations
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_epochs
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
initial_temp
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_runs
'
],
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
algorithm
'
])
end
=
time
.
time
()
noruns
=
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
no_runs
'
]
dt
=
(
end
-
start
)
/
noruns
print
(
f
'
Average time per run:
{
dt
}
'
)
output_folder
=
init_folder
(
parameters
,
input_dict
,
suffix
=
'
_c
'
+
str
(
c
)
+
'
_MIRSA
'
)
with
open
(
join
(
output_folder
,
'
config_model.yaml
'
),
'
w
'
)
as
outfile
:
yaml
.
dump
(
parameters
,
outfile
,
default_flow_style
=
False
,
sort_keys
=
False
)
pickle
.
dump
(
jl_selected
,
open
(
join
(
output_folder
,
'
solution_matrix.p
'
),
'
wb
'
),
protocol
=
4
)
pickle
.
dump
(
jl_objective
,
open
(
join
(
output_folder
,
'
objective_vector.p
'
),
'
wb
'
),
protocol
=
4
)
pickle
.
dump
(
jl_traj
,
open
(
join
(
output_folder
,
'
trajectory_matrix.p
'
),
'
wb
'
),
protocol
=
4
)
if
c
==
parameters
[
'
solution_method
'
][
'
HEU
'
][
'
c
'
][
0
]:
pickle
.
dump
(
input_dict
[
'
criticality_data
'
],
open
(
join
(
output_folder
,
'
criticality_matrix.p
'
),
'
wb
'
),
protocol
=
4
)
#if parameters['solution_method']['HEU']['which_sol'] == 'max':
# jl_objective_seed = max(jl_objective)
# jl_selected_seed = jl_selected[argmax(jl_objective), :]
# output_folder = init_folder(parameters, input_dict, suffix='_c' + str(c))
# with open(join(output_folder, 'config_model.yaml'), 'w') as outfile:
# yaml.dump(parameters, outfile, default_flow_style=False, sort_keys=False)
# jl_locations = retrieve_location_dict_jl(jl_selected_seed, parameters, input_dict, indices)
# retrieve_site_data(parameters, input_dict, output_folder, jl_locations, jl_objective_seed)
#else: #'rand'
# seed = parameters['solution_method']['HEU']['seed']
# for i in range(jl_selected.shape[0]):
# output_folder = init_folder(parameters, input_dict, suffix='_c' + str(c) + '_seed' + str(seed) + '_MIRSA')
# seed += 1
# with open(join(output_folder, 'config_model.yaml'), 'w') as outfile:
# yaml.dump(parameters, outfile, default_flow_style=False, sort_keys=False)
# jl_selected_seed = jl_selected[i, :]
# jl_objective_seed = jl_objective[i]
# jl_locations = retrieve_location_dict_jl(jl_selected_seed, parameters, input_dict, indices)
# retrieve_site_data(c, parameters, input_dict, output_folder, jl_locations, jl_objective_seed)
else
:
raise
ValueError
(
'
This solution method is not available. Retry.
'
)
...
...
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