Energy System Optimization with Julia
Hamburg University of Applied Science - Summer 2025
Objective: Minimize total generation and storage costs over multiple time periods
Decision Variables:
Key Constraints:
Note
The Unit Commitment problem with storage extends the basic UC problem by adding storage system modeling and operation constraints.
\(\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} + \sum_{s \in \mathcal{S}} (p^{dis}_{s,t} - p^{ch}_{s,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}\)
\(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}\)
\(E^{min}_s \leq e_{s,t} \leq E^{max}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
\(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}\)
\(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
The Unit Commitment problem with storage provides a comprehensive model for power system operation, including both generation and storage resources.
Note
The tutorial demonstrated how to implement and solve the UC problem with storage using Julia and JuMP, including visualization of generation and storage operation over time.
Tip
You can ask questions anytime in class or via email!
In mathematical optimization, particularly for Mixed-Integer Linear Programming (MILP) problems like the Unit Commitment problem, the concepts of “tight” and “compact” formulations are crucial for efficient problem solving.
A formulation is considered “tight” when there is a small gap between the optimal solution of the linear programming (LP) relaxation and the integer solution. This is important because:
A formulation is considered “compact” when it uses fewer variables and constraints while maintaining accuracy. This is important because:
# Less tight formulation
p_{g,t} ≤ P^{max}_g u_{g,t} # Only upper bound
# Tighter formulation
P^{min}_g u_{g,t} ≤ p_{g,t} ≤ P^{max}_g u_{g,t} # Both bounds
# Less tight formulation
e_{s,t} = e_{s,t-1} + p^{ch}_{s,t} - p^{dis}_{s,t} # Without efficiency
# Tighter formulation
e_{s,t} = (1-sdr_s)e_{s,t-1} + η^{ch}_s p^{ch}_{s,t} - p^{dis}_{s,t}/η^{dis}_s # With efficiency
# Less compact formulation
u_{g,t} - u_{g,t-1} ≤ u_{g,τ} ∀τ ∈ [t+1, t+T^{up}_g-1]
u_{g,t-1} - u_{g,t} ≤ 1 - u_{g,τ} ∀τ ∈ [t+1, t+T^{down}_g-1]
# More compact formulation
∑_{τ=t}^{t+T^{up}_g-1} u_{g,τ} ≥ T^{up}_g (u_{g,t} - u_{g,t-1})
∑_{τ=t}^{t+T^{down}_g-1} (1-u_{g,τ}) ≥ T^{down}_g (u_{g,t-1} - u_{g,t})
# Less compact formulation
p^{ch}_{s,t} ≤ P^{ch,max}_s u^{ch}_{s,t}
p^{dis}_{s,t} ≤ P^{dis,max}_s u^{dis}_{s,t}
u^{ch}_{s,t} + u^{dis}_{s,t} ≤ 1
# More compact formulation
p^{ch}_{s,t}/P^{ch,max}_s + p^{dis}_{s,t}/P^{dis,max}_s ≤ 1
Note
These concepts are particularly important in the Unit Commitment problem with storage and approximations of part-load efficiencies because:
In this lecture, we extend the Unit Commitment problem to include investment decisions for energy system components. This allows us to:
Note
The design problem combines investment planning (sizing) with operational optimization, enabling comprehensive energy system design.
We will focus on optimizing:
… while fullfilling a fixed electric demand. Additionally, we consider a maximum investment budget.
All nominal sizes will be decision variables in our optimization model.
The Present Value Annuity Factor (PVAF) is used to convert investment costs into equivalent annual costs. It is calculated as:
\(F^{PVAF} = \frac{(1 + r)^n - 1}{r(1 + r)^n}\)
where: - \(r\) is the discount rate (e.g., 0.05 for 5%) - \(n\) is the component lifetime in years (we assume the same lifetime for all components in the following)
This factor allows us to:
\(\text{Minimize} \quad \sum_{s \in \mathcal{S}} AC^{inv}_s + \sum_{w \in \mathcal{W}} AC^{inv}_w + \sum_{v \in \mathcal{V}} AC^{inv}_v + AC^{grid,imp} - AR^{grid,exp}\)
Note
The objective function minimizes the total annual costs of the energy system:
Investment costs for all components:
Grid electricity costs/revenues:
\(AC^{inv}_s = \frac{C^{E}_s}{F^{PVAF}} e^{nom}_s + \frac{C^{P,ch}_s}{F^{PVAF}} p^{ch,nom}_s + \frac{C^{P,dis}_s}{F^{PVAF}} p^{dis,nom}_s \quad \forall s \in \mathcal{S}\) \(AC^{inv}_w = \frac{C^{W}_w}{F^{PVAF}} p^{nom}_w \quad \forall w \in \mathcal{W}\) \(AC^{inv}_v = \frac{C^{PV}_v}{F^{PVAF}} p^{nom}_v \quad \forall v \in \mathcal{V}\)
Note
The investment costs are annualized using the Present Value Annuity Factor (PVAF):
Storage investment includes:
Wind and PV investment include:
\(\sum_{s \in \mathcal{S}} (C^{E}_s e^{nom}_s + C^{P,ch}_s p^{ch,nom}_s + C^{P,dis}_s p^{dis,nom}_s) + \sum_{w \in \mathcal{W}} C^{W}_w p^{nom}_w + \sum_{v \in \mathcal{V}} C^{PV}_v p^{nom}_v \leq B^{max}\)
Note
The investment budget constraint ensures that:
Total investment costs do not exceed the maximum budget
Includes all component investments:
\(AC^{grid,imp} = \sum_{t \in \mathcal{T}} (c^{MP}_t + c^{TaL}) p^{in}_t\) \(AR^{grid,exp} = \sum_{t \in \mathcal{T}} c^{MP}_t p^{out}_t\)
Note
The grid electricity costs and revenues are calculated as:
Import costs include:
Export revenue includes:
\(\sum_{w \in \mathcal{W}} p_{w,t} + \sum_{v \in \mathcal{V}} p_{v,t} + (p^{in}_t - p^{out}_t) + \sum_{s \in \mathcal{S}} (p^{dis}_{s,t} - p^{ch}_{s,t}) = d_t \quad \forall t \in \mathcal{T}\)
Note
The power balance ensures that at each time step:
Total generation equals total demand:
Net grid power flow is:
\(0 \leq p_{w,t} \leq f_{w,t} p^{nom}_w \quad \forall w \in \mathcal{W}, t \in \mathcal{T}\)
Note
Wind power output is constrained by:
Non-negativity (no negative generation)
Maximum available power:
\(0 \leq p_{v,t} \leq f_{v,t} p^{nom}_v \quad \forall v \in \mathcal{V}, t \in \mathcal{T}\)
Note
PV power output is constrained by:
Non-negativity (no negative generation)
Maximum available power:
\(0 \leq p^{ch}_{s,t} \leq p^{ch,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\) \(0 \leq p^{dis}_{s,t} \leq p^{dis,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\) \(DoD_s e^{nom}_s \leq e_{s,t} \leq e^{nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}\)
Note
Storage operation is constrained by:
Charging power limits:
Discharging power limits:
Energy level limits:
\(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}\)
Note
The storage energy balance accounts for:
Previous energy level:
Charging:
Discharging:
Note
The model can be adapted to the specific use case, i.e. if a windpark already has a fixed capacity, the corresponding variable can be coverted to a parameter.
Note
The sizing problem provides a foundation for comprehensive energy system planning and optimization.
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 VIII - Energy System Design Problem | Dr. Tobias Cors | Home