flixopt.calculation ¶
This module provides backwards-compatible aliases for the renamed Optimization classes.
DEPRECATED: This module is deprecated. Use the optimization module instead. The following classes have been renamed: - Calculation -> Optimization - FullCalculation -> Optimization (now the standard, no "Full" prefix) - AggregatedCalculation -> ClusteredOptimization - SegmentedCalculation -> SegmentedOptimization
Import from flixopt.optimization or use the new names from flixopt directly.
Classes¶
Calculation ¶
Calculation(name: str, flow_system: FlowSystem, active_timesteps: Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] = None, folder: Path | None = None, normalize_weights: bool = True)
Bases: Optimization
DEPRECATED: Use Optimization instead.
class for defined way of solving a flow_system optimization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | name of calculation | required |
flow_system | FlowSystem | flow_system which should be calculated | required |
folder | Path | None | folder where results should be saved. If None, then the current working directory is used. | None |
normalize_weights | bool | Whether to automatically normalize the weights of scenarios to sum up to 1 when solving. | True |
active_timesteps | Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] | Deprecated. Use FlowSystem.sel(time=...) or FlowSystem.isel(time=...) instead. | None |
Functions¶
fix_sizes ¶
Fix the sizes of the optimizations to specified values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds | Dataset | None | The dataset that contains the variable names mapped to their sizes. If None, the dataset is loaded from the results. | None |
decimal_rounding | int | None | The number of decimal places to round the sizes to. If no rounding is applied, numerical errors might lead to infeasibility. | 5 |
FullCalculation ¶
FullCalculation(name: str, flow_system: FlowSystem, active_timesteps: Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] = None, folder: Path | None = None, normalize_weights: bool = True)
Bases: Optimization
DEPRECATED: Use Optimization instead (the "Full" prefix has been removed).
FullCalculation solves the complete optimization problem using all time steps.
This is the most comprehensive calculation type that considers every time step in the optimization, providing the most accurate but computationally intensive solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | name of calculation | required |
flow_system | FlowSystem | flow_system which should be calculated | required |
folder | Path | None | folder where results should be saved. If None, then the current working directory is used. | None |
normalize_weights | bool | Whether to automatically normalize the weights of scenarios to sum up to 1 when solving. | True |
active_timesteps | Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] | Deprecated. Use FlowSystem.sel(time=...) or FlowSystem.isel(time=...) instead. | None |
Functions¶
fix_sizes ¶
Fix the sizes of the optimizations to specified values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds | Dataset | None | The dataset that contains the variable names mapped to their sizes. If None, the dataset is loaded from the results. | None |
decimal_rounding | int | None | The number of decimal places to round the sizes to. If no rounding is applied, numerical errors might lead to infeasibility. | 5 |
AggregatedCalculation ¶
AggregatedCalculation(name: str, flow_system: FlowSystem, aggregation_parameters: AggregationParameters, components_to_clusterize: list[Component] | None = None, active_timesteps: Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] = None, folder: Path | None = None)
Bases: ClusteredOptimization
DEPRECATED: Use ClusteredOptimization instead.
AggregatedCalculation reduces computational complexity by clustering time series into typical periods.
This calculation approach aggregates time series data using clustering techniques (tsam) to identify representative time periods, significantly reducing computation time while maintaining solution accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Name of the calculation | required |
flow_system | FlowSystem | FlowSystem to be optimized | required |
aggregation_parameters | AggregationParameters | Parameters for aggregation. See AggregationParameters class documentation | required |
components_to_clusterize | list[Component] | None | list of Components to perform aggregation on. If None, all components are aggregated. This equalizes variables in the components according to the typical periods computed in the aggregation | None |
active_timesteps | Annotated[DatetimeIndex | None, 'DEPRECATED: Use flow_system.sel(time=...) or flow_system.isel(time=...) instead'] | DatetimeIndex of timesteps to use for optimization. If None, all timesteps are used | None |
folder | Path | None | Folder where results should be saved. If None, current working directory is used | None |
Functions¶
fix_sizes ¶
Fix the sizes of the optimizations to specified values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds | Dataset | None | The dataset that contains the variable names mapped to their sizes. If None, the dataset is loaded from the results. | None |
decimal_rounding | int | None | The number of decimal places to round the sizes to. If no rounding is applied, numerical errors might lead to infeasibility. | 5 |
calculate_clustering_weights classmethod ¶
Calculate weights for all datavars in the dataset. Weights are pulled from the attrs of the datavars.
calculate_aggregation_weights classmethod ¶
Deprecated: Use calculate_clustering_weights instead.
SegmentedCalculation ¶
SegmentedCalculation(name: str, flow_system: FlowSystem, timesteps_per_segment: int, overlap_timesteps: int, nr_of_previous_values: int = 1, folder: Path | None = None)
Bases: SegmentedOptimization
DEPRECATED: Use SegmentedOptimization instead.
Solve large optimization problems by dividing time horizon into (overlapping) segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Unique identifier for the calculation, used in result files and logging. | required |
flow_system | FlowSystem | The FlowSystem to optimize, containing all components, flows, and buses. | required |
timesteps_per_segment | int | Number of timesteps in each segment (excluding overlap). | required |
overlap_timesteps | int | Number of additional timesteps added to each segment. | required |
nr_of_previous_values | int | Number of previous timestep values to transfer between segments for initialization. | 1 |
folder | Path | None | Directory for saving results. Defaults to current working directory + 'results'. | None |
Attributes¶
start_values_of_segments property ¶
Gives an overview of the start values of all Segments
main_results property ¶
Aggregated main results from all segments.
Note
For SegmentedOptimization, results are aggregated from SegmentedResults which handles the overlapping segments properly. Individual segment results should not be summed directly as they contain overlapping timesteps.
The objective value shown is the sum of all segment objectives and includes double-counting from overlapping regions. It does not represent a true full-horizon objective value.
summary property ¶
Summary of the segmented optimization with aggregated information from all segments.
Functions¶
do_modeling_and_solve ¶
do_modeling_and_solve(solver: _Solver, log_file: Path | None = None, log_main_results: bool = False, show_individual_solves: bool = False) -> SegmentedOptimization
Model and solve all segments of the segmented optimization.
This method creates sub-optimizations for each time segment, then iteratively models and solves each segment. It supports two output modes: a progress bar for compact output, or detailed individual solve information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver | _Solver | The solver instance to use for optimization (e.g., Gurobi, HiGHS). | required |
log_file | Path | None | Optional path to the solver log file. If None, defaults to folder/name.log. | None |
log_main_results | bool | Whether to log main results (objective, effects, etc.) after each segment solve. Defaults to False. | False |
show_individual_solves | bool | If True, shows detailed output for each segment solve with logger messages. If False (default), shows a compact progress bar with suppressed solver output for cleaner display. | False |
Returns:
| Type | Description |
|---|---|
SegmentedOptimization | Self, for method chaining. |
Note
The method automatically transfers all start values between segments to ensure continuity of storage states and flow rates across segment boundaries.