Building Your Own Optimization-Based Forecast-Based Controller
Introduction
This section provides guidance on how to create your own custom optimization-based forecast-based controller (FBC) in HAMLET. By extending the existing framework, you can implement specialized control strategies tailored to your specific energy system requirements, taking advantage of forecasts and multi-period optimization.
Prerequisites
Before building your own optimization-based FBC, you should have:
A good understanding of mathematical optimization concepts, particularly multi-period optimization
Familiarity with the HAMLET framework and its component models
Knowledge of Python programming
Understanding of forecast integration and receding horizon control
Understanding of the specific requirements for your energy system
General Steps
Define Your Mathematical Formulation
Identify the objective function(s) for your controller over the prediction horizon
Determine the necessary constraints, including temporal coupling constraints
Select appropriate decision variables for each timestep in the horizon
Define how forecasts will be integrated into the problem
Consider terminal constraints or costs for the end of the horizon
Choose an Implementation Approach
Linopy-based implementation (higher-level, more concise)
PyOptInterface-based implementation (lower-level, more control)
Custom solver integration
Implement the Controller
Create a new controller class
Implement the required methods for multi-period optimization
Define the optimization problem with time dimension
Implement the receding horizon approach
Connect to the HAMLET framework
Test and Validate
Verify mathematical correctness
Test with simple scenarios
Compare against existing controllers
Validate with realistic use cases
Test with different forecast qualities to assess robustness
Handling Forecasts
A key aspect of building an FBC is properly integrating forecasts:
Forecast Sources - Determine which forecasts your controller needs (weather, prices, loads, etc.) - Decide how to obtain these forecasts (from HAMLET’s forecasting module or external sources)
Forecast Uncertainty - Consider how to handle forecast uncertainty (e.g., robust optimization, stochastic programming) - Implement fallback strategies for when forecasts are unavailable or unreliable
Forecast Horizon - Determine the appropriate forecast horizon for your application - Consider the trade-off between horizon length and computational complexity
Implementing Receding Horizon Control
The receding horizon approach is central to FBCs:
Optimization Horizon - Define the length of the optimization horizon - Consider the trade-off between horizon length and computational complexity
Control Execution - Implement the logic to apply only the first timestep’s decisions - Update the system state based on the applied decisions
Re-optimization - Implement the logic to shift the horizon forward and re-solve the problem - Update forecasts with the latest available information
Extension Points
The HAMLET framework provides several extension points for custom FBCs:
Custom objective functions over the prediction horizon
Component-specific constraints with temporal coupling
Alternative solver configurations for large-scale problems
Best Practices
Start with a simplified version of your controller (shorter horizon, fewer components)
Incrementally add complexity
Document your mathematical formulation, especially temporal coupling constraints
Use consistent naming conventions for variables across timesteps
Include appropriate tests for different forecast scenarios
Consider computational efficiency (problem size grows with horizon length)
Implement warm-starting to speed up successive optimizations