Skip to content

Commit

Permalink
Fixed unit test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmnz committed Nov 29, 2024
1 parent b914bc1 commit 9471fb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/andromede/simulation/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 8 additions & 6 deletions src/andromede/study/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_investment_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def candidate() -> Component:
)
],
objective_operational_contribution=(param("op_cost") * var("generation"))
.sum()
.time_sum()
.expec(),
objective_investment_contribution=param("invest_cost")
* var("delta_invest"),
Expand Down

0 comments on commit 9471fb5

Please sign in to comment.