diff --git a/src/andromede/simulation/optimization.py b/src/andromede/simulation/optimization.py index 3f5463c..d411106 100644 --- a/src/andromede/simulation/optimization.py +++ b/src/andromede/simulation/optimization.py @@ -623,8 +623,12 @@ def _solver_variable_name( if (self.context.full_var_name and self.context.tree_node) else "" ) - scenario_suffix = f"_s{s}" if s is not None else "" - block_suffix = f"_t{t}" if t is not None else "" + scenario_suffix = ( + f"_s{s}" if (s is not None and self.context.scenarios > 1) else "" + ) + block_suffix = ( + f"_t{t}" if (t is not None and self.context.block_length() > 1) else "" + ) # Set solver var name # Externally, for the Solver, this variable will have a full name @@ -653,10 +657,11 @@ def _create_variables(self) -> None: ) time_indices: Iterable[Optional[int]] = [None] - if var_indexing.time: + if var_indexing.is_time_varying(): time_indices = self.context.get_time_indices(var_indexing) + scenario_indices: Iterable[Optional[int]] = [None] - if var_indexing.scenario: + if var_indexing.is_scenario_varying(): scenario_indices = self.context.get_scenario_indices(var_indexing) for t, s in itertools.product(time_indices, scenario_indices): diff --git a/src/andromede/study/data.py b/src/andromede/study/data.py index c3a1b19..99df164 100644 --- a/src/andromede/study/data.py +++ b/src/andromede/study/data.py @@ -191,7 +191,7 @@ def check_requirement(self, time: bool, scenario: bool) -> bool: @dataclass(frozen=True) -class DatabaseIndex: +class ComponentParameterIndex: component_id: str parameter_name: str @@ -204,20 +204,22 @@ class DataBase: Data can have different structure : constant, varying in time or scenarios. """ - _data: Dict[DatabaseIndex, AbstractDataStructure] + _data: Dict[ComponentParameterIndex, AbstractDataStructure] def __init__(self) -> None: - self._data: Dict[DatabaseIndex, AbstractDataStructure] = {} + self._data: Dict[ComponentParameterIndex, AbstractDataStructure] = {} def get_data(self, component_id: str, parameter_name: str) -> AbstractDataStructure: - return self._data[DatabaseIndex(component_id, parameter_name)] + return self._data[ComponentParameterIndex(component_id, parameter_name)] def add_data( self, component_id: str, parameter_name: str, data: AbstractDataStructure ) -> None: - self._data[DatabaseIndex(component_id, parameter_name)] = data + self._data[ComponentParameterIndex(component_id, parameter_name)] = data - def get_value(self, index: DatabaseIndex, timestep: int, scenario: int) -> float: + def get_value( + self, index: ComponentParameterIndex, timestep: int, scenario: int + ) -> float: if index in self._data: return self._data[index].get_value(timestep, scenario) else: