"""Iterator on arithmetic expressions in a catalogMichel BierlaireThu Apr 17 2025, 08:30:58"""from__future__importannotationsfrombiogeme.exceptionsimportBiogemeErrorfrom.central_controllerimportCentralControllerfrom.configurationimportConfiguration
[docs]classSelectedConfigurationsIterator:"""A multiple expression is an expression that contains Catalog. This iterator loops on pre-specified configurations """def__init__(self,the_central_controller:CentralController,selected_configurations:set[Configuration]|None=None,):"""Ctor. :param the_central_controller: expression containing Catalogs :param selected_configurations: selected configurations to iterate on. If None, all configurations are considered. """self.the_central_controller=the_central_controllerself.configurations=(selected_configurationsorthe_central_controller.all_configurations)ifnotisinstance(self.configurations,set):error_msg=f'The selected configurations must be a set, and not an object of type {type(self.configurations)}'raiseBiogemeError(error_msg)self.set_iterator=iter(self.configurations)self.current_configuration=next(self.set_iterator)self.the_central_controller.set_configuration(self.current_configuration)self.first=Trueself.number=0def__iter__(self)->SelectedConfigurationsIterator:returnselfdef__next__(self)->Configuration:self.number+=1ifself.first:self.first=Falsereturnself.current_configurationself.current_configuration=next(self.set_iterator)self.the_central_controller.set_configuration(self.current_configuration)returnself.current_configuration