1. 安装Julia
- 在官网中Download Julia (julialang.org)下载合适的julia安装包并进行安装
-
安装完成后运行界面如下
2. 配置IDE
- VScode Julia + VSCode - 知乎 (zhihu.com)
- 安装插件:Julia 和 code runner
- 在扩展列表中,右击 Julia,选择扩展设置(Extension Settings)
- 将 Julia: Executable Path (julia.executablePath)的值改为 julia.exe 的绝对路径。
- 如果路径使用反斜线则需要转义(\ -> \),建议使用正斜线(/)
- 如果之前添加了环境变量,可以只写 julia // 或不写
] 进入pkg模式,可以下载所需的包
? 进入help模式
;进入shell模式,可以执行shell命令
3. 安装所需包
- 打开Julia, 进入pkg模式(])
- 输入以下命令
add Cbc
add JuMP
add UnitCommitment
4. 求解Unit Commitment 问题,示例如下
新建sample.jl文件,运行即可
using Cbc
using JuMP
using UnitCommitment
import UnitCommitment:
Formulation,
KnuOstWat2018,
MorLatRam2013,
ShiftFactorsFormulation
# Read benchmark instance
instance = UnitCommitment.read_benchmark(
"matpower/case118/2017-02-01",
)
# Construct model (using state-of-the-art defaults)
model = UnitCommitment.build_model(
instance = instance,
optimizer = Cbc.Optimizer,
)
# Construct model (using customized formulation)
model = UnitCommitment.build_model(
instance = instance,
optimizer = Cbc.Optimizer,
formulation = Formulation(
pwl_costs = KnuOstWat2018.PwlCosts(),
ramping = MorLatRam2013.Ramping(),
startup_costs = MorLatRam2013.StartupCosts(),
transmission = ShiftFactorsFormulation(
isf_cutoff = 0.005,
lodf_cutoff = 0.001,
),
),
)
# Modify the model (e.g. add custom constraints)
@constraint(
model,
model[:is_on]["g3", 1] + model[:is_on]["g4", 1] <= 1,
)
# Solve model
UnitCommitment.optimize!(model)
# Extract solution
solution = UnitCommitment.solution(model)
UnitCommitment.write("output.json", solution)