Energy System Optimization with Julia
Hamburg University of Applied Science - Summer 2025
Objective: Minimize total annual costs (investment + operational) while respecting budget constraints
Decision Variables:
Key Constraints:
Note
The Energy System Design problem combines investment planning (sizing) with operational optimization, enabling comprehensive energy system design. The stochastic formulation considers multiple scenarios to account for uncertainty in renewable generation, demand patterns, and price variations.
\(\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 + \sum_{\omega \in \Omega} \pi_{\omega} (AC^{grid,imp}_{\omega} - AR^{grid,exp}_{\omega})\)
\(\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}\)
\(\sum_{w \in \mathcal{W}} p_{w,t,\omega} + \sum_{v \in \mathcal{V}} p_{v,t,\omega} + (p^{in}_{t,\omega} - p^{out}_{t,\omega}) + \sum_{s \in \mathcal{S}} (p^{dis}_{s,t,\omega} - p^{ch}_{s,t,\omega}) = d_{t,\omega} \quad \forall t \in \mathcal{T}, \omega \in \Omega\)
\(0 \leq p_{w,t,\omega} \leq f_{w,t,\omega} p^{nom}_w \quad \forall w \in \mathcal{W}, t \in \mathcal{T}, \omega \in \Omega\) \(0 \leq p_{v,t,\omega} \leq f_{v,t,\omega} p^{nom}_v \quad \forall v \in \mathcal{V}, t \in \mathcal{T}, \omega \in \Omega\) \(0 \leq p^{ch}_{s,t,\omega} \leq p^{ch,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\) \(0 \leq p^{dis}_{s,t,\omega} \leq p^{dis,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\) \(DoD_s e^{nom}_s \leq e_{s,t,\omega} \leq e^{nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\)
\(e_{s,t,\omega} = (1-sdr_s)e_{s,t-1,\omega} + \eta^{ch}_s p^{ch}_{s,t,\omega} - \frac{p^{dis}_{s,t,\omega}}{\eta^{dis}_s} \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\)
Tip
The model can be adapted to specific use cases, i.e., if a wind park already has a fixed capacity, the corresponding variable can be converted to a parameter. The stochastic formulation allows for more robust investment decisions by considering multiple scenarios.
The basic model can be extended with various constraints, partly covered from previous lectures:
Note
These additional constraints can be included based on the specific requirements of the energy system being designed. Each constraint adds complexity but may be necessary for realistic modeling.
Note
The tutorial demonstrated how to implement and solve the stochastic design problem using Julia and JuMP, including comprehensive sensitivity analysis of key parameters such as investment budget and electricity prices.
Tip
You can ask questions anytime in class or via email!
A two-stage stochastic programming problem is characterized by its decision structure, not its solution method. The key aspects are:
Note
The “two-stage” classification refers to the logical structure and timing of decisions, not how the problem is solved computationally.
In our energy system design problem:
Tip
Whether we solve this as one large optimization problem or use decomposition methods, it remains a two-stage stochastic program due to its decision structure and information flow.
The general form of a two-stage stochastic program is:
\(\min_{x} \quad c^T x + \mathbb{E}_{\omega}[Q(x,\omega)]\)
where:
This structure can be solved:
The choice of solution method depends on:
Note
The two-stage structure provides a framework for modeling decision-making under uncertainty, regardless of the computational approach used to solve it.
A multi-energy system is a system that combines multiple energy carriers (e.g. electricity, hydrogen, heat, etc.) to meet the energy demand of a specific application.
Example case of a hydrogen value chain
Note
The figure shows a multi-energy system with:
In this lecture, we extend the Stochastic System Design problem to include investment decisions for multi-energy systems. This allows us to:
Note
Remember: The design problem combines investment planning (sizing) with operational optimization, enabling comprehensive (multi-)energy system design.
We will focus on optimizing:
… while fullfilling a fixed hydrogen demand. Additionally, we consider a maximum investment budget.
All nominal sizes will be decision variables in our optimization model.
… on the simple example of the hydrogen value chain with electricity and hydrogen as mediums
Note
New additions to the sets:
Note
New operational variables for the electrolyzer:
Note
New cost variable: \(AC^{inv}_x\) for electrolyzer investment costs
Note
New investment cost parameter: \(C^{X}_x\) for electrolyzer capacity costs
Note
Changes in operational parameters:
\(\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 + \sum_{x \in \mathcal{X}} AC^{inv}_x + \sum_{\omega \in \Omega} \pi_{\omega} (AC^{grid,imp}_{\omega} - AR^{grid,exp}_{\omega})\)
Note
Changes in objective function: Added electrolyzer investment costs \(\sum_{x \in \mathcal{X}} AC^{inv}_x\)
\(AC^{inv}_s = \frac{C^{E}_s}{F^{PVAF}} e^{nom}_s + C^{P,ch}_s p^{ch,nom}_s + C^{P,dis}_s 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}\) \(AC^{inv}_x = \frac{C^{X}_x}{F^{PVAF}} p^{nom}_x \quad \forall x \in \mathcal{X}\)
\(\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 + \sum_{x \in \mathcal{X}} C^{X}_x p^{nom}_x \leq B^{max}\)
Note
Changes in investment budget: Added electrolyzer investment costs \(\sum_{x \in \mathcal{X}} C^{X}_x p^{nom}_x\)
\(AC^{grid,imp}_{\omega} = \sum_{t \in \mathcal{T}} (c^{MP}_{t,\omega} + c^{TaL}) p^{in}_{t,\omega} \quad \forall \omega \in \Omega\) \(AR^{grid,exp}_{\omega} = \sum_{t \in \mathcal{T}} c^{MP}_{t,\omega} p^{out}_{t,\omega} \quad \forall \omega \in \Omega\)
\(\sum_{w \in \mathcal{W}} p_{w,t,\omega} + \sum_{v \in \mathcal{V}} p_{v,t,\omega} + (p^{in}_{t,\omega} - p^{out}_{t,\omega}) + \sum_{s \in \mathcal{S}_{\text{El}}} (p^{dis}_{s,t,\omega} - p^{ch}_{s,t,\omega}) = \sum_{x \in \mathcal{X}} p_{x,t,\omega} \quad \forall t \in \mathcal{T}, \omega \in \Omega\)
Note
Changes in electricity balance:
\(\sum_{x \in \mathcal{X}} h_{x,t,\omega} + \sum_{s \in \mathcal{S}_{\text{H2}}} (p^{dis}_{s,t,\omega} - p^{ch}_{s,t,\omega}) = d_{t,\omega} \quad \forall t \in \mathcal{T}, \omega \in \Omega\)
Note
New constraint:
Hydrogen balance equation considering:
\(0 \leq p_{w,t,\omega} \leq f_{w,t,\omega} p^{nom}_w \quad \forall w \in \mathcal{W}, t \in \mathcal{T}, \omega \in \Omega\)
\(0 \leq p_{v,t,\omega} \leq f_{v,t,\omega} p^{nom}_v \quad \forall v \in \mathcal{V}, t \in \mathcal{T}, \omega \in \Omega\)
\(0 \leq p^{ch}_{s,t,\omega} \leq p^{ch,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\) \(0 \leq p^{dis}_{s,t,\omega} \leq p^{dis,nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\) \(DoD_s e^{nom}_s \leq e_{s,t,\omega} \leq e^{nom}_s \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\)
\(e_{s,t,\omega} = (1-sdr_s)e_{s,t-1,\omega} + \eta^{ch}_s p^{ch}_{s,t,\omega} - \frac{p^{dis}_{s,t,\omega}}{\eta^{dis}_s} \quad \forall s \in \mathcal{S}, t \in \mathcal{T}, \omega \in \Omega\)
\(0 \leq p_{x,t,\omega} \leq p^{nom}_x \quad \forall x \in \mathcal{X}, t \in \mathcal{T}, \omega \in \Omega\) \(h_{x,t,\omega} = \beta_x p_{x,t,\omega} \quad \forall x \in \mathcal{X}, t \in \mathcal{T}, \omega \in \Omega\)
Note
New constraints for electrolyzer:
Multi-energy systems (MES) and energy hubs represent a fundamental shift in energy system design, moving from single-carrier optimization to integrated multi-carrier approaches. The energy hub concept was originally introduced by Geidl and Andersson (2007) as a framework for optimal coupling of energy infrastructures, enabling the integration of electricity, heat, gas, and other energy carriers within a unified optimization framework.
Note
The energy hub concept provides a systematic approach to model and optimize multi-carrier energy systems, enabling the integration of renewable energy sources, storage technologies, and energy conversion processes.
Several comprehensive literature reviews have been conducted in recent years, highlighting the growing importance of multi-energy systems:
Recent reviews by Jasinski et al. (2023), Lasemi et al. (2022), and Onen, Mokryani, and Zubo (2022) focus on uncertainty modeling approaches in energy hub optimization. These reviews identify three main approaches: - Stochastic Programming: Using scenario-based optimization with Monte Carlo simulation - Robust Optimization: Providing conservative but computationally efficient solutions - Hybrid Methods: Combining the advantages of both approaches
Papadimitriou et al. (2023) provides a systematic review of modeling formulations, optimization methods, and market interactions in energy hubs. Ding et al. (2022) extends this analysis to include trading and control structures for handling large-scale datasets.
Earlier reviews by Maroufmashat et al. (2019) and Son et al. (2021) identified the hydrogen economy as a major application area for energy hubs, following the original proposals by Geidl and Andersson (2007). These reviews systematically analyzed 200+ articles published between 2007-2017, establishing the foundation for current research directions.
Recent literature identifies hydrogen and Power-to-X (P2X) technologies as critical future research directions. Kountouris et al. (2023) developed an optimization model for P2X-integrated energy hubs applied to an industrial park in Denmark, demonstrating the economic viability of hydrogen, methanol, and ammonia production.
Wassermann et al. (2022) addressed the planning and operation problem for hydrogen demand in refinery applications, presenting MILP model extensions for water electrolysis and cavern storage. This work demonstrates the practical application of energy hub concepts to real-world industrial decarbonization projects.
The representation of renewable energy uncertainty is identified as a core challenge across multiple reviews. Ringkjöb, Haugan, and Solbrekke (2018), who reviewed 75 energy system modeling frameworks, conclude that high spatiotemporal resolution is essential for accurate RES representation, but comes at significant computational cost.
Note
The trade-off between model fidelity and computational burden is a central challenge in multi-energy system optimization, particularly when considering renewable energy uncertainty.
Several studies demonstrate the effectiveness of Benders decomposition for energy hub optimization. Mansouri et al. (2020), Chen et al. (2019), and Hemmati, Ghaderi, and Ghazizadeh (2018) use Benders decomposition to separate dimensioning decisions (master problem) from operational optimization (subproblems), enabling efficient solution of large-scale problems.
Recent frameworks address computational complexity through innovative approaches:
Gonzato, Bruninx, and Delarue (2021) analyzed techniques for reducing temporal scope in expansion planning models with long-term storage, recommending against temporal reductions and advocating for full-year time series inclusion to prevent biases in system design.
The integration of hydrogen supply chain network design (HSCND) with energy hub optimization represents an emerging research area. Li, Manier, and Manier (2019) provides a comprehensive review of HSCND optimization approaches, while Riera, Lima, and Knio (2023) reviews hydrogen production and supply chain modeling specifically.
Note
The integration of hydrogen supply chain optimization with energy hub concepts enables comprehensive planning of green hydrogen value chains from production to end-use applications.
Several reviews assess the maturity and capabilities of open-source energy system optimization tools:
Recent literature reviews identify several critical future research directions:
Note
The energy hub concept has evolved from a theoretical framework to a practical tool for industrial decarbonization, with growing applications in hydrogen value chains and Power-to-X systems.
Questions?
For more interesting literature to learn more about Julia, take a look at the literature list of this course.
Lecture IX - Multi-Energy Systems | Dr. Tobias Cors | Home