1
- """
2
- Checks if any generator cost model will require a JuMP nonlinear expression
3
- """
4
- function check_nl_gen_cost_models (pm:: AbstractPowerModel )
5
- for (n, nw_ref) in nws (pm)
6
- for (i,gen) in nw_ref[:gen ]
7
- if haskey (gen, " cost" )
8
- if gen[" model" ] == 2 && length (gen[" cost" ]) > 3
9
- return true
10
- end
11
- end
12
- end
13
- end
14
- return false
15
- end
16
-
17
- """
18
- Checks if any dcline cost model will require a JuMP nonlinear expression
19
- """
20
- function check_nl_dcline_cost_models (pm:: AbstractPowerModel )
21
- for (n, nw_ref) in nws (pm)
22
- for (i,dcline) in nw_ref[:dcline ]
23
- if haskey (dcline, " cost" )
24
- if dcline[" model" ] == 2 && length (dcline[" cost" ]) > 3
25
- return true
26
- end
27
- end
28
- end
29
- end
30
- return false
31
- end
32
-
33
-
34
1
" "
35
2
function objective_min_fuel_and_flow_cost (pm:: AbstractPowerModel ; kwargs... )
36
- nl_gen = check_nl_gen_cost_models (pm)
37
- nl_dc = check_nl_dcline_cost_models (pm)
38
-
39
- nl = nl_gen || nl_dc || typeof (pm) <: AbstractIVRModel
40
-
41
3
expression_pg_cost (pm; kwargs... )
42
4
expression_p_dc_cost (pm; kwargs... )
43
5
44
- if ! nl
45
- return JuMP. @objective (pm. model, Min,
46
- sum (
47
- sum ( var (pm, n, :pg_cost , i) for (i,gen) in nw_ref[:gen ]) +
48
- sum ( var (pm, n, :p_dc_cost , i) for (i,dcline) in nw_ref[:dcline ])
49
- for (n, nw_ref) in nws (pm))
50
- )
51
- else
52
- pg_cost = Dict ()
53
- p_dc_cost = Dict ()
54
- for (n, nw_ref) in nws (pm)
55
- for (i,gen) in nw_ref[:gen ]
56
- pg_cost[(n,i)] = var (pm, n, :pg_cost , i)
57
- end
58
- for (i,dcline) in nw_ref[:dcline ]
59
- p_dc_cost[(n,i)] = var (pm, n, :p_dc_cost , i)
60
- end
61
- end
62
-
63
- return JuMP. @NLobjective (pm. model, Min,
64
- sum (
65
- sum ( pg_cost[n,i] for (i,gen) in nw_ref[:gen ]) +
66
- sum ( p_dc_cost[n,i] for (i,dcline) in nw_ref[:dcline ])
67
- for (n, nw_ref) in nws (pm))
68
- )
69
- end
6
+ return JuMP. @objective (pm. model, Min,
7
+ sum (
8
+ sum ( var (pm, n, :pg_cost , i) for (i,gen) in nw_ref[:gen ]) +
9
+ sum ( var (pm, n, :p_dc_cost , i) for (i,dcline) in nw_ref[:dcline ])
10
+ for (n, nw_ref) in nws (pm))
11
+ )
70
12
end
71
13
72
14
73
15
" "
74
16
function objective_min_fuel_cost (pm:: AbstractPowerModel ; kwargs... )
75
- nl_gen = check_nl_gen_cost_models (pm)
76
-
77
- nl = nl_gen || typeof (pm) <: AbstractIVRModel
78
-
79
17
expression_pg_cost (pm; kwargs... )
80
18
81
- if ! nl
82
- return JuMP. @objective (pm. model, Min,
83
- sum (
84
- sum ( var (pm, n, :pg_cost , i) for (i,gen) in nw_ref[:gen ])
85
- for (n, nw_ref) in nws (pm))
86
- )
87
- else
88
- pg_cost = Dict ()
89
- for (n, nw_ref) in nws (pm)
90
- for (i,gen) in nw_ref[:gen ]
91
- pg_cost[(n,i)] = var (pm, n, :pg_cost , i)
92
- end
93
- end
94
-
95
- return JuMP. @NLobjective (pm. model, Min,
96
- sum (
97
- sum ( pg_cost[n,i] for (i,gen) in nw_ref[:gen ])
98
- for (n, nw_ref) in nws (pm))
99
- )
100
- end
19
+ return JuMP. @objective (pm. model, Min,
20
+ sum (
21
+ sum ( var (pm, n, :pg_cost , i) for (i,gen) in nw_ref[:gen ])
22
+ for (n, nw_ref) in nws (pm))
23
+ )
101
24
end
102
25
103
26
@@ -293,7 +216,7 @@ function _pwl_cost_expression(pm::AbstractPowerModel, x_list, points; nw=0, id=1
293
216
expr += point. mw* cost_lambda[i]
294
217
cost_expr += point. cost* cost_lambda[i]
295
218
end
296
- JuMP. @NLconstraint (pm. model, expr == sum (x for x in x_list))
219
+ JuMP. @constraint (pm. model, expr == sum (x for x in x_list))
297
220
298
221
return cost_expr
299
222
end
@@ -313,7 +236,7 @@ function _polynomial_cost_expression(pm::AbstractPowerModel, x_list::Array{JuMP.
313
236
return cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2
314
237
else # length(cost_terms) >= 4
315
238
cost_nl = cost_terms[4 : end ]
316
- return JuMP. @NLexpression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 + sum ( v* x^ (d+ 2 ) for (d,v) in enumerate (cost_nl)) )
239
+ return JuMP. @expression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 + sum ( v* x^ (d+ 2 ) for (d,v) in enumerate (cost_nl)) )
317
240
end
318
241
end
319
242
@@ -355,18 +278,18 @@ end
355
278
356
279
# note that `cost_terms` should be providing in ascending order (the reverse of the Matpower spec.)
357
280
function _polynomial_cost_expression (pm:: AbstractPowerModel , x_list, cost_terms; nw= 0 , id= 1 , var_name= " x" )
358
- x = JuMP. @NLexpression (pm. model, sum (x for x in x_list))
281
+ x = JuMP. @expression (pm. model, sum (x for x in x_list))
359
282
if length (cost_terms) == 0
360
283
return 0.0
361
284
elseif length (cost_terms) == 1
362
285
return cost_terms[1 ]
363
286
elseif length (cost_terms) == 2
364
- return JuMP. @NLexpression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x)
287
+ return JuMP. @expression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x)
365
288
elseif length (cost_terms) == 3
366
- return JuMP. @NLexpression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 )
289
+ return JuMP. @expression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 )
367
290
else # length(cost_terms) >= 4
368
291
cost_nl = cost_terms[4 : end ]
369
- return JuMP. @NLexpression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 + sum ( v* x^ (d+ 2 ) for (d,v) in enumerate (cost_nl)) )
292
+ return JuMP. @expression (pm. model, cost_terms[1 ] + cost_terms[2 ]* x + cost_terms[3 ]* x^ 2 + sum ( v* x^ (d+ 2 ) for (d,v) in enumerate (cost_nl)) )
370
293
end
371
294
end
372
295
0 commit comments