@@ -173,6 +173,72 @@ def remove_listener(self, name: str):
173173 """
174174 self ._remove_listener (self .sim , name .encode ())
175175
176+ def add_scenario (self , scenario_config : str = None , real_actions : list [tuple ] = None , integer_actions : list [tuple ] = None ,
177+ boolean_actions : list [tuple ] = None ,
178+ string_actions : list [tuple ] = None ):
179+ """
180+ Add a scenario to the simulation.
181+ Args:
182+ scenario_config (str, optional): Optional scenario configuration XML file.
183+ real_actions (list of tuples): List of real actions as (time_point, identifier, value).
184+ integer_actions (list of tuples): List of integer actions as (time_point, identifier, value).
185+ boolean_actions (list of tuples): List of boolean actions as (time_point, identifier, value).
186+ string_actions (list of tuples): List of string actions as (time_point, identifier, value).
187+ """
188+
189+ listener = None
190+ if scenario_config is not None :
191+ load_scenario = dll .ecos_scenario_load
192+ load_scenario .argtypes = [c_char_p ]
193+ load_scenario .restype = c_void_p
194+ listener = load_scenario (str .encode ("utf-8" ))
195+
196+ else :
197+ create_scenario = dll .ecos_scenario_create
198+ create_scenario .restype = c_void_p
199+ listener = create_scenario ()
200+
201+ if listener is None :
202+ raise ValueError ("Unable to create/load scenario: " + EcosLib .get_last_error ())
203+
204+ if real_actions is not None :
205+ for action in real_actions :
206+ scenario_add_real_action = dll .ecos_scenario_add_real_action
207+ scenario_add_real_action .argtypes = [c_void_p , c_double , c_char_p , c_double ]
208+ scenario_add_real_action .restype = c_bool
209+
210+ time_point , identifier , value = action
211+ scenario_add_real_action (listener , time_point , identifier .encode ("utf-8" ), value )
212+
213+ if integer_actions is not None :
214+ for action in integer_actions :
215+ scenario_add_integer_action = dll .ecos_scenario_add_real_action
216+ scenario_add_integer_action .argtypes = [c_void_p , c_double , c_char_p , c_int ]
217+ scenario_add_integer_action .restype = c_bool
218+
219+ time_point , identifier , value = action
220+ scenario_add_integer_action (listener , time_point , identifier .encode ("utf-8" ), value )
221+
222+ if boolean_actions is not None :
223+ for action in boolean_actions :
224+ scenario_add_boolean_action = dll .ecos_scenario_add_real_action
225+ scenario_add_boolean_action .argtypes = [c_void_p , c_double , c_char_p , c_bool ]
226+ scenario_add_boolean_action .restype = c_bool
227+
228+ time_point , identifier , value = action
229+ scenario_add_boolean_action (listener , time_point , identifier .encode ("utf-8" ), value )
230+
231+ if string_actions is not None :
232+ for action in string_actions :
233+ scenario_add_string_action = dll .ecos_scenario_add_real_action
234+ scenario_add_string_action .argtypes = [c_void_p , c_double , c_char_p , c_char_p ]
235+ scenario_add_string_action .restype = c_bool
236+
237+ time_point , identifier , value = action
238+ scenario_add_string_action (listener , time_point , identifier .encode ("utf-8" ), value .encode ("utf-8" ))
239+
240+ self ._add_listener (self .sim , b'scenario' , listener )
241+
176242 def add_csv_writer (self , result_file : str , csv_config : str = None , identifiers : list [str ] = None ,
177243 decimation_factor : int = None ):
178244 """
@@ -208,21 +274,6 @@ def add_csv_writer(self, result_file: str, csv_config: str = None, identifiers:
208274
209275 self ._add_listener (self .sim , b'csv_writer' , listener )
210276
211- def load_scenario (self , scenario_file : str ):
212- """
213- Load a scenario file into the simulation.
214- Args:
215- scenario_file (str): Path to the scenario file to load.
216- Raises:
217- Exception: If loading the scenario fails in the underlying library.
218- """
219- _load_scenario = dll .ecos_simulation_load_scenario
220- _load_scenario .argtypes = [c_void_p , c_char_p ]
221- _load_scenario .restype = c_bool
222-
223- if not _load_scenario (self .sim , scenario_file .encode ()):
224- raise Exception (EcosLib .get_last_error ())
225-
226277 def get_integer (self , identifier : str ):
227278 val = c_int ()
228279 if not self ._get_integer (self .sim , identifier .encode (), byref (val )):
0 commit comments