Energy System Optimization with Julia
Hamburg University of Applied Science - Summer 2025
# Example: Creating a NamedTuple for a student
function Student(name::String, age::Int, grade::Float64)
return (name = name, age = age, grade = grade)
end
# Create a dictionary of students
students = Dict(
"Alice" => Student("Alice", 20, 3.7),
"Bob" => Student("Bob", 21, 3.5)
)
# Access data using dot notation
println(students["Alice"].grade) # Output: 3.7
# Example data for different scenarios
data = Dict(
"base" => Dict(
"cost" => 10.0,
"limit" => 100.0
),
"high_cost" => Dict(
"cost" => 15.0,
"limit" => 100.0
),
"low_limit" => Dict(
"cost" => 10.0,
"limit" => 50.0
)
)
# Example: Function to solve a simple optimization problem
function solve_optimization(data::Dict)
model = Model(HiGHS.Optimizer)
set_silent(model)
# Define variables and solve model
@variable(model, x >= 0)
@objective(model, Min, data["cost"] * x)
@constraint(model, x <= data["limit"])
optimize!(model)
# Return results as NamedTuple
return (
solution = value(x),
objective = objective_value(model)
)
end
# Store results in DataFrame
results = DataFrame(
scenario = String[],
solution = Float64[],
objective = Float64[]
)
# Solve multiple scenarios
for (name, scenario_data) in data
solution = solve_optimization(scenario_data)
push!(results, (name, solution.solution, solution.objective))
end
Note
The Economic Dispatch problem optimizes power generation for a single time step, assuming all generators are already committed to operation.
Limitations of Economic Dispatch: - Assumes generators are already running - Ignores start-up and shut-down costs - Doesn’t consider minimum up/down times - Single time step optimization
Unit Commitment Solution: - Adds binary variables for generator on/off status - Considers multiple time steps - Includes start-up/shut-down costs - Enforces minimum up/down time, ramping, etc. constraints - More realistic but computationally more complex
Tip
Unit Commitment extends Economic Dispatch by adding operational constraints and time-dependent decisions.
Tip
You can ask questions anytime in class or via email!
How does the mathematical model look like?
Question: What are the sets we need?
Question: What are possible parameters?
\(\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}) + \sum_{w \in \mathcal{W}} C^{var}_w p_{w,t} \right)\)
The objective includes:
\(\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}\)
Tip
This constraint ensures that at each time step \(t\): - The sum of all thermal generator outputs (\(\sum_{g \in \mathcal{G}} p_{g,t}\)) - Plus all wind power outputs (\(\sum_{w \in \mathcal{W}} p_{w,t}\)) - Must exactly match the forecasted demand (\(D^f_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}\)
Tip
For each generator \(g\) at time \(t\): - If the generator is on (\(u_{g,t} = 1\)), its output must be between minimum (\(P^{\min}_g\)) and maximum (\(P^{\max}_g\)) power - If the generator is off (\(u_{g,t} = 0\)), its output must be zero - The binary variable \(u_{g,t}\) ensures these limits are enforced
\(0 \leq p_{w,t} \leq P^f_{w,t} \quad \forall w \in \mathcal{W}, t \in \mathcal{T}\)
Tip
For each wind turbine \(w\) at time \(t\): - Power output must be non-negative - Cannot exceed the forecasted available wind power (\(P^f_{w,t}\)) - Unlike thermal generators, wind turbines don’t have binary variables as the power injection is controllable between 0 and the forecasted available wind power
\(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}|)]\)
Tip
These constraints enforce minimum operating times: - First equation: If a generator starts up at time \(t\), it must stay on for at least \(T^{up}_g\) time periods - Second equation: If a generator shuts down at time \(t\), it must stay off for at least \(T^{down}_g\) time periods - \(\tau\) represents the time periods during which these constraints must be enforced
\(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}\)
Tip
These constraints limit how quickly generators can change their output: - First equation: Power increase between consecutive time steps cannot exceed ramp-up rate \(R^{up}_g\) - Second equation: Power decrease between consecutive time steps cannot exceed ramp-down rate \(R^{down}_g\) - Prevents sudden changes in generator output that could damage equipment
\(\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}) + \sum_{w \in \mathcal{W}} C^{var}_w p_{w,t} \right)\)
subject to
\(\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}\)
\(u_{g,t} \in \{0,1\} \quad \forall g \in \mathcal{G}, t \in \mathcal{T}\)
Question: What type of optimization problem is this?
Question: How can we solve this problem?
Question: What makes this problem challenging?
And that’s it for today’s lecture!
We have covered the Unit Commitment problem 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 VI - Unit Commitment Problem | Dr. Tobias Cors | Home