From bc3aee38f81d9a2221de46972852fca1d4014606 Mon Sep 17 00:00:00 2001 From: Jun He Date: Wed, 8 Mar 2023 13:35:33 -0500 Subject: [PATCH] modified the tests for LMP and AELMP --- test/Project.toml | 1 + test/fixtures/aelmp_simple.json.gz | Bin 0 -> 364 bytes test/fixtures/lmp_simple_test_1.json.gz | Bin 0 -> 374 bytes test/fixtures/lmp_simple_test_2.json.gz | Bin 0 -> 391 bytes test/fixtures/lmp_simple_test_3.json.gz | Bin 0 -> 435 bytes test/fixtures/lmp_simple_test_4.json.gz | Bin 0 -> 439 bytes test/lmp/aelmp_test.jl | 39 +++++++++++++++++ test/lmp/lmp_test.jl | 54 ++++++++++++++++++++++++ test/runtests.jl | 4 ++ 9 files changed, 98 insertions(+) create mode 100644 test/fixtures/aelmp_simple.json.gz create mode 100644 test/fixtures/lmp_simple_test_1.json.gz create mode 100644 test/fixtures/lmp_simple_test_2.json.gz create mode 100644 test/fixtures/lmp_simple_test_3.json.gz create mode 100644 test/fixtures/lmp_simple_test_4.json.gz create mode 100644 test/lmp/aelmp_test.jl create mode 100644 test/lmp/lmp_test.jl 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 0000000000000000000000000000000000000000..aaa932592338f32fe1fba42980433dd2b560458c GIT binary patch literal 364 zcmV-y0h9h8iwFo#?CW9x17T%sZE#<6X>D+9WiD!SZ*BnHl;2CkFc8Pz_g94CLxoO~ z#&*-ky@=popg2W*2yI}2H7WVw(9!?hBwe?)wcub+>%*1aeeW)pPtxrO*e6&JNeZf| zRKY#idY|{dS`QQ4IsVFd*%A=!`MAY5Hr3F?NGrX>gq#$7apK3dhHU}hBU zG@GH;xA#2>l7n!*bQN%#?1NRS*aPKM5-qyRU-k>yzHS=ZD{2Q8QsgGnc3O}Lr9o!o z7j0U9zzD?98SG37KmV6~)g&VbT{=R^oqOSU(kt<-iPWa_`D&j!q{``8g_hpZq zX-3u-0nw(BjqNH1bfwr(*-YCN%^7EfDS#=p!&(;`66IpUk7WmBN5|vsY+#Vz)>~($ zr%_2gk!f0U!F{HG0>KXCWkPvB8GH9H4=+HA{s=B}6MaAckvlB9>x1@&^@E{qNXqlDZ0riG|I+_p$HpJ$pMKBzgn| z91SWR-I1+}xY)DXF)3UiqNA&5c!(|;M^Z|~KBXXWdG6#Sl(fN`#GDDQq|_-pFGrcx z7+gN>mTvPPp&;>m<&V&PaMxU!{e&g70lNe<6sW++u!R|f=UoZDnQ7CCZ(GU2=EikN za;Xi;t$N2c#S0z!H1zd1{H&$N^aNiRP{!7KR(DumFR+3S-Iy5y_ktM)mGcygZGj6{ zQ;(?S232QaC(oH++;U=T<7acYpf4A4BSPS01he%w9%g^$VfwE;>|WJ3dR1QU2d$PEa0D3&GH`}89^o+LL%o2<^UZlHxHE+?bw UNqUm2L`Un&yx-V6i)0R9WB_5c6? literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f23d08a78edd166d8616a1be30c3fe491eecb99a GIT binary patch literal 391 zcmV;20eJo&iwFp&2J~V818i+@Uvp_~aBO8?bY*jNUotLgb8l_{-IF~}!!Qtr_x=hi zVhB>H9H4=+wM&IW5uz0gh`~(`YALoOe^5cy|IWEhjH`f{SlH})AN%g!vo}3Lk~^lE z01MhAS7d_`j6L9vD~W-G4$hMPKDyun$VzGcp(IIH$0%p9WGvJq6JbboJ^d7 z=<;z`;^s!NlBBaoe}wLW+vdv2Pgs^UU`Q|p37T0Iw=iY#c`U&Qg05VuwTyv-5lolgcsThp5A%QJVR)Sj&7=|B_#Z_o zF5|yYWwFC^<#YjL*?FuBreDFfLNtMUV1;E852b1)%r5U>1H?Q-MWh*I1xAWLcEA=bb%%*`Ecmie>drt(zs4R7>X8J$T`nR-o7WCRSTFW zxJCj|tgw*5Iarl36TLNS!kGyLu+t0LE_>A^ApyV zQDurXQSeNs$~Xp6E)__%c){+td)T%|!iTR5jvODu4+S%YgwjPx%L;5FGMuAVxowV* zTri>t%1w`u(hfN>+8UUGFR`eaQ3Ixg5vnQBg|hwLY|;c|e97v_PKzdwjm{%pYob9Bv+uR&K_P~**0&X-0kCCVApjdw0i-u+B_ dvS0i77ijN&)Ayg#-g002z610q^w*IG002^<%838~ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..cddf8afc412c21365f6778ddc64b232c90e8601e GIT binary patch literal 439 zcmV;o0Z9HIiwFqv2lQe918i+@Uvp_~aBO8?bY*jNUocRCt<3PP&zMYS%FPNiZk>fx6N^p z8%7jCnduQyx6(^Y9-qN)%!y z(dP>)i()!390dKkJ}ncRZ?UOmx`WQ;Ai9cb&>a`lxOvU^(iBUHDg|}Jy@!)^zpFhy hT>I$6wKq)stoKXrr>;HPc~z~={|lN1D~6E=005hs%+mk> literal 0 HcmV?d00001 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