include(joinpath(@__DIR__, "..", "..", "examples", "julia", "dispatch_model.jl"))
using .DispatchModelPrecompiling packages... 1092.0 ms ✓ QuartoNotebookWorkerJSONExt (serial) 1 dependency successfully precompiled in 1 seconds
This example solves the economic dispatch problem with JuMP and HiGHS. The reusable implementation lives in examples/julia/dispatch_model.jl; this section includes that script, defines a small generator fleet, and reports the least-cost dispatch.
include(joinpath(@__DIR__, "..", "..", "examples", "julia", "dispatch_model.jl"))
using .DispatchModelPrecompiling packages... 1092.0 ms ✓ QuartoNotebookWorkerJSONExt (serial) 1 dependency successfully precompiled in 1 seconds
The generator data include a zero-marginal-cost wind unit, a low-cost solar unit, and a gas unit that covers the remaining demand.
generators = [
Generator("wind", 0.0, 35.0),
Generator("solar", 3.0, 25.0),
Generator("gas", 75.0, 60.0),
]
demand = 80.080.0
The solver chooses generation from the cheapest available units first, while enforcing the demand balance and each unit’s capacity limit.
dispatch = merit_order_dispatch(demand, generators)
cost = total_cost(dispatch, generators)
dispatch, cost(["wind" => 35.0, "solar" => 25.0, "gas" => 20.0], 1575.0)
The solution uses all available wind and solar output, then dispatches gas for the remaining demand.
for (generator_name, output) in dispatch
println("$generator_name: $(round(output; digits = 1)) MW")
end
println("Total cost: $(round(cost; digits = 2))")wind: 35.0 MW
solar: 25.0 MW
gas: 20.0 MW
Total cost: 1575.0
If demand exceeds total available capacity, the model is infeasible and the example raises a clear error.
try
merit_order_dispatch(200.0, generators)
catch error
println(error)
endArgumentError("demand exceeds available capacity")