forked from lanl-ansi/PowerModels.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tnep.jl
196 lines (144 loc) · 6.4 KB
/
tnep.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
function check_tnep_status(sol)
for (idx,val) in sol["ne_branch"]
@test isapprox(val["built"], 0.0, atol=1e-6, rtol=1e-6) || isapprox(val["built"], 1.0, atol=1e-6, rtol=1e-6)
end
end
# test that ne_branch solution information is a superset of regular branches
function check_ne_branch_keys(sol)
branch = collect(sol["branch"])[1].second
ne_brnach = collect(sol["ne_branch"])[1].second
@test all(haskey(ne_brnach, k) for k in keys(branch))
end
@testset "test ac tnep" begin
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, ACPPowerModel, minlp_solver)
check_tnep_status(result["solution"])
check_ne_branch_keys(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
end
@testset "5-bus case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", ACPPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end
@testset "test soc tnep" begin
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, SOCWRPowerModel, minlp_solver)
check_tnep_status(result["solution"])
check_ne_branch_keys(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
end
@testset "5-bus rts case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", SOCWRPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end
# requires a correct implementation of `variable_ne_branch_voltage`
# @testset "test qc tnep" begin
# @testset "3-bus case" begin
# data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
# calc_thermal_limits!(data)
# result = run_tnep(data, QCRMPowerModel, minlp_solver)
# check_tnep_status(result["solution"])
# check_ne_branch_keys(result["solution"])
# @test result["termination_status"] == LOCALLY_SOLVED
# @test isapprox(result["objective"], 2; atol = 1e-2)
# end
# @testset "5-bus rts case" begin
# result = run_tnep("../test/data/matpower/case5_tnep.m", QCRMPowerModel, minlp_solver)
# check_tnep_status(result["solution"])
# @test result["termination_status"] == LOCALLY_SOLVED
# @test isapprox(result["objective"], 1; atol = 1e-2)
# end
# end
@testset "test dc tnep" begin
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, DCPPowerModel, minlp_solver)
check_tnep_status(result["solution"])
check_ne_branch_keys(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
end
@testset "5-bus case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", DCPPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end
@testset "test matpower dc tnep" begin
@testset "5-bus case with matpower DCMP model and TNEP" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", DCMPPowerModel, minlp_solver)
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["solution"]["ne_branch"]["1"]["built"], 1.0; atol = 1e-5)
@test isapprox(result["solution"]["ne_branch"]["2"]["built"], 0.0; atol = 1e-5)
end
end
@testset "test dc-losses tnep" begin
#=
# turn off due to numerical stability across operating systems
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, DCPLLPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
end
=#
@testset "5-bus case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", DCPLLPowerModel, minlp_solver)
check_tnep_status(result["solution"])
check_ne_branch_keys(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end
@testset "test lpac tnep" begin
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, LPACCPowerModel, minlp_solver)
check_tnep_status(result["solution"])
check_ne_branch_keys(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
end
@testset "5-bus case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", LPACCPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end
@testset "test tnep branch flow output" begin
@testset "3-bus case" begin
data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m")
calc_thermal_limits!(data)
result = run_tnep(data, SOCWRPowerModel, minlp_solver)
check_tnep_status(result["solution"])
@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 2; atol = 1e-2)
branches = result["solution"]["branch"]
ne_branches = result["solution"]["ne_branch"]
flow_keys = ["pf","qf","pt","qt"]
for fk in flow_keys
@test !isnan(branches["1"][fk])
@test !isnan(ne_branches["1"][fk])
@test !isnan(ne_branches["2"][fk])
@test !isnan(ne_branches["3"][fk])
end
end
end