Skip to content

Commit 686c010

Browse files
authored
improve support for pwl uc functions and add test (#795)
1 parent 84252ad commit 686c010

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PowerModels.jl Change Log
22
=========================
33

44
### Staged
5+
- Improved support for PWL costs with on/off generators
56
- Added support for two-terminal HVDC lines to PSSE export (#754)
67
- Improved formulation of `relaxation_sin_on_off` constraint (#786)
78

src/core/objective.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,12 @@ function objective_variable_pg_cost(pm::AbstractPowerModel, report::Bool=true)
482482
pg_cost = var(pm, n)[:pg_cost] = Dict{Int,Any}()
483483

484484
for (i,gen) in ref(pm, n, :gen)
485-
points = calc_pwl_points(gen["ncost"], gen["cost"], gen["pmin"], gen["pmax"])
485+
pg_vars = [var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)]
486+
pmin = sum(JuMP.lower_bound.(pg_vars))
487+
pmax = sum(JuMP.upper_bound.(pg_vars))
488+
489+
# note pmin/pmax may be different from gen["pmin"]/gen["pmax"] in the on/off case
490+
points = calc_pwl_points(gen["ncost"], gen["cost"], pmin, pmax)
486491

487492
pg_cost_lambda = JuMP.@variable(pm.model,
488493
[i in 1:length(points)], base_name="$(n)_pg_cost_lambda",
@@ -497,7 +502,7 @@ function objective_variable_pg_cost(pm::AbstractPowerModel, report::Bool=true)
497502
pg_expr += point.mw*pg_cost_lambda[i]
498503
pg_cost_expr += point.cost*pg_cost_lambda[i]
499504
end
500-
JuMP.@constraint(pm.model, pg_expr == sum(var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)))
505+
JuMP.@constraint(pm.model, pg_expr == sum(pg_vars))
501506
pg_cost[i] = pg_cost_expr
502507
end
503508

@@ -512,7 +517,13 @@ function objective_variable_dc_cost(pm::AbstractPowerModel, report::Bool=true)
512517
p_dc_cost = var(pm, n)[:p_dc_cost] = Dict{Int,Any}()
513518

514519
for (i,dcline) in ref(pm, n, :dcline)
515-
points = calc_pwl_points(dcline["ncost"], dcline["cost"], dcline["pminf"], dcline["pmaxf"])
520+
arc = (i, dcline["f_bus"], dcline["t_bus"])
521+
p_dc_vars = [var(pm, n, :p_dc)[arc][c] for c in conductor_ids(pm, n)]
522+
pmin = sum(JuMP.lower_bound.(p_dc_vars))
523+
pmax = sum(JuMP.upper_bound.(p_dc_vars))
524+
525+
# note pmin/pmax may be different from dcline["pminf"]/dcline["pmaxf"] in the on/off case
526+
points = calc_pwl_points(dcline["ncost"], dcline["cost"], pmin, pmax)
516527

517528
dc_p_cost_lambda = JuMP.@variable(pm.model,
518529
[i in 1:length(points)], base_name="$(n)_dc_p_cost_lambda",
@@ -528,8 +539,7 @@ function objective_variable_dc_cost(pm::AbstractPowerModel, report::Bool=true)
528539
dc_p_cost_expr += point.cost*dc_p_cost_lambda[i]
529540
end
530541

531-
arc = (i, dcline["f_bus"], dcline["t_bus"])
532-
JuMP.@constraint(pm.model, dc_p_expr == sum(var(pm, n, :p_dc)[arc][c] for c in conductor_ids(pm, n)))
542+
JuMP.@constraint(pm.model, dc_p_expr == sum(p_dc_vars))
533543
p_dc_cost[i] = dc_p_cost_expr
534544
end
535545

test/data/matpower/case5_pwlc.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
%% generator data
1818
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin
1919
mpc.gen = [
20-
1 40.0 30.0 30.0 -30.0 1.07762 100.0 1 40.0 0.0;
21-
1 170.0 127.5 127.5 -127.5 1.07762 100.0 1 170.0 0.0;
22-
3 324.498 390.0 390.0 -390.0 1.1 100.0 1 520.0 0.0;
23-
4 0.0 -10.802 150.0 -150.0 1.06414 100.0 1 200.0 0.0;
24-
10 470.694 -165.039 450.0 -450.0 1.06907 100.0 1 600.0 0.0;
20+
1 40.0 30.0 30.0 -30.0 1.07762 100.0 1 40.0 0.0;
21+
1 170.0 127.5 127.5 -127.5 1.07762 100.0 1 170.0 50.0;
22+
3 324.498 390.0 390.0 -390.0 1.1 100.0 1 520.0 100.0;
23+
4 0.0 -10.802 150.0 -150.0 1.06414 100.0 1 200.0 50.0;
24+
10 470.694 -165.039 450.0 -450.0 1.06907 100.0 1 600.0 60.0;
2525
];
2626

2727
%% generator cost data

test/opf-var.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,19 @@ end
404404
@test isapprox(result["objective"], 17613.2; atol = 1e0)
405405
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0)
406406
end
407+
408+
@testset "5-bus uc pwl case" begin
409+
data = parse_file("../test/data/matpower/case5_pwlc.m")
410+
for (i,load) in data["load"]
411+
load["pd"] = 0.5*load["pd"]
412+
end
413+
result = PowerModels._run_ucopf(data, DCPPowerModel, cbc_solver)
414+
415+
@test result["termination_status"] == OPTIMAL
416+
@test isapprox(result["objective"], 8008.0; atol = 1e0)
417+
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0)
418+
@test isapprox(result["solution"]["gen"]["5"]["gen_status"], 0.0)
419+
end
407420
end
408421

409422

0 commit comments

Comments
 (0)