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
371f22a0
Commit
371f22a0
authored
4 years ago
by
David Radu
Browse files
Options
Downloads
Patches
Plain Diff
adding module based jl file
parent
4157c6dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/jl/main_heuristics_module.jl
+162
-0
162 additions, 0 deletions
src/jl/main_heuristics_module.jl
with
162 additions
and
0 deletions
src/jl/main_heuristics_module.jl
0 → 100644
+
162
−
0
View file @
371f22a0
using
PyCall
include
(
"optimisation_models.jl"
)
include
(
"MCP_heuristics.jl"
)
module
Siting_Heuristics
# Simulated Annealing & Local Search algorithm
function
main_MIRSA
(
index_dict
,
deployment_dict
,
D
,
c
,
N
,
I
,
E
,
T_init
,
R
,
run
)
index_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
index_dict
[
k
]))
for
k
in
keys
(
index_dict
)])
deployment_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
deployment_dict
[
k
]))
for
k
in
keys
(
deployment_dict
)])
D
=
convert
.
(
Float64
,
D
)
c
=
convert
(
Float64
,
c
)
N
=
convert
(
Int64
,
N
)
I
=
convert
(
Int64
,
I
)
E
=
convert
(
Int64
,
E
)
T_init
=
convert
(
Float64
,
T_init
)
R
=
convert
(
Int64
,
R
)
run
=
string
(
run
)
W
,
L
=
size
(
D
)
P
=
maximum
(
values
(
index_dict
))
n_partitions
=
[
deployment_dict
[
i
]
for
i
in
1
:
P
]
if
run
==
"SALS"
x_sol
,
LB_sol
,
obj_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
),
Array
{
Float64
,
2
}(
undef
,
R
,
I
)
x_init
=
solve_MILP_partitioning
(
D
,
c
,
n_partitions
,
index_dict
,
"Gurobi"
)
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
],
obj_sol
[
r
,
:
]
=
simulated_annealing_local_search_partition
(
D
,
c
,
n_partitions
,
N
,
I
,
E
,
x_init
,
T_init
,
index_dict
)
end
elseif
run
==
"SALSR"
x_sol
,
LB_sol
,
obj_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
),
Array
{
Float64
,
2
}(
undef
,
R
,
I
)
x_init
=
zeros
(
Float64
,
L
)
ind
=
collect
(
1
:
L
)
x_ind
=
sample
(
ind
,
convert
(
Int64
,
deployment_dict
[
1
]))
x_init
[
x_ind
]
.=
1.
n
=
convert
(
Float64
,
deployment_dict
[
1
])
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
],
obj_sol
[
r
,
:
]
=
simulated_annealing_local_search
(
D
,
c
,
n
,
N
,
I
,
E
,
x_init
,
T_init
)
end
else
println
(
"No such run available."
)
throw
(
ArgumentError
)
end
return
x_sol
,
LB_sol
,
obj_sol
end
# Random Search algorithm
function
main_RAND
(
deployment_dict
,
D
,
c
,
run
)
deployment_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
deployment_dict
[
k
]))
for
k
in
keys
(
deployment_dict
)])
D
=
convert
.
(
Float64
,
D
)
c
=
convert
(
Float64
,
c
)
if
run
==
"RS"
x_sol
,
LB_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
)
n
=
convert
(
Float64
,
deployment_dict
[
1
])
runs
=
convert
(
Int64
,
I
*
E
)
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
]
=
random_search
(
D
,
c
,
n
,
runs
)
end
else
println
(
"No such run available."
)
throw
(
ArgumentError
)
end
return
x_sol
,
LB_sol
end
# Greedy algorithms
function
main_GRED
(
deployment_dict
,
D
,
c
,
run
)
deployment_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
deployment_dict
[
k
]))
for
k
in
keys
(
deployment_dict
)])
D
=
convert
.
(
Float64
,
D
)
c
=
convert
(
Float64
,
c
)
if
run
==
"RGH"
x_sol
,
LB_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
)
n
=
convert
(
Float64
,
deployment_dict
[
1
])
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
]
=
randomised_greedy_heuristic
(
D
,
c
,
n
)
end
elseif
run
==
"CGA"
x_sol
,
LB_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
)
n
=
convert
(
Float64
,
deployment_dict
[
1
])
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
]
=
classic_greedy_algorithm
(
D
,
c
,
n
)
end
elif
run
==
"SGA"
x_sol
,
LB_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
)
n
=
convert
(
Float64
,
deployment_dict
[
1
])
eps
=
convert
(
Float64
,
0.001
)
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
]
=
stochastic_greedy_algorithm
(
D
,
c
,
n
,
eps
)
end
else
println
(
"No such run available."
)
throw
(
ArgumentError
)
end
return
x_sol
,
LB_sol
end
#Local Search algorithm
function
main_LSEA
(
index_dict
,
deployment_dict
,
D
,
c
,
N
,
I
,
E
,
run
)
index_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
index_dict
[
k
]))
for
k
in
keys
(
index_dict
)])
deployment_dict
=
Dict
([(
convert
(
Int64
,
k
),
convert
(
Int64
,
deployment_dict
[
k
]))
for
k
in
keys
(
deployment_dict
)])
D
=
convert
.
(
Float64
,
D
)
c
=
convert
(
Float64
,
c
)
N
=
convert
(
Int64
,
N
)
I
=
convert
(
Int64
,
I
)
E
=
convert
(
Int64
,
E
)
T_init
=
convert
(
Float64
,
T_init
)
R
=
convert
(
Int64
,
R
)
run
=
string
(
run
)
W
,
L
=
size
(
D
)
P
=
maximum
(
values
(
index_dict
))
n_partitions
=
[
deployment_dict
[
i
]
for
i
in
1
:
P
]
if
run
==
"GLS"
x_sol
,
LB_sol
,
obj_sol
=
Array
{
Float64
,
2
}(
undef
,
R
,
L
),
Array
{
Float64
,
1
}(
undef
,
R
),
Array
{
Float64
,
2
}(
undef
,
R
,
I
)
x_init
=
solve_MILP_partitioning
(
D
,
c
,
n_partitions
,
index_dict
,
"Gurobi"
)
for
r
=
1
:
R
println
(
"Run "
,
r
,
"/"
,
R
)
x_sol
[
r
,
:
],
LB_sol
[
r
],
obj_sol
[
r
,
:
]
=
greedy_local_search_partition
(
D
,
c
,
n_partitions
,
N
,
I
,
E
,
x_init
,
index_dict
)
end
else
println
(
"No such run available."
)
throw
(
ArgumentError
)
end
return
x_sol
,
LB_sol
,
obj_sol
end
end
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