Energy System Optimization with Julia
Hamburg University of Applied Science - Summer 2026
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 a piecewise linear approximation with a Special Ordered Set of type 2 (SOS2) formulation:
The breakpoints lie on (or slightly above) the convex fuel curve; the red chords in the figure are the linear segments.
\(p_{g,t} = \sum_{k \in \mathcal{B}} \lambda_{g,t,k} P_{g,k} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
\(f_{g,t} = \sum_{k \in \mathcal{B}} \lambda_{g,t,k} F_{g,k} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Convex combination:
\(\sum_{k \in \mathcal{B}} \lambda_{g,t,k} = 1 \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
One active segment:
\(\sum_{s \in \mathcal{L}} \delta_{g,t,s} = 1 \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Link weights to segments (at most two adjacent \(\lambda\)’s may be positive):
\(\lambda_{g,t,1} \leq \delta_{g,t,1} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
\(\lambda_{g,t,k} \leq \delta_{g,t,k-1} + \delta_{g,t,k} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}, k \in \{2,\ldots,K-1\}\)
\(\lambda_{g,t,K} \leq \delta_{g,t,K-1} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Note
When \(\delta_{g,t,s}=1\), only \(\lambda_{g,t,s}\) and \(\lambda_{g,t,s+1}\) can be positive. The operating point is a convex combination of the two endpoints of segment \(s\), so \((p_{g,t}, f_{g,t})\) lies on the corresponding chord. This is the standard MILP formulation for approximating a convex fuel curve.
Diagram Explanation
The diagram shows:
The green point lies on segment 2 (between \(P_{g,1}\) and \(P_{g,2}\)), with:
The fuel consumption curve \(f(p)\) is convex (for convex efficiency curves, \(f = p/\eta\) is convex in \(p\)). For a convex function, any point on a chord between two breakpoints lies above the true curve; the MILP uses the chord as an outer approximation (typically a slight overestimate of fuel use).
The SOS2 constraints ensure:
In the example above, with \(\delta_{g,t,2}=1\):
\(p_{g,t} = \lambda_{g,t,1} P_{g,1} + \lambda_{g,t,2} P_{g,2}, \quad f_{g,t} = \lambda_{g,t,1} F_{g,1} + \lambda_{g,t,2} F_{g,2}\)
Tip
While the efficiency curve of a thermal unit is often concave in \(p\), we approximate the fuel consumption curve \(f(p)\), which is convex. That convexity justifies this chord-based MILP formulation. Tighter UC formulations (e.g. incremental heat input) are discussed in Morales-Espana et al. (2013).
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 et al. (2013) and Zimmermann and Kather (2019).
Lecture VII - Storage Modeling | Dr. Tobias Cors | Home