diff --git a/test/Project.toml b/test/Project.toml index b87293d..5a175be 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,6 +3,7 @@ Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63" +HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/test/fixtures/aelmp_simple.json.gz b/test/fixtures/aelmp_simple.json.gz new file mode 100644 index 0000000..aaa9325 Binary files /dev/null and b/test/fixtures/aelmp_simple.json.gz differ diff --git a/test/fixtures/lmp_simple_test_1.json.gz b/test/fixtures/lmp_simple_test_1.json.gz new file mode 100644 index 0000000..5ec9a7f Binary files /dev/null and b/test/fixtures/lmp_simple_test_1.json.gz differ diff --git a/test/fixtures/lmp_simple_test_2.json.gz b/test/fixtures/lmp_simple_test_2.json.gz new file mode 100644 index 0000000..f23d08a Binary files /dev/null and b/test/fixtures/lmp_simple_test_2.json.gz differ diff --git a/test/fixtures/lmp_simple_test_3.json.gz b/test/fixtures/lmp_simple_test_3.json.gz new file mode 100644 index 0000000..5cb48f4 Binary files /dev/null and b/test/fixtures/lmp_simple_test_3.json.gz differ diff --git a/test/fixtures/lmp_simple_test_4.json.gz b/test/fixtures/lmp_simple_test_4.json.gz new file mode 100644 index 0000000..cddf8af Binary files /dev/null and b/test/fixtures/lmp_simple_test_4.json.gz differ diff --git a/test/lmp/aelmp_test.jl b/test/lmp/aelmp_test.jl new file mode 100644 index 0000000..cfa80ba --- /dev/null +++ b/test/lmp/aelmp_test.jl @@ -0,0 +1,39 @@ +# 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, Cbc, HiGHS, JuMP +import UnitCommitment: + AELMP + +@testset "aelmp" begin + path = "$FIXTURES/aelmp_simple.json.gz" + # model has to be solved first + instance = UnitCommitment.read(path) + model = UnitCommitment.build_model( + instance=instance, + optimizer=Cbc.Optimizer, + variable_names = true, + ) + JuMP.set_silent(model) + UnitCommitment.optimize!(model) + + # policy 1: allow offlines; consider startups + aelmp_1 = UnitCommitment.compute_lmp( + model, + AELMP.Method(), + optimizer=HiGHS.Optimizer + ) + @test aelmp_1["B1", 1] ≈ 231.7 atol = 0.1 + + # policy 2: do not allow offlines; but consider startups + aelmp_2 = UnitCommitment.compute_lmp( + model, + AELMP.Method( + allow_offline_participation=false, + consider_startup_costs=true + ), + optimizer=HiGHS.Optimizer + ) + @test aelmp_2["B1", 1] ≈ 274.3 atol = 0.1 +end \ No newline at end of file diff --git a/test/lmp/lmp_test.jl b/test/lmp/lmp_test.jl new file mode 100644 index 0000000..e219501 --- /dev/null +++ b/test/lmp/lmp_test.jl @@ -0,0 +1,54 @@ +# 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, Cbc, HiGHS, JuMP +import UnitCommitment: + LMP + +function solve_lmp_testcase(path::String) + instance = UnitCommitment.read(path) + model = UnitCommitment.build_model( + instance = instance, + optimizer = Cbc.Optimizer, + variable_names = true, + ) + # set silent, solve the UC + JuMP.set_silent(model) + UnitCommitment.optimize!(model) + # get the lmp + lmp = UnitCommitment.compute_lmp( + model, + LMP.Method(), + optimizer=HiGHS.Optimizer, + ) + return lmp +end + +@testset "lmp" begin + # instance 1 + path = "$FIXTURES/lmp_simple_test_1.json.gz" + lmp = solve_lmp_testcase(path) + @test lmp["A", 1] == 50.0 + @test lmp["B", 1] == 50.0 + + # instance 2 + path = "$FIXTURES/lmp_simple_test_2.json.gz" + lmp = solve_lmp_testcase(path) + @test lmp["A", 1] == 50.0 + @test lmp["B", 1] == 60.0 + + # instance 3 + path = "$FIXTURES/lmp_simple_test_3.json.gz" + lmp = solve_lmp_testcase(path) + @test lmp["A", 1] == 50.0 + @test lmp["B", 1] == 70.0 + @test lmp["C", 1] == 100.0 + + # instance 4 + path = "$FIXTURES/lmp_simple_test_4.json.gz" + lmp = solve_lmp_testcase(path) + @test lmp["A", 1] == 50.0 + @test lmp["B", 1] == 70.0 + @test lmp["C", 1] == 90.0 +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 9a61bf2..4203495 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,4 +39,8 @@ FIXTURES = "$(@__DIR__)/fixtures" @testset "validation" begin include("validation/repair_test.jl") end + @testset "lmp" begin + include("lmp/lmp_test.jl") + include("lmp/aelmp_test.jl") + end end