forked from lanl-ansi/PowerModels.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.jl
175 lines (147 loc) · 8.44 KB
/
util.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
@testset "obbt with trilinear convex hull relaxation" begin
@testset "3-bus case" begin
result_ac = run_ac_opf("../test/data/matpower/case3.m", nlp_solver);
upper_bound = result_ac["objective"]
data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCLSPowerModel);
@test isapprox(stats["final_relaxation_objective"], 5901.96; atol=1e0)
@test isnan(stats["final_rel_gap_from_ub"])
@test stats["iteration_count"] == 5
data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver,
model_type = QCLSPowerModel,
upper_bound = upper_bound,
upper_bound_constraint = true,
rel_gap_tol = 1e-3);
@test isapprox(stats["final_rel_gap_from_ub"], 0; atol=1e0)
@test stats["iteration_count"] == 2
@test isapprox(stats["vm_range_final"], 0.0793; atol=1e0)
end
end
@testset "obbt with qc relaxation" begin
@testset "3-bus case" begin
result_ac = run_ac_opf("../test/data/matpower/case3.m", nlp_solver);
upper_bound = result_ac["objective"]
data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCRMPowerModel);
@test isapprox(stats["final_relaxation_objective"], 5900.04; atol=1e0)
@test isnan(stats["final_rel_gap_from_ub"])
@test stats["iteration_count"] == 5
data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver,
model_type = QCRMPowerModel,
upper_bound = upper_bound,
upper_bound_constraint = true,
rel_gap_tol = 1e-3);
@test isapprox(stats["final_rel_gap_from_ub"], 0; atol=1e0)
@test stats["iteration_count"] == 2
@test isapprox(stats["vm_range_final"], 0.148; atol=1e0)
end
@testset "3-bus linear case" begin
# tests with linear objective function
data = PowerModels.parse_file("../test/data/matpower/case3.m")
data["gen"]["1"]["cost"] = data["gen"]["1"]["cost"][2:3]
data["gen"]["2"]["cost"] = data["gen"]["2"]["cost"][2:3]
result_ac = run_ac_opf(data, nlp_solver);
upper_bound = result_ac["objective"]
data, stats = run_obbt_opf!(data, nlp_solver,
model_type=QCRMPowerModel,
upper_bound = upper_bound,
upper_bound_constraint = true);
@test isapprox(stats["final_relaxation_objective"], 982.216; atol=1e0)
@test isapprox(stats["final_rel_gap_from_ub"], 0.0; atol=1e-2)
@test stats["iteration_count"] == 4
end
end
@testset "opf with flow cuts" begin
@testset "ac 5-bus case" begin
result_base = run_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["vm"], result_cuts["solution"]["bus"][i]["vm"]; atol = 1e-7)
@test isapprox(result_base["solution"]["bus"][i]["va"], result_cuts["solution"]["bus"][i]["va"]; atol = 1e-7)
end
end
@testset "ac 14-bus case" begin
result_base = run_opf("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["vm"], result_cuts["solution"]["bus"][i]["vm"]; atol = 1e-8)
@test isapprox(result_base["solution"]["bus"][i]["va"], result_cuts["solution"]["bus"][i]["va"]; atol = 1e-8)
end
end
@testset "soc 5-bus case" begin
result_base = run_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["w"], result_cuts["solution"]["bus"][i]["w"]; atol = 1e-5)
end
end
@testset "soc 14-bus case" begin
result_base = run_opf("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["w"], result_cuts["solution"]["bus"][i]["w"]; atol = 1e-5)
end
end
@testset "dc 5-bus case" begin
result_base = run_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", DCPPowerModel, milp_solver)
@test result_base["termination_status"] == OPTIMAL
@test result_cuts["termination_status"] == OPTIMAL
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["va"], result_cuts["solution"]["bus"][i]["va"]; atol = 1e-8)
end
end
@testset "dc 14-bus case" begin
result_base = run_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver)
result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,bus) in result_base["solution"]["bus"]
@test isapprox(result_base["solution"]["bus"][i]["va"], result_cuts["solution"]["bus"][i]["va"]; atol = 1e-8)
end
end
end
@testset "ptdf opf with flow cuts" begin
@testset "dc 5-bus case" begin
result_base = run_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver)
result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case5.m", milp_solver)
@test result_base["termination_status"] == OPTIMAL
@test result_cuts["termination_status"] == OPTIMAL
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,gen) in result_base["solution"]["gen"]
@test isapprox(result_base["solution"]["gen"][i]["pg"], result_cuts["solution"]["gen"][i]["pg"]; atol = 1e-8)
end
end
@testset "dc 5-bus ext case" begin
result_base = run_opf("../test/data/matpower/case5_ext.m", DCPPowerModel, milp_solver)
result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case5_ext.m", milp_solver)
@test result_base["termination_status"] == OPTIMAL
@test result_cuts["termination_status"] == OPTIMAL
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,gen) in result_base["solution"]["gen"]
@test isapprox(result_base["solution"]["gen"][i]["pg"], result_cuts["solution"]["gen"][i]["pg"]; atol = 1e-8)
end
end
@testset "dc 14-bus case" begin
result_base = run_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver)
result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case14.m", nlp_solver)
@test result_base["termination_status"] == LOCALLY_SOLVED
@test result_cuts["termination_status"] == LOCALLY_SOLVED
@test isapprox(result_base["objective"], result_cuts["objective"])
for (i,gen) in result_base["solution"]["gen"]
@test isapprox(result_base["solution"]["gen"][i]["pg"], result_cuts["solution"]["gen"][i]["pg"]; atol = 1e-8)
end
end
end