From 7897adbee1db57fe17332967e25bc249bac5d192 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 5 Aug 2024 20:03:38 -0500 Subject: [PATCH] enforce_transmission: Add constraint refs to model --- .../methods/XavQiuWanThi2019/enforce.jl | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/solution/methods/XavQiuWanThi2019/enforce.jl b/src/solution/methods/XavQiuWanThi2019/enforce.jl index 87b39f0..61dc7ac 100644 --- a/src/solution/methods/XavQiuWanThi2019/enforce.jl +++ b/src/solution/methods/XavQiuWanThi2019/enforce.jl @@ -26,59 +26,67 @@ function _enforce_transmission(; isf::Matrix{Float64}, lodf::Matrix{Float64}, )::Nothing - instance = model[:instance] limit::Float64 = 0.0 overflow = model[:overflow] net_injection = model[:net_injection] + lm = violation.monitored_line + lc = violation.outage_line + t = violation.time + eq_flow_ub = _init(model, :eq_flow_ub) + eq_flow_lb = _init(model, :eq_flow_lb) + eq_flow_def = _init(model, :eq_flow_def) + eq_idx = ( + sc.name, + lm.name, + lc === nothing ? "Base" : lc.name, + t, + ) - if violation.outage_line === nothing - limit = violation.monitored_line.normal_flow_limit[violation.time] + if lc === nothing + limit = lm.normal_flow_limit[t] @info @sprintf( " %8.3f MW overflow in %-5s time %3d (pre-contingency, scenario %s)", violation.amount, - violation.monitored_line.name, - violation.time, + lm.name, + t, sc.name, ) else - limit = violation.monitored_line.emergency_flow_limit[violation.time] + limit = lm.emergency_flow_limit[t] @info @sprintf( " %8.3f MW overflow in %-5s time %3d (outage: line %s, scenario %s)", violation.amount, - violation.monitored_line.name, - violation.time, - violation.outage_line.name, + lm.name, + t, + lc.name, sc.name, ) end - fm = violation.monitored_line.name - t = violation.time - flow = @variable(model, base_name = "flow[$fm,$t]") - - v = overflow[sc.name, violation.monitored_line.name, violation.time] - @constraint(model, flow <= limit + v) - @constraint(model, -flow <= limit + v) + v = overflow[sc.name, lm.name, t] + flow = @variable(model, base_name = "flow[$eq_idx]") + eq_flow_ub[eq_idx] = @constraint(model, flow <= limit + v) + eq_flow_lb[eq_idx] = @constraint(model, -flow <= limit + v) - if violation.outage_line === nothing - @constraint( + if lc === nothing + eq_flow_def[eq_idx] = @constraint( model, flow == sum( - net_injection[sc.name, b.name, violation.time] * - isf[violation.monitored_line.offset, b.offset] for + net_injection[sc.name, b.name, t] * + isf[lm.offset, b.offset] for b in sc.buses if b.offset > 0 ) ) else - @constraint( + eq_flow_def[eq_idx] = @constraint( model, flow == sum( - net_injection[sc.name, b.name, violation.time] * ( - isf[violation.monitored_line.offset, b.offset] + ( + net_injection[sc.name, b.name, t] * ( + isf[lm.offset, b.offset] + ( lodf[ - violation.monitored_line.offset, - violation.outage_line.offset, - ] * isf[violation.outage_line.offset, b.offset] + lm.offset, + lc.offset, + ] * isf[lc.offset, b.offset] ) ) for b in sc.buses if b.offset > 0 )