forked from lanl-ansi/PowerModels.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matpower.jl
157 lines (127 loc) · 5.84 KB
/
matpower.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
using JSON
@testset "test matpower parser" begin
@testset "30-bus case file" begin
result = run_opf("../test/data/case30.m", ACPPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 204.96; atol = 1e-1)
end
@testset "30-bus case matpower data" begin
data = PowerModels.parse_file("../test/data/case30.m")
@test isa(JSON.json(data), String)
result = run_opf(data, ACPPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 204.96; atol = 1e-1)
end
@testset "14-bus case file with names" begin
data = PowerModels.parse_file("../test/data/case14.m")
@test data["bus"]["1"]["bus_name"] == "Bus 1 HV"
@test isa(JSON.json(data), String)
end
@testset "2-bus case file with spaces" begin
result = run_opf("../test/data/case2.m", ACPPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 184.70; atol = 1e-1)
end
end
@testset "test matpower data coercion" begin
@testset "ACP Model" begin
result = run_opf("../test/data/case14.m", ACPPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 8081.5; atol = 1e0)
#@test result["status"] = bus_name
end
@testset "DC Model" begin
result = run_opf("../test/data/case14.m", DCPPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 7642.6; atol = 1e0)
end
@testset "QC Model" begin
result = run_opf("../test/data/case14.m", QCWRPowerModel, ipopt_solver)
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 8075.1; atol = 1e0)
end
end
@testset "test matpower extentions parser" begin
@testset "3-bus extended constants" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test data["const_int"] == 123
@test data["const_float"] == 4.56
@test data["const_str"] == "a string"
@test isa(JSON.json(data), String)
end
@testset "3-bus extended matrix" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas")
@test data["areas"]["1"]["col_1"] == 1
@test data["areas"]["1"]["col_2"] == 1
@test data["areas"]["2"]["col_1"] == 2
@test data["areas"]["2"]["col_2"] == 3
@test isa(JSON.json(data), String)
end
@testset "3-bus extended named matrix" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas_named")
@test data["areas_named"]["1"]["area"] == 4
@test data["areas_named"]["1"]["refbus"] == 5
@test data["areas_named"]["2"]["area"] == 5
@test data["areas_named"]["2"]["refbus"] == 6
@test isa(JSON.json(data), String)
end
@testset "3-bus extended predefined matrix" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas_named")
@test data["branch"]["1"]["rate_i"] == 50.2
@test data["branch"]["1"]["rate_p"] == 45
@test data["branch"]["2"]["rate_i"] == 36
@test data["branch"]["2"]["rate_p"] == 60.1
@test data["branch"]["3"]["rate_i"] == 12
@test data["branch"]["3"]["rate_p"] == 30
@test isa(JSON.json(data), String)
end
@testset "3-bus extended matrix from cell" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas_cells")
@test data["areas_cells"]["1"]["col_1"] == "Area 1"
@test data["areas_cells"]["1"]["col_2"] == 123
@test data["areas_cells"]["1"]["col_4"] == "Slack 'Bus' 1"
@test data["areas_cells"]["1"]["col_5"] == 1.23
@test data["areas_cells"]["2"]["col_1"] == "Area 2"
@test data["areas_cells"]["2"]["col_2"] == 456
@test data["areas_cells"]["2"]["col_4"] == "Slack Bus 3"
@test data["areas_cells"]["2"]["col_5"] == 4.56
@test isa(JSON.json(data), String)
end
@testset "3-bus extended named matrix from cell" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas_named_cells")
@test data["areas_named_cells"]["1"]["area_name"] == "Area 1"
@test data["areas_named_cells"]["1"]["area"] == 123
@test data["areas_named_cells"]["1"]["area2"] == 987
@test data["areas_named_cells"]["1"]["refbus_name"] == "Slack Bus 1"
@test data["areas_named_cells"]["1"]["refbus"] == 1.23
@test data["areas_named_cells"]["2"]["area_name"] == "Area 2"
@test data["areas_named_cells"]["2"]["area"] == 456
@test data["areas_named_cells"]["2"]["area2"] == 987
@test data["areas_named_cells"]["2"]["refbus_name"] == "Slack Bus 3"
@test data["areas_named_cells"]["2"]["refbus"] == 4.56
@test isa(JSON.json(data), String)
end
@testset "3-bus extended predefined matrix from cell" begin
data = PowerModels.parse_file("../test/data/case3.m")
@test haskey(data, "areas_named")
@test data["branch"]["1"]["name"] == "Branch 1"
@test data["branch"]["1"]["number_id"] == 123
@test data["branch"]["2"]["name"] == "Branch 2"
@test data["branch"]["2"]["number_id"] == 456
@test data["branch"]["3"]["name"] == "Branch 3"
@test data["branch"]["3"]["number_id"] == 789
@test isa(JSON.json(data), String)
end
@testset "3-bus tnep case" begin
data = PowerModels.parse_file("../test/data/case3_tnep.m")
@test haskey(data, "ne_branch")
@test data["ne_branch"]["1"]["f_bus"] == 1
@test data["ne_branch"]["1"]["construction_cost"] == 1
@test isa(JSON.json(data), String)
end
end