mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-07 00:38:51 -06:00
Add basic formulation tests
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using UnitCommitment, LinearAlgebra, Cbc, JuMP
|
||||
|
||||
@testset "build_model" begin
|
||||
instance = UnitCommitment.read_benchmark("test/case14")
|
||||
for line in instance.lines, t in 1:4
|
||||
line.normal_flow_limit[t] = 10.0
|
||||
end
|
||||
optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
||||
model = UnitCommitment.build_model(
|
||||
instance = instance,
|
||||
optimizer = optimizer,
|
||||
variable_names = true,
|
||||
)
|
||||
@test name(model[:is_on]["g1", 1]) == "is_on[g1,1]"
|
||||
|
||||
# Optimize and retrieve solution
|
||||
UnitCommitment.optimize!(model)
|
||||
solution = UnitCommitment.solution(model)
|
||||
|
||||
# Write solution to a file
|
||||
filename = tempname()
|
||||
UnitCommitment.write(filename, solution)
|
||||
loaded = JSON.parsefile(filename)
|
||||
@test length(loaded["Is on"]) == 6
|
||||
|
||||
# Verify solution
|
||||
@test UnitCommitment.validate(instance, solution)
|
||||
|
||||
# Reoptimize with fixed solution
|
||||
UnitCommitment.fix!(model, solution)
|
||||
UnitCommitment.optimize!(model)
|
||||
@test UnitCommitment.validate(instance, solution)
|
||||
end
|
||||
17
test/model/formulations_test.jl
Normal file
17
test/model/formulations_test.jl
Normal file
@@ -0,0 +1,17 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using UnitCommitment
|
||||
|
||||
function _test(formulation::UnitCommitment.Formulation)::Nothing
|
||||
instance = UnitCommitment.read_benchmark("matpower/case118/2017-02-01")
|
||||
UnitCommitment._build_model(instance, formulation) # should not crash
|
||||
return
|
||||
end
|
||||
|
||||
@testset "formulations" begin
|
||||
_test(UnitCommitment.Formulation(ramping = UnitCommitment.ArrCon00()))
|
||||
_test(UnitCommitment.Formulation(ramping = UnitCommitment.DamKucRajAta16()))
|
||||
_test(UnitCommitment.Formulation(ramping = UnitCommitment.MorLatRam13()))
|
||||
end
|
||||
Reference in New Issue
Block a user