Skip to content
Snippets Groups Projects
Commit b69bf548 authored by Zizhe Wang's avatar Zizhe Wang
Browse files

style minor improvements

parent 11532b1a
Branches
No related tags found
No related merge requests found
......@@ -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, PRECISION
from config import MODEL_FILE, MODEL_NAME, SIMULATION_STOP_TIME, OBJECTIVES, MODEL_PATH, PRECISION
temp_dirs = [] # List to store paths of temporary directories
......@@ -71,15 +71,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 result in RESULTS:
value_command = f"val({result}, {SIMULATION_STOP_TIME})"
for objective in OBJECTIVES:
value_command = f"val({objective}, {SIMULATION_STOP_TIME})"
value = omc.sendExpression(value_command)
print(f"Value for {result} at {SIMULATION_STOP_TIME}: {value}")
print(f"Value for {objective} at {SIMULATION_STOP_TIME}: {value}")
if value is None:
raise ValueError(f"Simulation result returned None for {result}")
raise ValueError(f"Simulation result returned None for {objective}")
if not isinstance(value, (float, int)):
raise ValueError(f"Simulation result for {result} is not in expected format (float or int)")
result_values[result] = round(value, PRECISION)
raise ValueError(f"Simulation result for {objective} is not in expected format (float or int)")
result_values[objective] = round(value, PRECISION)
print(f"Simulation results: {result_values}")
return list(result_values.values())
......@@ -92,7 +92,7 @@ def optimization_function(param_values, retries=3, delay=2):
shutdown_omc(omc)
# If all attempts fail, return NaNs
return [np.nan] * len(RESULTS)
return [np.nan] * len(OBJECTIVES)
def shutdown_omc(omc):
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment