Skip to content

Commit fd82229

Browse files
kersulisccoffrin
authored andcommitted
#30, fix Julia 0.5 warnings (#31)
* fix warnings #30, replace [...=>...for...] with Dict(...=>...for...), replace readall with readstring, replace symbol with Symbol
1 parent e2da539 commit fd82229

File tree

9 files changed

+75
-84
lines changed

9 files changed

+75
-84
lines changed

REQUIRE

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ julia 0.4.6
22
JSON
33
MathProgBase 0.5.4
44
JuMP 0.14.0
5+
Compat

src/PowerModels.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module PowerModels
55
using JSON
66
using MathProgBase
77
using JuMP
8+
using Compat
89

910
include("io/matpower.jl")
1011
include("io/json.jl")
@@ -27,4 +28,4 @@ include("prob/opf.jl")
2728
include("prob/ots.jl")
2829
include("prob/misc.jl")
2930

30-
end
31+
end

src/core/base.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ function run_generic_model(file, model_constructor, solver, post_method; solutio
102102
end
103103

104104
function build_sets(data::Dict{AbstractString,Any})
105-
bus_lookup = [ Int(bus["index"]) => bus for bus in data["bus"] ]
106-
gen_lookup = [ Int(gen["index"]) => gen for gen in data["gen"] ]
105+
bus_lookup = Dict([(Int(bus["index"]), bus) for bus in data["bus"]])
106+
gen_lookup = Dict([(Int(gen["index"]), gen) for gen in data["gen"]])
107107
for gencost in data["gencost"]
108108
i = Int(gencost["index"])
109109
gen_lookup[i] = merge(gen_lookup[i], gencost)
110110
end
111-
branch_lookup = [ Int(branch["index"]) => branch for branch in data["branch"] ]
111+
branch_lookup = Dict([(Int(branch["index"]), branch) for branch in data["branch"]])
112112

113113
# filter turned off stuff
114114
bus_lookup = filter((i, bus) -> bus["bus_type"] != 4, bus_lookup)
@@ -119,12 +119,12 @@ function build_sets(data::Dict{AbstractString,Any})
119119
arcs_to = [(i,branch["t_bus"],branch["f_bus"]) for (i,branch) in branch_lookup]
120120
arcs = [arcs_from; arcs_to]
121121

122-
bus_gens = [i => [] for (i,bus) in bus_lookup]
122+
bus_gens = Dict([(i, []) for (i,bus) in bus_lookup])
123123
for (i,gen) in gen_lookup
124124
push!(bus_gens[gen["gen_bus"]], i)
125125
end
126126

127-
bus_branches = [i => [] for (i,bus) in bus_lookup]
127+
bus_branches = Dict([(i, []) for (i,bus) in bus_lookup])
128128
for (l,i,j) in arcs_from
129129
push!(bus_branches[i], (l,i,j))
130130
push!(bus_branches[j], (l,j,i))
@@ -152,9 +152,9 @@ end
152152

153153
# compute bus pair level structures
154154
function buspair_parameters(buspair_indexes, branches, buses)
155-
bp_angmin = [bp => -Inf for bp in buspair_indexes]
156-
bp_angmax = [bp => Inf for bp in buspair_indexes]
157-
bp_line = [bp => Inf for bp in buspair_indexes]
155+
bp_angmin = Dict([(bp, -Inf) for bp in buspair_indexes])
156+
bp_angmax = Dict([(bp, Inf) for bp in buspair_indexes])
157+
bp_line = Dict([(bp, Inf) for bp in buspair_indexes])
158158

159159
for (l,branch) in branches
160160
i = branch["f_bus"]
@@ -165,7 +165,7 @@ function buspair_parameters(buspair_indexes, branches, buses)
165165
bp_line[(i,j)] = min(bp_line[(i,j)], l)
166166
end
167167

168-
buspairs = [(i,j) => Dict(
168+
buspairs = Dict([((i,j), Dict(
169169
"line"=>bp_line[(i,j)],
170170
"angmin"=>bp_angmin[(i,j)],
171171
"angmax"=>bp_angmax[(i,j)],
@@ -175,7 +175,7 @@ function buspair_parameters(buspair_indexes, branches, buses)
175175
"v_from_max"=>buses[i]["vmax"],
176176
"v_to_min"=>buses[j]["vmin"],
177177
"v_to_max"=>buses[j]["vmax"]
178-
) for (i,j) in buspair_indexes]
178+
)) for (i,j) in buspair_indexes])
179179
return buspairs
180180
end
181181

src/core/solution.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function build_solution{T}(pm::GenericPowerModel{T}, status, solve_time; objecti
33

44
if status != :Error
55
objective = getobjectivevalue(pm.model)
6-
status = solver_status_dict(symbol(typeof(pm.model.solver).name.module), status)
6+
status = solver_status_dict(Symbol(typeof(pm.model.solver).name.module), status)
77
end
88

99
solution = Dict{AbstractString,Any}(

src/core/variable.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function compute_voltage_product_bounds{T}(pm::GenericPowerModel{T})
9393
buspairs = pm.set.buspairs
9494
buspair_indexes = pm.set.buspair_indexes
9595

96-
wr_min = [bp => -Inf for bp in buspair_indexes]
97-
wr_max = [bp => Inf for bp in buspair_indexes]
98-
wi_min = [bp => -Inf for bp in buspair_indexes]
99-
wi_max = [bp => Inf for bp in buspair_indexes]
96+
wr_min = Dict([(bp, -Inf) for bp in buspair_indexes])
97+
wr_max = Dict([(bp, Inf) for bp in buspair_indexes])
98+
wi_min = Dict([(bp, -Inf) for bp in buspair_indexes])
99+
wi_max = Dict([(bp, Inf) for bp in buspair_indexes])
100100

101101
for bp in buspair_indexes
102102
i,j = bp
@@ -140,7 +140,7 @@ end
140140
function variable_complex_voltage_product_on_off{T}(pm::GenericPowerModel{T})
141141
wr_min, wr_max, wi_min, wi_max = compute_voltage_product_bounds(pm)
142142

143-
bi_bp = [i => (b["f_bus"], b["t_bus"]) for (i,b) in pm.set.branches]
143+
bi_bp = Dict([(i, (b["f_bus"], b["t_bus"])) for (i,b) in pm.set.branches])
144144

145145
@variable(pm.model, min(0, wr_min[bi_bp[b]]) <= wr[b in pm.set.branch_indexes] <= max(0, wr_max[bi_bp[b]]), start = getstart(pm.set.buspairs, bi_bp[b], "wr_start", 1.0))
146146
@variable(pm.model, min(0, wi_min[bi_bp[b]]) <= wi[b in pm.set.branch_indexes] <= max(0, wi_max[bi_bp[b]]), start = getstart(pm.set.buspairs, bi_bp[b], "wr_start"))
@@ -152,7 +152,7 @@ function variable_complex_voltage_product_matrix{T}(pm::GenericPowerModel{T})
152152
wr_min, wr_max, wi_min, wi_max = compute_voltage_product_bounds(pm)
153153

154154
w_index = 1:length(pm.set.bus_indexes)
155-
lookup_w_index = [bi => i for (i,bi) in enumerate(pm.set.bus_indexes)]
155+
lookup_w_index = Dict([(bi, i) for (i,bi) in enumerate(pm.set.bus_indexes)])
156156

157157
@variable(pm.model, WR[1:length(pm.set.bus_indexes), 1:length(pm.set.bus_indexes)], Symmetric)
158158
@variable(pm.model, WI[1:length(pm.set.bus_indexes), 1:length(pm.set.bus_indexes)])
@@ -195,16 +195,16 @@ end
195195

196196
# Creates the voltage magnitude product variables
197197
function variable_voltage_magnitude_product{T}(pm::GenericPowerModel{T})
198-
vv_min = [bp => pm.set.buspairs[bp]["v_from_min"]*pm.set.buspairs[bp]["v_to_min"] for bp in pm.set.buspair_indexes]
199-
vv_max = [bp => pm.set.buspairs[bp]["v_from_max"]*pm.set.buspairs[bp]["v_to_max"] for bp in pm.set.buspair_indexes]
198+
vv_min = Dict([(bp, pm.set.buspairs[bp]["v_from_min"]*pm.set.buspairs[bp]["v_to_min"]) for bp in pm.set.buspair_indexes])
199+
vv_max = Dict([(bp, pm.set.buspairs[bp]["v_from_max"]*pm.set.buspairs[bp]["v_to_max"]) for bp in pm.set.buspair_indexes])
200200

201201
@variable(pm.model, vv_min[bp] <= vv[bp in pm.set.buspair_indexes] <= vv_max[bp], start = getstart(pm.set.buspairs, bp, "vv_start", 1.0))
202202
return vv
203203
end
204204

205205
function variable_cosine{T}(pm::GenericPowerModel{T})
206-
cos_min = [bp => -Inf for bp in pm.set.buspair_indexes]
207-
cos_max = [bp => Inf for bp in pm.set.buspair_indexes]
206+
cos_min = Dict([(bp, -Inf) for bp in pm.set.buspair_indexes])
207+
cos_max = Dict([(bp, Inf) for bp in pm.set.buspair_indexes])
208208

209209
for bp in pm.set.buspair_indexes
210210
buspair = pm.set.buspairs[bp]
@@ -233,8 +233,8 @@ end
233233

234234
function variable_current_magnitude_sqr{T}(pm::GenericPowerModel{T})
235235
buspairs = pm.set.buspairs
236-
cm_min = [bp => 0 for bp in pm.set.buspair_indexes]
237-
cm_max = [bp => (buspairs[bp]["rate_a"]*buspairs[bp]["tap"]/buspairs[bp]["v_from_min"])^2 for bp in pm.set.buspair_indexes]
236+
cm_min = Dict([(bp, 0) for bp in pm.set.buspair_indexes])
237+
cm_max = Dict([(bp, (buspairs[bp]["rate_a"]*buspairs[bp]["tap"]/buspairs[bp]["v_from_min"])^2) for bp in pm.set.buspair_indexes])
238238

239239
@variable(pm.model, cm_min[bp] <= cm[bp in pm.set.buspair_indexes] <= cm_max[bp], start = getstart(pm.set.buspairs, bp, "cm_start"))
240240
return cm

src/form/dcp.jl

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export
1+
export
22
DCPPowerModel, StandardDCPForm,
33
DCPLLPowerModel, StandardDCPLLForm
44

@@ -32,8 +32,8 @@ function variable_active_line_flow{T <: StandardDCPForm}(pm::GenericPowerModel{T
3232
@variable(pm.model, p[(l,i,j) in pm.set.arcs_from], start = getstart(pm.set.branches, l, "p_start"))
3333
end
3434

35-
p_expr = [(l,i,j) => 1.0*p[(l,i,j)] for (l,i,j) in pm.set.arcs_from]
36-
p_expr = merge(p_expr, [(l,j,i) => -1.0*p[(l,i,j)] for (l,i,j) in pm.set.arcs_from])
35+
p_expr = Dict([((l,i,j), 1.0*p[(l,i,j)]) for (l,i,j) in pm.set.arcs_from])
36+
p_expr = merge(p_expr, Dict([((l,j,i), -1.0*p[(l,i,j)]) for (l,i,j) in pm.set.arcs_from]))
3737

3838
pm.model.ext[:p_expr] = p_expr
3939
end
@@ -112,7 +112,7 @@ function constraint_phase_angle_difference{T <: AbstractDCPForm}(pm::GenericPowe
112112
return Set([c1, c2])
113113
end
114114

115-
function constraint_thermal_limit_from{T <: AbstractDCPForm}(pm::GenericPowerModel{T}, branch)
115+
function constraint_thermal_limit_from{T <: AbstractDCPForm}(pm::GenericPowerModel{T}, branch)
116116
i = branch["index"]
117117
f_bus = branch["f_bus"]
118118
t_bus = branch["t_bus"]
@@ -132,7 +132,7 @@ function constraint_thermal_limit_from{T <: AbstractDCPForm}(pm::GenericPowerMod
132132
return Set()
133133
end
134134

135-
function constraint_thermal_limit_to{T <: AbstractDCPForm}(pm::GenericPowerModel{T}, branch)
135+
function constraint_thermal_limit_to{T <: AbstractDCPForm}(pm::GenericPowerModel{T}, branch)
136136
# nothing to do, from handles both sides
137137
return Set()
138138
end
@@ -296,7 +296,3 @@ function constraint_thermal_limit_to_on_off{T <: AbstractDCPLLForm}(pm::GenericP
296296
c2 = @constraint(pm.model, p_to >= getlowerbound(p_to)*z)
297297
return Set([c1, c2])
298298
end
299-
300-
301-
302-

src/form/wr.jl

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export
1+
export
22
SOCWRPowerModel, SOCWRForm,
33
QCWRPowerModel, QCWRForm
44

@@ -21,7 +21,7 @@ function constraint_complex_voltage{T <: AbstractWRForm}(pm::GenericPowerModel{T
2121
w = getvariable(pm.model, :w)
2222
wr = getvariable(pm.model, :wr)
2323
wi = getvariable(pm.model, :wi)
24-
24+
2525
for (i,j) in pm.set.buspair_indexes
2626
relaxation_complex_product(pm.model, w[i], w[j], wr[(i,j)], wi[(i,j)])
2727
end
@@ -93,7 +93,7 @@ function constraint_active_ohms_yt{T <: AbstractWRForm}(pm::GenericPowerModel{T}
9393
c = branch["br_b"]
9494
tr = branch["tr"]
9595
ti = branch["ti"]
96-
tm = tr^2 + ti^2
96+
tm = tr^2 + ti^2
9797

9898
c1 = @constraint(pm.model, p_fr == g/tm*w_fr + (-g*tr+b*ti)/tm*(wr) + (-b*tr-g*ti)/tm*( wi) )
9999
c2 = @constraint(pm.model, p_to == g*w_to + (-g*tr-b*ti)/tm*(wr) + (-b*tr+g*ti)/tm*(-wi) )
@@ -119,7 +119,7 @@ function constraint_reactive_ohms_yt{T <: AbstractWRForm}(pm::GenericPowerModel{
119119
c = branch["br_b"]
120120
tr = branch["tr"]
121121
ti = branch["ti"]
122-
tm = tr^2 + ti^2
122+
tm = tr^2 + ti^2
123123

124124
c1 = @constraint(pm.model, q_fr == -(b+c/2)/tm*w_fr - (-b*tr-g*ti)/tm*(wr) + (-g*tr+b*ti)/tm*( wi) )
125125
c2 = @constraint(pm.model, q_to == -(b+c/2)*w_to - (-b*tr+g*ti)/tm*(wr) + (-g*tr-b*ti)/tm*(-wi) )
@@ -168,7 +168,7 @@ function constraint_complex_voltage_on_off{T <: AbstractWRForm}(pm::GenericPower
168168
wr = getvariable(pm.model, :wr)
169169
wi = getvariable(pm.model, :wi)
170170
z = getvariable(pm.model, :line_z)
171-
171+
172172
w_from = getvariable(pm.model, :w_from)
173173
w_to = getvariable(pm.model, :w_to)
174174

@@ -226,7 +226,7 @@ end
226226
function constraint_complex_voltage_product_on_off{T}(pm::GenericPowerModel{T})
227227
wr_min, wr_max, wi_min, wi_max = compute_voltage_product_bounds(pm)
228228

229-
bi_bp = [i => (b["f_bus"], b["t_bus"]) for (i,b) in pm.set.branches]
229+
bi_bp = Dict([(i, (b["f_bus"], b["t_bus"])) for (i,b) in pm.set.branches])
230230

231231
wr = getvariable(pm.model, :wr)
232232
wi = getvariable(pm.model, :wi)
@@ -266,7 +266,7 @@ function constraint_active_ohms_yt_on_off{T <: AbstractWRForm}(pm::GenericPowerM
266266
c = branch["br_b"]
267267
tr = branch["tr"]
268268
ti = branch["ti"]
269-
tm = tr^2 + ti^2
269+
tm = tr^2 + ti^2
270270

271271
c1 = @constraint(pm.model, p_fr == g/tm*w_fr + (-g*tr+b*ti)/tm*(wr) + (-b*tr-g*ti)/tm*( wi) )
272272
c2 = @constraint(pm.model, p_to == g*w_to + (-g*tr-b*ti)/tm*(wr) + (-b*tr+g*ti)/tm*(-wi) )
@@ -292,7 +292,7 @@ function constraint_reactive_ohms_yt_on_off{T <: AbstractWRForm}(pm::GenericPowe
292292
c = branch["br_b"]
293293
tr = branch["tr"]
294294
ti = branch["ti"]
295-
tm = tr^2 + ti^2
295+
tm = tr^2 + ti^2
296296

297297
c1 = @constraint(pm.model, q_fr == -(b+c/2)/tm*w_fr - (-b*tr-g*ti)/tm*(wr) + (-g*tr+b*ti)/tm*( wi) )
298298
c2 = @constraint(pm.model, q_to == -(b+c/2)*w_to - (-b*tr+g*ti)/tm*(wr) + (-g*tr-b*ti)/tm*(-wi) )
@@ -346,11 +346,11 @@ function constraint_complex_voltage(pm::QCWRPowerModel)
346346
si = getvariable(pm.model, :si)
347347
cs = getvariable(pm.model, :cs)
348348
vv = getvariable(pm.model, :vv)
349-
349+
350350
w = getvariable(pm.model, :w)
351351
wr = getvariable(pm.model, :wr)
352352
wi = getvariable(pm.model, :wi)
353-
353+
354354
const_set = Set()
355355
for (i,b) in pm.set.buses
356356
cs1 = relaxation_sqr(pm.model, v[i], w[i])
@@ -403,7 +403,7 @@ function constraint_power_magnitude_sqr(pm::QCWRPowerModel, branch)
403403

404404
tr = branch["tr"]
405405
ti = branch["ti"]
406-
tm = tr^2 + ti^2
406+
tm = tr^2 + ti^2
407407

408408
c = @constraint(pm.model, p_fr^2 + q_fr^2 <= w_i/tm*cm)
409409
return Set([c])
@@ -428,7 +428,7 @@ function constraint_power_magnitude_link(pm::QCWRPowerModel, branch)
428428
c = branch["br_b"]
429429
tr = branch["tr"]
430430
ti = branch["ti"]
431-
tm = tr^2 + ti^2
431+
tm = tr^2 + ti^2
432432

433433
c = @constraint(pm.model, cm == (g^2 + b^2)*(w_fr/tm + w_to - 2*(tr*wr + ti*wi)/tm) - c*q_fr - ((c/2)/tm)^2*w_fr)
434434
return Set([c])
@@ -472,8 +472,3 @@ function add_bus_voltage_setpoint(sol, pm::QCWRPowerModel)
472472
add_setpoint(sol, pm, "bus", "bus_i", "vm", :v)
473473
add_setpoint(sol, pm, "bus", "bus_i", "va", :t)
474474
end
475-
476-
477-
478-
479-

src/io/json.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
function parse_json(file_string)
3-
data_string = readall(open(file_string))
3+
data_string = readstring(open(file_string))
44
return JSON.parse(data_string, dicttype = Dict{AbstractString,Any})
5-
end
5+
end

0 commit comments

Comments
 (0)