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
8cd1e7a5
Commit
8cd1e7a5
authored
11 months ago
by
Zizhe Wang
Browse files
Options
Downloads
Patches
Plain Diff
refactor definition of parameters to be maximized
parent
71d959df
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.json
+9
-5
9 additions, 5 deletions
src/config.json
src/config.py
+26
-18
26 additions, 18 deletions
src/config.py
src/parallel_computing.py
+7
-7
7 additions, 7 deletions
src/parallel_computing.py
with
42 additions
and
30 deletions
src/config.json
+
9
−
5
View file @
8cd1e7a5
...
...
@@ -2,9 +2,12 @@
"MODEL_NAME"
:
"SimpleHeatingSystem"
,
"MODEL_FILE"
:
"SimpleHeatingSystem.mo"
,
"SIMULATION_STOP_TIME"
:
3000
,
"PRECISION"
:
2
,
"PARAMETERS"
:
[
"Q_max"
,
"T_set"
],
"OBJECTIVES"
:
[
"energy"
,
"comfort"
],
"MAXIMIZE"
:
[
"comfort"
],
"OBJECTIVES"
:
[
{
"name"
:
"energy"
,
"maximize"
:
false
},
{
"name"
:
"comfort"
,
"maximize"
:
true
}
],
"PARAM_BOUNDS"
:
{
"Q_max"
:
{
"bounds"
:
[
1000
,
5000
],
...
...
@@ -15,12 +18,13 @@
"type"
:
"int"
}
},
"PRECISION"
:
2
,
"OPTIMIZATION_CONFIG"
:
{
"USE_ADAPTIVE_INSTANCE_SELECTION"
:
true
,
"ADAPTIVE_INSTANCE_SELECTION_FREQUENCY"
:
5
,
"ALGORITHM_NAME"
:
"NSGA2"
,
"POP_SIZE"
:
1
,
"N_GEN"
:
1
"POP_SIZE"
:
10
,
"MIN_POP_SIZE"
:
1
,
"N_GEN"
:
10
},
"PLOT_CONFIG"
:
{
"PLOT_X"
:
"Energy Consumption"
,
...
...
This diff is collapsed.
Click to expand it.
src/config.py
+
26
−
18
View file @
8cd1e7a5
...
...
@@ -18,12 +18,13 @@ with open(CONFIG_FILE, 'r') as f:
# Assign configuration variables
MODEL_NAME
=
config
[
'
MODEL_NAME
'
]
MODEL_FILE
=
config
[
'
MODEL_FILE
'
]
SIMULATION_STOP_TIME
=
config
[
'
SIMULATION_STOP_TIME
'
]
PARAMETERS
=
config
[
'
PARAMETERS
'
]
OBJECTIVES
=
config
[
'
OBJECTIVES
'
]
MAXIMIZE
=
config
[
'
MAXIMIZE
'
]
PARAM_BOUNDS
=
config
[
'
PARAM_BOUNDS
'
]
PRECISION
=
config
[
'
PRECISION
'
]
SIMULATION_STOP_TIME
=
config
[
'
SIMULATION_STOP_TIME
'
]
# in seconds
PRECISION
=
config
[
'
PRECISION
'
]
# Results precision (decimal places)
PARAMETERS
=
config
[
'
PARAMETERS
'
]
# Parameters to be varied
OBJECTIVES
=
config
[
'
OBJECTIVES
'
]
# Objectives to be optimize
OBJECTIVE_NAMES
=
[
obj
[
'
name
'
]
for
obj
in
OBJECTIVES
]
MAXIMIZE
=
[
obj
[
'
maximize
'
]
for
obj
in
OBJECTIVES
]
PARAM_BOUNDS
=
config
[
'
PARAM_BOUNDS
'
]
# Parameter range
OPTIMIZATION_CONFIG
=
config
[
'
OPTIMIZATION_CONFIG
'
]
PLOT_CONFIG
=
config
[
'
PLOT_CONFIG
'
]
N_JOBS
=
config
[
'
N_JOBS
'
]
...
...
@@ -41,16 +42,23 @@ def get_types(param_bounds):
PARAM_BOUND_VALUES
=
get_bounds
(
PARAM_BOUNDS
)
PARAM_TYPES
=
get_types
(
PARAM_BOUNDS
)
# "PARAMETERS": Parameters to be varied
# "OBJECTIVES": Objectives to be optimized
# "MAXIMIZE": Objectives to be maximized
# "PARAM_BOUNDS": Parameter range
# "PRECISION": Results precision (decimal places)
# "OPTIMIZATION_CONFIG": Configuration parameters for optimization
# "USE_ADAPTIVE_INSTANCE_SELECTION": Flag to enable or disable adaptive instance selection
# "ADAPTIVE_INSTANCE_SELECTION_FREQUENCY":
# Frequency (in generations) at which adaptive instance selection is applied
# For example, a value of 5 means adaptive instance selection will be applied every 5 generations
# "ALGORITHM_NAME": Optimization algorithm
# "POP_SIZE": Initial population size for the optimization algorithm
# "MIN_POP_SIZE":
# Minimum population size to maintain diversity and prevent premature convergence
# The population size will not be reduced below this value
# "N_GEN": Total number of generations (iterations) for the optimization process
# "N_JOBS": Parallel processing
# Options: '-1', '1', 'n', 'None'
# ====================================================================
# -1 = use all available CPU cores
# 1 = disables parallel processing and runs the tasks sequentially
# n = specifies the exact number of CPU cores to use
# None = will run the tasks sequentially, equivalent to '1'
# ====================================================================
\ No newline at end of file
# Options: '-1', '1', 'n', 'None'
# ====================================================================
# -1 = use all available CPU cores
# 1 = disables parallel processing and runs the tasks sequentially
# n = specifies the exact number of CPU cores to use
# None = will run the tasks sequentially, equivalent to '1'
# ====================================================================
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/parallel_computing.py
+
7
−
7
View file @
8cd1e7a5
...
...
@@ -14,7 +14,7 @@ import numpy as np
from
time
import
sleep
from
joblib
import
Parallel
,
delayed
from
OMPython
import
OMCSessionZMQ
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
PARAMETERS
,
OBJECTIVES
,
PARAM_BOUNDS
,
PARAM_TYPES
,
MODEL_PATH
,
PRECISION
,
OPTIMIZATION_CONFIG
,
N_JOBS
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
PARAMETERS
,
OBJECTIVE
_NAME
S
,
PARAM_BOUNDS
,
PARAM_TYPES
,
MODEL_PATH
,
PRECISION
,
OPTIMIZATION_CONFIG
,
N_JOBS
from
adaptive_instance_selection
import
initial_sampling
,
evaluate_samples
,
advanced_clustering_samples
,
adaptive_select_informative_instances
,
iterative_refinement
temp_dirs
=
[]
# List to store paths of temporary directories
...
...
@@ -77,15 +77,15 @@ def optimization_function(param_values, retries=3, delay=2):
simulate_result
=
omc
.
sendExpression
(
f
"
simulate(
{
MODEL_NAME
}
, stopTime=
{
SIMULATION_STOP_TIME
}
)
"
)
# Retrieve simulation results
result_values
=
{}
for
objective
in
OBJECTIVES
:
value_command
=
f
"
val(
{
objective
}
,
{
SIMULATION_STOP_TIME
}
)
"
for
objective
_name
in
OBJECTIVE
_NAME
S
:
value_command
=
f
"
val(
{
objective
_name
}
,
{
SIMULATION_STOP_TIME
}
)
"
value
=
omc
.
sendExpression
(
value_command
)
print
(
f
"
Value for
{
objective
}
at
{
SIMULATION_STOP_TIME
}
:
{
value
}
"
)
print
(
f
"
Value for
{
objective
_name
}
at
{
SIMULATION_STOP_TIME
}
:
{
value
}
"
)
if
value
is
None
:
raise
ValueError
(
f
"
Simulation result returned None for
{
objective
}
"
)
raise
ValueError
(
f
"
Simulation result returned None for
{
objective
_name
}
"
)
if
not
isinstance
(
value
,
(
float
,
int
)):
raise
ValueError
(
f
"
Simulation result for
{
objective
}
is not in expected format (float or int)
"
)
result_values
[
objective
]
=
round
(
value
,
PRECISION
)
raise
ValueError
(
f
"
Simulation result for
{
objective
_name
}
is not in expected format (float or int)
"
)
result_values
[
objective
_name
]
=
round
(
value
,
PRECISION
)
print
(
f
"
Simulation results:
{
result_values
}
"
)
return
list
(
result_values
.
values
())
...
...
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