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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zizhe Wang
OptiOrch
Commits
fe0bc53c
Commit
fe0bc53c
authored
May 28, 2024
by
Zizhe Wang
Browse files
Options
Downloads
Patches
Plain Diff
feat add configuration of result precision and plot config
parent
e301bc3d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.py
+15
-7
15 additions, 7 deletions
src/config.py
src/optimize_main.py
+7
-6
7 additions, 6 deletions
src/optimize_main.py
src/parallel_computing.py
+5
-5
5 additions, 5 deletions
src/parallel_computing.py
with
27 additions
and
18 deletions
src/config.py
+
15
−
7
View file @
fe0bc53c
...
...
@@ -13,23 +13,31 @@
import
os
# Basic settings
SIMULATION_STOP_TIME
=
2000
# in seconds
MODEL_NAME
=
"
SimpleHeatingSystem
"
MODEL_FILE
=
f
"
{
MODEL_NAME
}
.mo
"
current_directory
=
os
.
getcwd
()
model_path
=
os
.
path
.
join
(
current_directory
,
MODEL_FILE
)
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
MODEL_FILE
)
SIMULATION_STOP_TIME
=
2000
# in seconds
# Parameters and result variables
PARAMETERS
=
[
"
Q_max
"
,
"
T_set
"
]
RESULTS
=
[
"
energy
"
,
"
cost
"
,
"
comfort
"
]
RESULTS
=
[
"
energy
"
,
"
comfort
"
]
# Parameter
bounds
# Parameter
range
PARAM_BOUNDS
=
{
"
Q_max
"
:
(
1000
,
5000
),
"
T_set
"
:
(
280
,
310
),
}
# Results precision
PRECISION
=
2
# decimal places
# Plot configurations
PLOT_CONFIG
=
{
"
PLOT_X
"
:
"
Energy Consumption
"
,
"
PLOT_Y
"
:
"
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
'
...
...
This diff is collapsed.
Click to expand it.
src/optimize_main.py
+
7
−
6
View file @
fe0bc53c
...
...
@@ -14,7 +14,8 @@ from pymoo.core.problem import Problem
from
pymoo.optimize
import
minimize
from
optimization_libraries
import
initialize_algorithm
from
parallel_computing
import
optimization_function
,
cleanup_temp_dirs
from
config
import
PARAMETERS
,
RESULTS
,
PARAM_BOUNDS
,
POP_SIZE
,
N_GEN
,
N_JOBS
,
OPTIMIZATION_LIBRARY
,
ALGORITHM_NAME
from
config
import
(
PARAMETERS
,
RESULTS
,
PARAM_BOUNDS
,
PRECISION
,
PLOT_CONFIG
,
OPTIMIZATION_LIBRARY
,
ALGORITHM_NAME
,
POP_SIZE
,
N_GEN
,
N_JOBS
)
# Import all configuration variables
class
OptimizationProblem
(
Problem
):
def
__init__
(
self
):
...
...
@@ -49,15 +50,15 @@ print("Optimization Results:")
for
i
,
result
in
enumerate
(
res
.
F
):
print
(
f
"
Solution
{
i
}
:
"
,
end
=
""
)
for
name
,
value
in
zip
(
RESULTS
,
result
):
print
(
f
"
{
name
.
capitalize
()
}
=
{
value
:
.
2
f
}
"
,
end
=
"
,
"
)
# two decimal places
print
(
f
"
{
name
.
capitalize
()
}
=
{
value
:
.
{
PRECISION
}
f
}
"
,
end
=
"
,
"
)
print
()
# Plot the results
plt
.
figure
(
figsize
=
(
8
,
6
))
plt
.
scatter
(
res
.
F
[:,
0
],
res
.
F
[:,
2
])
plt
.
xlabel
(
'
Energy Consumption
'
)
plt
.
ylabel
(
'
Comfort
'
)
plt
.
title
(
'
Pareto Front of Energy Consumption vs Comfort
'
)
plt
.
scatter
(
res
.
F
[:,
0
],
res
.
F
[:,
1
])
plt
.
xlabel
(
PLOT_X
)
plt
.
ylabel
(
PLOT_Y
)
plt
.
title
(
PLOT_TITLE
)
plt
.
grid
(
True
)
plt
.
tight_layout
()
plt
.
show
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/parallel_computing.py
+
5
−
5
View file @
fe0bc53c
...
...
@@ -13,7 +13,7 @@ import shutil
from
time
import
sleep
from
OMPython
import
OMCSessionZMQ
import
numpy
as
np
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
RESULTS
,
model_path
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
RESULTS
,
MODEL_PATH
,
PRECISION
temp_dirs
=
[]
# List to store paths of temporary directories
...
...
@@ -31,7 +31,7 @@ def optimization_function(param_values):
# Copy model file to temporary directory
temp_model_path
=
os
.
path
.
join
(
temp_dir
,
MODEL_FILE
).
replace
(
'
\\
'
,
'
/
'
)
shutil
.
copy
(
model_path
,
temp_model_path
)
shutil
.
copy
(
MODEL_PATH
,
temp_model_path
)
# Load the model in the worker session
load_temp_model_result
=
omc
.
sendExpression
(
f
"
loadFile(
\"
{
temp_model_path
}
\"
)
"
)
...
...
@@ -60,7 +60,7 @@ def optimization_function(param_values):
raise
RuntimeError
(
f
"
Expected file not found:
{
file
}
"
)
# Set model parameters
rounded_param_values
=
{
param
:
round
(
value
,
2
)
for
param
,
value
in
param_values
.
items
()}
# two decimal places
rounded_param_values
=
{
param
:
round
(
value
,
PRECISION
)
for
param
,
value
in
param_values
.
items
()}
for
param
,
value
in
rounded_param_values
.
items
():
set_param_result
=
omc
.
sendExpression
(
f
"
setParameterValue(
{
MODEL_NAME
}
,
{
param
}
,
{
value
}
)
"
)
if
not
set_param_result
:
...
...
@@ -79,8 +79,8 @@ def optimization_function(param_values):
# print(f"Executing command: {value_command}")
value
=
omc
.
sendExpression
(
value_command
)
print
(
f
"
Value for
{
result
}
at
{
SIMULATION_STOP_TIME
}
:
{
value
}
"
)
# Round the result
to 2 decimal places
result_values
[
result
]
=
round
(
value
,
2
)
# Round the result
result_values
[
result
]
=
round
(
value
,
PRECISION
)
if
value
is
None
:
raise
ValueError
(
f
"
Simulation result returned None for
{
result
}
"
)
if
not
isinstance
(
value
,
(
float
,
int
)):
...
...
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