Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OptiOrch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Zizhe Wang
OptiOrch
Commits
11532b1a
Commit
11532b1a
authored
11 months ago
by
Zizhe Wang
Browse files
Options
Downloads
Patches
Plain Diff
style minor improvements
parent
4ea9e608
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
src/config.py
+9
-11
9 additions, 11 deletions
src/config.py
src/optimize_main.py
+11
-8
11 additions, 8 deletions
src/optimize_main.py
with
20 additions
and
19 deletions
src/config.py
+
9
−
11
View file @
11532b1a
...
@@ -18,9 +18,9 @@ MODEL_FILE = f"{MODEL_NAME}.mo"
...
@@ -18,9 +18,9 @@ MODEL_FILE = f"{MODEL_NAME}.mo"
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
MODEL_FILE
)
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
MODEL_FILE
)
SIMULATION_STOP_TIME
=
3000
# in seconds
SIMULATION_STOP_TIME
=
3000
# in seconds
# Parameters
and result variables
# Parameters
to be varied and objectives to be optimized
PARAMETERS
=
[
"
Q_max
"
,
"
T_set
"
]
PARAMETERS
=
[
"
Q_max
"
,
"
T_set
"
]
RESULT
S
=
[
"
energy
"
,
"
comfort
"
]
OBJECTIVE
S
=
[
"
energy
"
,
"
comfort
"
]
MAXIMIZE
=
[
"
comfort
"
]
# List of objectives to maximize
MAXIMIZE
=
[
"
comfort
"
]
# List of objectives to maximize
# Parameter range
# Parameter range
...
@@ -32,6 +32,13 @@ PARAM_BOUNDS = {
...
@@ -32,6 +32,13 @@ PARAM_BOUNDS = {
# Results precision
# Results precision
PRECISION
=
2
# decimal places
PRECISION
=
2
# decimal places
# Optimization settings
OPTIMIZATION_CONFIG
=
{
"
ALGORITHM_NAME
"
:
'
NSGA2
'
,
# Algorithm selection
"
POP_SIZE
"
:
100
,
# Population size for algorithm
"
N_GEN
"
:
50
# Number of generations
}
# Plot configurations
# Plot configurations
PLOT_CONFIG
=
{
PLOT_CONFIG
=
{
"
PLOT_X
"
:
"
Energy Consumption
"
,
"
PLOT_X
"
:
"
Energy Consumption
"
,
...
@@ -39,15 +46,6 @@ PLOT_CONFIG = {
...
@@ -39,15 +46,6 @@ PLOT_CONFIG = {
"
PLOT_TITLE
"
:
"
Pareto Front of Energy Consumption vs Comfort
"
"
PLOT_TITLE
"
:
"
Pareto Front of Energy Consumption vs Comfort
"
}
}
# Algorithm selection
# Options: 'pymoo.NSGA2', 'pymoo.NSGA3', 'pymoo.CMAES', 'scipy.de', 'scipy.minimize'
OPTIMIZATION_LIBRARY
=
'
pymoo
'
ALGORITHM_NAME
=
'
NSGA2
'
# Optimization settings
POP_SIZE
=
50
# Population size for NSGA2
N_GEN
=
100
# Number of generations
# Parallel processing
# Parallel processing
N_JOBS
=
-
1
# Options: '-1', '1', 'n', 'None'
N_JOBS
=
-
1
# Options: '-1', '1', 'n', 'None'
# ====================================================================
# ====================================================================
...
...
This diff is collapsed.
Click to expand it.
src/optimize_main.py
+
11
−
8
View file @
11532b1a
...
@@ -14,21 +14,21 @@ from pymoo.core.problem import Problem
...
@@ -14,21 +14,21 @@ from pymoo.core.problem import Problem
from
pymoo.optimize
import
minimize
from
pymoo.optimize
import
minimize
from
optimization_libraries
import
initialize_algorithm
from
optimization_libraries
import
initialize_algorithm
from
parallel_computing
import
optimization_function
,
cleanup_temp_dirs
from
parallel_computing
import
optimization_function
,
cleanup_temp_dirs
from
config
import
(
PARAMETERS
,
RESULTS
,
PARAM_BOUNDS
,
PRECISION
,
PLOT_CONFIG
,
from
config
import
(
PARAMETERS
,
OBJECTIVES
,
MAXIMIZE
,
PARAM_BOUNDS
,
PRECISION
,
PLOT_CONFIG
,
OPTIMIZATION_
LIBRARY
,
ALGORITHM_NAME
,
POP_SIZE
,
N_GEN
,
N_JOBS
,
MAXIMIZE
)
# Import all configuration variables
OPTIMIZATION_
CONFIG
,
N_JOBS
)
# Import all configuration variables
class
OptimizationProblem
(
Problem
):
class
OptimizationProblem
(
Problem
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
param_names
=
list
(
PARAM_BOUNDS
.
keys
())
self
.
param_names
=
list
(
PARAM_BOUNDS
.
keys
())
self
.
result_names
=
RESULT
S
self
.
objective_names
=
OBJECTIVE
S
self
.
maximize_indices
=
[
self
.
result
_names
.
index
(
res
)
for
res
in
MAXIMIZE
]
self
.
maximize_indices
=
[
self
.
objective
_names
.
index
(
res
)
for
res
in
MAXIMIZE
]
n_var
=
len
(
self
.
param_names
)
n_var
=
len
(
self
.
param_names
)
xl
=
np
.
array
([
PARAM_BOUNDS
[
param
][
0
]
for
param
in
self
.
param_names
])
xl
=
np
.
array
([
PARAM_BOUNDS
[
param
][
0
]
for
param
in
self
.
param_names
])
xu
=
np
.
array
([
PARAM_BOUNDS
[
param
][
1
]
for
param
in
self
.
param_names
])
xu
=
np
.
array
([
PARAM_BOUNDS
[
param
][
1
]
for
param
in
self
.
param_names
])
print
(
f
"
Number of variables:
{
n_var
}
"
)
print
(
f
"
Number of variables:
{
n_var
}
"
)
print
(
f
"
Lower bounds:
{
xl
}
"
)
print
(
f
"
Lower bounds:
{
xl
}
"
)
print
(
f
"
Upper bounds:
{
xu
}
"
)
print
(
f
"
Upper bounds:
{
xu
}
"
)
super
().
__init__
(
n_var
=
n_var
,
n_obj
=
len
(
RESULT
S
),
n_constr
=
0
,
xl
=
xl
,
xu
=
xu
)
super
().
__init__
(
n_var
=
n_var
,
n_obj
=
len
(
OBJECTIVE
S
),
n_constr
=
0
,
xl
=
xl
,
xu
=
xu
)
def
_evaluate
(
self
,
X
,
out
,
*
args
,
**
kwargs
):
def
_evaluate
(
self
,
X
,
out
,
*
args
,
**
kwargs
):
param_values_list
=
[
dict
(
zip
(
self
.
param_names
,
x
))
for
x
in
X
]
param_values_list
=
[
dict
(
zip
(
self
.
param_names
,
x
))
for
x
in
X
]
...
@@ -43,14 +43,17 @@ class OptimizationProblem(Problem):
...
@@ -43,14 +43,17 @@ class OptimizationProblem(Problem):
out
[
"
F
"
]
=
np
.
array
(
results
)
# Ensure results are a 2D array
out
[
"
F
"
]
=
np
.
array
(
results
)
# Ensure results are a 2D array
# Initialize the optimization algorithm
# Initialize the optimization algorithm
algorithm
=
initialize_algorithm
(
OPTIMIZATION_LIBRARY
,
ALGORITHM_NAME
,
POP_SIZE
)
algorithm
=
initialize_algorithm
(
OPTIMIZATION_CONFIG
[
'
ALGORITHM_NAME
'
],
OPTIMIZATION_CONFIG
.
get
(
'
POP_SIZE
'
)
)
# Define the optimization problem
# Define the optimization problem
problem
=
OptimizationProblem
()
problem
=
OptimizationProblem
()
try
:
try
:
# Run the optimization
# Run the optimization
res
=
minimize
(
problem
,
algorithm
,
(
"
n_gen
"
,
N_GEN
),
verbose
=
True
)
res
=
minimize
(
problem
,
algorithm
,
(
"
n_gen
"
,
OPTIMIZATION_CONFIG
[
'
N_GEN
'
]
),
verbose
=
True
)
finally
:
finally
:
# Cleanup temporary directories
# Cleanup temporary directories
cleanup_temp_dirs
()
cleanup_temp_dirs
()
...
@@ -65,7 +68,7 @@ for i, result in enumerate(res.F):
...
@@ -65,7 +68,7 @@ for i, result in enumerate(res.F):
result
=
tuple
(
result
)
result
=
tuple
(
result
)
print
(
f
"
Solution
{
i
}
:
"
,
end
=
""
)
print
(
f
"
Solution
{
i
}
:
"
,
end
=
""
)
for
name
,
value
in
zip
(
RESULT
S
,
result
):
for
name
,
value
in
zip
(
OBJECTIVE
S
,
result
):
print
(
f
"
{
name
.
capitalize
()
}
=
{
value
:
.
{
PRECISION
}
f
}
"
,
end
=
"
,
"
)
print
(
f
"
{
name
.
capitalize
()
}
=
{
value
:
.
{
PRECISION
}
f
}
"
,
end
=
"
,
"
)
print
()
print
()
...
...
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