Skip to content

Commit 15829a9

Browse files
authored
Updating syntax for Julia v0.5 and JuMP v0.15 (#57)
* adding Julia 0.5, JuMP 0.15, Pajarito 3.1 requirements * updating summation syntax * removing julia 0.4 from travis * removing Julia v0.6
1 parent ff95e40 commit 15829a9

File tree

10 files changed

+29
-33
lines changed

10 files changed

+29
-33
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.4
76
- 0.5
87
cache:
98
directories:

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
PowerModels.jl Change Log
22
=================
33

4+
### staged
5+
- Updated to JuMP v0.15 syntax
6+
47
### v0.2.3
58
- Multiple improvements to Matlab file parsing
69
- Added support matlab cell arrays

REQUIRE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
julia 0.4.6
1+
julia 0.5
22
JSON 0.6.0
33
MathProgBase 0.5.4
4-
JuMP 0.14 0.15-
4+
JuMP 0.15 0.16-
55
Compat 0.7.9

src/core/objective.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
function objective_min_fuel_cost{T}(pm::GenericPowerModel{T})
77
pg = getvariable(pm.model, :pg)
88
cost = (i) -> pm.set.gens[i]["cost"]
9-
return @objective(pm.model, Min, sum{ cost(i)[1]*pg[i]^2 + cost(i)[2]*pg[i] + cost(i)[3], i in pm.set.gen_indexes} )
9+
return @objective(pm.model, Min, sum(cost(i)[1]*pg[i]^2 + cost(i)[2]*pg[i] + cost(i)[3] for i in pm.set.gen_indexes) )
1010
end
1111

1212
function objective_min_fuel_cost{T <: AbstractConicPowerFormulation}(pm::GenericPowerModel{T})
@@ -19,12 +19,12 @@ function objective_min_fuel_cost{T <: AbstractConicPowerFormulation}(pm::Generic
1919
end
2020

2121
cost = (i) -> pm.set.gens[i]["cost"]
22-
return @objective(pm.model, Min, sum{ cost(i)[1]*pg_sqr[i] + cost(i)[2]*pg[i] + cost(i)[3], i in pm.set.gen_indexes} )
22+
return @objective(pm.model, Min, sum( cost(i)[1]*pg_sqr[i] + cost(i)[2]*pg[i] + cost(i)[3] for i in pm.set.gen_indexes) )
2323
end
2424

2525
### Cost of building lines
2626
function objective_tnep_cost{T}(pm::GenericPowerModel{T})
2727
line_ne = getvariable(pm.model, :line_ne)
2828
branches = pm.ext[:ne].branches
29-
return @objective(pm.model, Min, sum{ branches[i]["construction_cost"]*line_ne[i], (i,branch) in branches} )
29+
return @objective(pm.model, Min, sum( branches[i]["construction_cost"]*line_ne[i] for (i,branch) in branches) )
3030
end

src/form/acp.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function constraint_active_kcl_shunt{T <: AbstractACPForm}(pm::GenericPowerModel
6161
p = getvariable(pm.model, :p)
6262
pg = getvariable(pm.model, :pg)
6363

64-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*v[i]^2)
64+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*v[i]^2)
6565
return Set([c])
6666
end
6767

@@ -76,7 +76,7 @@ function constraint_active_kcl_shunt_ne{T <: AbstractACPForm}(pm::GenericPowerMo
7676
p_ne = getvariable(pm.model, :p_ne)
7777
pg = getvariable(pm.model, :pg)
7878

79-
c = @constraint(pm.model, sum{p[a], a in bus_branches} + sum{p_ne[a], a in bus_branches_ne} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*v[i]^2)
79+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) + sum(p_ne[a] for a in bus_branches_ne) == sum(pg[g], g in bus_gens) - bus["pd"] - bus["gs"]*v[i]^2)
8080
return Set([c])
8181
end
8282

@@ -90,7 +90,7 @@ function constraint_reactive_kcl_shunt{T <: AbstractACPForm}(pm::GenericPowerMod
9090
q = getvariable(pm.model, :q)
9191
qg = getvariable(pm.model, :qg)
9292

93-
c = @constraint(pm.model, sum{q[a], a in bus_branches} == sum{qg[g], g in bus_gens} - bus["qd"] + bus["bs"]*v[i]^2)
93+
c = @constraint(pm.model, sum(q[a] for a in bus_branches) == sum(qg[g] for g in bus_gens) - bus["qd"] + bus["bs"]*v[i]^2)
9494
return Set([c])
9595
end
9696

@@ -105,7 +105,7 @@ function constraint_reactive_kcl_shunt_ne{T <: AbstractACPForm}(pm::GenericPower
105105
q_ne = getvariable(pm.model, :q_ne)
106106
qg = getvariable(pm.model, :qg)
107107

108-
c = @constraint(pm.model, sum{q[a], a in bus_branches} + sum{q_ne[a], a in bus_branches_ne} == sum{qg[g], g in bus_gens} - bus["qd"] + bus["bs"]*v[i]^2)
108+
c = @constraint(pm.model, sum(q[a] for a in bus_branches) + sum(q_ne[a] for a in bus_branches_ne) == sum(qg[g] for g in bus_gens) - bus["qd"] + bus["bs"]*v[i]^2)
109109
return Set([c])
110110
end
111111

@@ -409,7 +409,7 @@ function objective_max_loading_voltage_norm{T}(pm::GenericPowerModel{T})
409409
scale = length(pm.set.buses)
410410
v = getvariable(pm.model, :v)
411411

412-
return @objective(pm.model, Max, 10*scale*load_factor - sum{ ((bus["vmin"] + bus["vmax"])/2 - v[i])^2, (i,bus) in pm.set.buses })
412+
return @objective(pm.model, Max, 10*scale*load_factor - sum(((bus["vmin"] + bus["vmax"])/2 - v[i])^2 for (i,bus) in pm.set.buses ))
413413
end
414414

415415
# Works but adds unnessiary runtime
@@ -420,7 +420,7 @@ function objective_max_loading_gen_output{T}(pm::GenericPowerModel{T})
420420
pg = getvariable(pm.model, :pg)
421421
qg = getvariable(pm.model, :qg)
422422

423-
return @NLobjective(pm.model, Max, 100*scale*load_factor - sum{ (pg[i]^2 - (2*qg[i])^2)^2, (i,gen) in pm.set.gens })
423+
return @NLobjective(pm.model, Max, 100*scale*load_factor - sum( (pg[i]^2 - (2*qg[i])^2)^2 for (i,gen) in pm.set.gens ))
424424
end
425425

426426

@@ -453,10 +453,10 @@ function constraint_active_kcl_shunt_scaled(pm::APIACPPowerModel, bus)
453453
pg = getvariable(pm.model, :pg)
454454

455455
if bus["pd"] > 0 && bus["qd"] > 0
456-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"]*load_factor - bus["gs"]*v[i]^2)
456+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"]*load_factor - bus["gs"]*v[i]^2)
457457
else
458458
# super fallback impl
459-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*v[i]^2)
459+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*v[i]^2)
460460
end
461461

462462
return Set([c])

src/form/dcp.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function constraint_active_kcl_shunt{T <: AbstractDCPForm}(pm::GenericPowerModel
8888
pg = getvariable(pm.model, :pg)
8989
p_expr = pm.model.ext[:p_expr]
9090

91-
c = @constraint(pm.model, sum{p_expr[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*1.0^2)
91+
c = @constraint(pm.model, sum(p_expr[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*1.0^2)
9292
return Set([c])
9393
end
9494

@@ -102,7 +102,7 @@ function constraint_active_kcl_shunt_ne{T <: AbstractDCPForm}(pm::GenericPowerMo
102102
p_expr = pm.model.ext[:p_expr]
103103
p_ne_expr = pm.model.ext[:p_ne_expr]
104104

105-
c = @constraint(pm.model, sum{p_expr[a], a in bus_branches} + sum{p_ne_expr[a], a in bus_branches_ne} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*1.0^2)
105+
c = @constraint(pm.model, sum(p_expr[a] for a in bus_branches) + sum(p_ne_expr[a] for a in bus_branches_ne) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*1.0^2)
106106
return Set([c])
107107
end
108108

@@ -358,7 +358,7 @@ function constraint_active_kcl_shunt{T <: AbstractDCPLLForm}(pm::GenericPowerMod
358358
pg = getvariable(pm.model, :pg)
359359
p = getvariable(pm.model, :p)
360360

361-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*1.0^2)
361+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*1.0^2)
362362
return Set([c])
363363
end
364364

@@ -372,7 +372,7 @@ function constraint_active_kcl_shunt_ne{T <: AbstractDCPLLForm}(pm::GenericPower
372372
p_ne = getvariable(pm.model, :p_ne)
373373
pg = getvariable(pm.model, :pg)
374374

375-
c = @constraint(pm.model, sum{p[a], a in bus_branches} + sum{p_ne[a], a in bus_branches_ne} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*1.0^2)
375+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) + sum(p_ne[a] for a in bus_branches_ne) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*1.0^2)
376376
return Set([c])
377377
end
378378

src/form/wr.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function constraint_active_kcl_shunt{T <: AbstractWRForm}(pm::GenericPowerModel{
5656
p = getvariable(pm.model, :p)
5757
pg = getvariable(pm.model, :pg)
5858

59-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*w[i])
59+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*w[i])
6060
return Set([c])
6161
end
6262

@@ -71,7 +71,7 @@ function constraint_active_kcl_shunt_ne{T <: AbstractWRForm}(pm::GenericPowerMod
7171
p_ne = getvariable(pm.model, :p_ne)
7272
pg = getvariable(pm.model, :pg)
7373

74-
c = @constraint(pm.model, sum{p[a], a in bus_branches} + sum{p_ne[a], a in bus_branches_ne} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*w[i])
74+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) + sum(p_ne[a] for a in bus_branches_ne) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*w[i])
7575
return Set([c])
7676
end
7777

@@ -84,7 +84,7 @@ function constraint_reactive_kcl_shunt{T <: AbstractWRForm}(pm::GenericPowerMode
8484
q = getvariable(pm.model, :q)
8585
qg = getvariable(pm.model, :qg)
8686

87-
c = @constraint(pm.model, sum{q[a], a in bus_branches} == sum{qg[g], g in bus_gens} - bus["qd"] + bus["bs"]*w[i])
87+
c = @constraint(pm.model, sum(q[a] for a in bus_branches) == sum(qg[g] for g in bus_gens) - bus["qd"] + bus["bs"]*w[i])
8888
return Set([c])
8989
end
9090

@@ -99,7 +99,7 @@ function constraint_reactive_kcl_shunt_ne{T <: AbstractWRForm}(pm::GenericPowerM
9999
q_ne = getvariable(pm.model, :q_ne)
100100
qg = getvariable(pm.model, :qg)
101101

102-
c = @constraint(pm.model, sum{q[a], a in bus_branches} + sum{q_ne[a], a in bus_branches_ne} == sum{qg[g], g in bus_gens} - bus["qd"] + bus["bs"]*w[i])
102+
c = @constraint(pm.model, sum(q[a] for a in bus_branches) + sum(q_ne[a] for a in bus_branches_ne) == sum(qg[g] for g in bus_gens) - bus["qd"] + bus["bs"]*w[i])
103103
return Set([c])
104104
end
105105

src/form/wrm.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function constraint_active_kcl_shunt{T <: AbstractWRMForm}(pm::GenericPowerModel
4444
p = getvariable(pm.model, :p)
4545
pg = getvariable(pm.model, :pg)
4646

47-
c = @constraint(pm.model, sum{p[a], a in bus_branches} == sum{pg[g], g in bus_gens} - bus["pd"] - bus["gs"]*w_i)
47+
c = @constraint(pm.model, sum(p[a] for a in bus_branches) == sum(pg[g] for g in bus_gens) - bus["pd"] - bus["gs"]*w_i)
4848
return Set([c])
4949
end
5050

@@ -60,7 +60,7 @@ function constraint_reactive_kcl_shunt{T <: AbstractWRMForm}(pm::GenericPowerMod
6060
q = getvariable(pm.model, :q)
6161
qg = getvariable(pm.model, :qg)
6262

63-
c = @constraint(pm.model, sum{q[a], a in bus_branches} == sum{qg[g], g in bus_gens} - bus["qd"] + bus["bs"]*w_i)
63+
c = @constraint(pm.model, sum(q[a] for a in bus_branches) == sum(qg[g] for g in bus_gens) - bus["qd"] + bus["bs"]*w_i)
6464
return Set([c])
6565
end
6666

test/REQUIRE

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
julia 0.4.6
1+
julia 0.5
22

33
Ipopt
44
SCS
55
GLPKMathProgInterface
6-
Pajarito 0.2.1
6+
Pajarito 0.3.1
77

8-
BaseTestNext 0.2.2
98
Logging 0.3.1

test/runtests.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ if (Pkg.installed("AmplNLWriter") != nothing && Pkg.installed("CoinOptServices")
1414
using CoinOptServices
1515
end
1616

17-
if VERSION >= v"0.5.0-dev+7720"
18-
using Base.Test
19-
else
20-
using BaseTestNext
21-
const Test = BaseTestNext
22-
end
17+
using Base.Test
2318

2419
# default setup for solvers
2520
ipopt_solver = IpoptSolver(tol=1e-6, print_level=0)

0 commit comments

Comments
 (0)