Energy System Optimization with Julia
Hamburg University of Applied Science - Summer 2025
Note
The Unit Commitment problem extends Economic Dispatch by adding operational constraints and time-dependent unit commitment decisions.
\(\text{Minimize} \quad \sum_{t \in \mathcal{T}} \left( \sum_{g \in \mathcal{G}} (c^{var}_g p_{g,t} + c^{fix}_g u_{g,t} + c^{start}_g v_{g,t}) + \sum_{w \in \mathcal{W}} c^{var}_w p_{w,t} \right)\)
\(\sum_{g \in \mathcal{G}} p_{g,t} + \sum_{w \in \mathcal{W}} p_{w,t} = d^f_t \quad \forall t \in \mathcal{T}\)
\(p^{\min}_g u_{g,t} \leq p_{g,t} \leq p^{\max}_g u_{g,t} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
\(0 \leq p_{w,t} \leq p^f_{w,t} \quad \forall w \in \mathcal{W}, t \in \mathcal{T}\)
\(u_{g,t} - u_{g,t-1} \leq u_{g,\tau} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}, \tau \in [t+1, \min(t+T^{up}_g-1,|\mathcal{T}|)]\) \(u_{g,t-1} - u_{g,t} \leq 1 - u_{g,\tau} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}, \tau \in [t+1, \min(t+T^{down}_g-1,|\mathcal{T}|)]\)
\(p_{g,t} - p_{g,t-1} \leq R^{up}_g \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\) \(p_{g,t-1} - p_{g,t} \leq R^{down}_g \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
\(v_{g,t} \geq u_{g,t} - u_{g,t-1} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Tip
The Unit Commitment problem is fundamental for power system operation, providing a realistic model estimating generator operation over time.
Note
The tutorial demonstrated how to implement and solve the UC problem using Julia and JuMP, including simple visualization of results over time.
Tip
You can ask questions anytime in class or via email!
In this lecture, we will extend the Unit Commitment problem by adding:
1. Generator efficiency modeling
2. Storage system modeling
3. Storage capacity optimization
These extensions make the model more realistic and allow for more sophisticated analysis of power systems.
The simplest approach is to assume constant efficiency:
\(\eta_g = \text{constant} \quad \forall g \in \mathcal{G}\)
Note
Constant efficiency is a simplification that works well for generators operating near their optimal point.
While efficiency can be modeled as a linear function of power output:
\(\eta_g(p_{g,t}) = \alpha_g + \beta_g p_{g,t}\)
This leads to a non-linear fuel consumption function:
\(f_{g,t} = \frac{p_{g,t}}{\alpha_g + \beta_g p_{g,t}}\)
Note
Direct linear approximation of efficiency is not possible in MILP because:
For non-linear fuel consumption curves, we use piecewise linear approximation:
\(f_{g,t} = \sum_{k \in \mathcal{K}} \lambda_{g,t,k} F_{g,k}\)
where:
To ensure that only one segment is active at a time, we introduce binary variables \(\delta_{g,t,k}\):
These binary variables are used to:
Segment Selection:
\(\sum_{k \in \mathcal{K}} \delta_{g,t,k} = 1 \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Power Output:
\(p_{g,t} = \sum_{k \in \mathcal{K}} \lambda_{g,t,k} P_{g,k} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Segment Limits:
\(\lambda_{g,t,k} \leq \delta_{g,t,k} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}, k \in \mathcal{K}\)
Note
The binary variables \(\delta_{g,t,k}\) ensure that only one segment is active at a time, while the weights \(\lambda_{g,t,k}\) determine the exact position within that segment. This approach maintains linearity while accurately approximating non-linear efficiency curves.
Diagram Explanation
The diagram shows:
The point lies in segment 2, with:
The piecewise linear approximation must be convex to ensure:
The binary variables \(\delta_{g,t,k}\) enforce convexity by:
In the example above:
Tip
While the efficiency curve of a thermal generator typically is concave, we model the fuel consumption curve (\(f = p/\eta\)) which is convex. This allows us to use piecewise linear approximation in our MILP formulation while maintaining mathematical properties needed for optimization. The convexity of the fuel consumption curve allows us to use piecewise linear approximation in our MILP formulation while maintaining mathematical properties needed for optimization.
We model a battery storage system with the following characteristics:
\(e_{s,t} = (1-sdr_s)e_{s,t-1} + \eta^{ch}_s p^{ch}_{s,t} - \frac{p^{dis}_{s,t}}{\eta^{dis}_s} \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
Tip
This constraint ensures that the energy level at time \(t\) equals:
For batteries the energy level is often referred to as state of charge (SOC).
\(E^{min}_s \leq e_{s,t} \leq E^{max}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
Tip
This constraint ensures that:
\(0 \leq p^{ch}_{s,t} \leq P^{ch,max}_s u^{ch}_{s,t} \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
\(0 \leq p^{dis}_{s,t} \leq P^{dis,max}_s u^{dis}_{s,t} \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
\(u^{ch}_{s,t} + u^{dis}_{s,t} \leq 1 \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
Tip
These constraints ensure that:
Question: When do we need the mutual exclusion constraint from a technical perspective?
Question: When do we need the mutual exclusion constraint from an economic perspective?
Summary: Mutual Exclusion Decision
The mutual exclusion constraint should be included when:
The decision depends on both the storage technology and the specific economic context of the application.
\(p^{ch}_{s,t} - p^{ch}_{s,t-1} \leq R^{ch}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\) \(p^{dis}_{s,t} - p^{dis}_{s,t-1} \leq R^{dis}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
Tip
These constraints limit how quickly the storage can change its charging or discharging power:
We now optimize both energy and power capacity:
New Decision Variables:
Variables (previously parameters):
Energy Capacity:
\(e^{min}_s = DoD_s e^{nom}_s \quad \forall s \in \mathcal{S}\)
\(e^{max}_s = e^{nom}_s \quad \forall s \in \mathcal{S}\)
Power Capacity:
\(p^{ch,max}_s = p^{ch,nom}_s \quad \forall s \in \mathcal{S}\)
\(p^{dis,max}_s = p^{dis,nom}_s \quad \forall s \in \mathcal{S}\)
Add to the original objective:
\(\text{Minimize} \quad ... + \sum_{s \in \mathcal{S}} (C^{E}_s / F^{PVAF} e^{nom}_s + C^{P,ch}_s p^{ch,nom}_s + C^{P,dis}_s p^{dis,nom}_s)\)
Note
This extension allows us to find the optimal storage capacity that balances investment costs with operational benefits. The objective function includes both energy and power capacity costs.
The investment costs and operational costs need to be calculated on the same time basis to be comparable. While operational costs are calculated for a specific time horizon (e.g. one year), investment costs are typically one-time fixed costs. Therefore, the investment costs need to be converted to an equivalent annual cost using the present value annuity factor (PVAF). This ensures we compare annual operational benefits with annualized investment costs.
Tip
The optimal storage capacity depends on the specific use case, electricity prices, and technical parameters of the storage system. The model now accounts for separate costs and capacities for energy storage and power handling equipment (charging/discharging infrastructure that converts between electrical energy and the storage medium’s form of energy, such as chemical energy in batteries or potential energy in pumped hydro).
Energy Prices in Ancillary Services
When ancillary services are activated:
Reactive Power and Battery Storage
Battery storage systems with power electronic converters (inverters) can provide reactive power:
Tip
Storage systems can participate in multiple markets simultaneously, but need to consider:
And that’s it for today’s lecture!
We have covered a extended version of the Unit Commitment problem with operation and sizing of storage systems and its mathematical formulation. The tutorial will help you implement and solve this problem using Julia and JuMP.
Questions?
For more interesting literature to learn more about Julia, take a look at the literature list of this course.
For a detailed mathematical formulation of the Unit Commitment problem, see Morales-Espana, Latorre, and Ramos (2013) and Zimmermann and Kather (2019).
Lecture VII - Storage Modeling | Dr. Tobias Cors | Home