flixopt.optimize_accessor ¶
Optimization accessor for FlowSystem.
This module provides the OptimizeAccessor class that enables the flow_system.optimize(...) pattern with extensible optimization methods.
Classes¶
OptimizeAccessor ¶
Accessor for optimization methods on FlowSystem.
This class provides the optimization API for FlowSystem, accessible via flow_system.optimize. It supports both direct calling (standard optimization) and method access for specialized optimization modes.
Examples:
Standard optimization (via call):
Rolling horizon optimization:
>>> segments = flow_system.optimize.rolling_horizon(solver, horizon=168)
>>> print(flow_system.solution) # Combined result
Initialize the accessor with a reference to the FlowSystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_system | FlowSystem | The FlowSystem to optimize. | required |
Functions¶
rolling_horizon ¶
rolling_horizon(solver: _Solver, horizon: int = 100, overlap: int = 0, nr_of_previous_values: int = 1) -> list[FlowSystem]
Solve the optimization using a rolling horizon approach.
Divides the time horizon into overlapping segments that are solved sequentially. Each segment uses final values from the previous segment as initial conditions, ensuring dynamic continuity across the solution. The combined solution is stored on the original FlowSystem.
This approach is useful for: - Large-scale problems that exceed memory limits - Annual planning with seasonal variations - Operational planning with limited foresight
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver | _Solver | The solver to use (e.g., HighsSolver, GurobiSolver). | required |
horizon | int | Number of timesteps in each segment (excluding overlap). Must be > 2. Larger values provide better optimization at the cost of memory and computation time. Default: 100. | 100 |
overlap | int | Number of additional timesteps added to each segment for lookahead. Improves storage optimization by providing foresight. Higher values improve solution quality but increase computational cost. Default: 0. | 0 |
nr_of_previous_values | int | Number of previous timestep values to transfer between segments for initialization (e.g., for uptime/downtime tracking). Default: 1. | 1 |
Returns:
| Type | Description |
|---|---|
list[FlowSystem] | List of segment FlowSystems, each with their individual solution. |
list[FlowSystem] | The combined solution (with overlaps trimmed) is stored on the original FlowSystem. |
Raises:
| Type | Description |
|---|---|
ValueError | If horizon <= 2 or overlap < 0. |
ValueError | If horizon + overlap > total timesteps. |
ValueError | If InvestParameters are used (not supported in rolling horizon). |
Examples:
Basic rolling horizon optimization:
>>> segments = flow_system.optimize.rolling_horizon(
... solver,
... horizon=168, # Weekly segments
... overlap=24, # 1-day lookahead
... )
>>> print(flow_system.solution) # Combined result
Inspect individual segments:
>>> for i, seg in enumerate(segments):
... print(f'Segment {i}: {seg.solution["costs"].item():.2f}')
Note
- InvestParameters are not supported as investment decisions require full-horizon optimization.
- Global constraints (flow_hours_max, etc.) may produce suboptimal results as they cannot be enforced globally across segments.
- Storage optimization may be suboptimal compared to full-horizon solutions due to limited foresight in each segment.