Skip to content

Commit

Permalink
fix interchange overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Sep 4, 2024
1 parent 82f893e commit d3203e3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/devices_models/devices/area_interchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function add_constraints!(
},
) where {T <: AbstractPTDFModel}
@assert !isempty(inter_area_branch_map)

time_steps = get_time_steps(container)
device_names = [PSY.get_name(d) for d in devices]

Expand Down Expand Up @@ -195,13 +196,16 @@ function add_constraints!(
inter_change_name = PSY.get_name(area_interchange)
area_from = PSY.get_from_area(area_interchange)
area_to = PSY.get_to_area(area_interchange)
direction_branch_map = Dict{Float64, Dict{DataType, Vector{<:PSY.ACBranch}}}()
if haskey(inter_area_branch_map, (area_from, area_to))
inter_area_branches = inter_area_branch_map[(area_from, area_to)]
mult = 1.0
elseif haskey(inter_area_branch_map, (area_to, area_from))
inter_area_branches = inter_area_branch_map[(area_to, area_from)]
mult = -1.0
else
# 1 is the multiplier
direction_branch_map[1.0] = inter_area_branch_map[(area_from, area_to)]
end
if haskey(inter_area_branch_map, (area_to, area_from))
# -1 is the multiplier because the direction is reversed
direction_branch_map[-1.0] = inter_area_branch_map[(area_to, area_from)]
end
if isempty(direction_branch_map)
@warn(
"There are no branches modeled in Area InterChange $(summary(area_interchange)) \
LineFlowBoundConstraint not created"
Expand All @@ -211,11 +215,13 @@ function add_constraints!(

for t in time_steps
sum_of_flows = JuMP.AffExpr()
for (type, branches) in inter_area_branches
flow_vars = get_variable(container, FlowActivePowerVariable(), type)
for b in branches
b_name = PSY.get_name(b)
_add_to_jump_expression!(sum_of_flows, flow_vars[b_name, t], mult)
for (mult, inter_area_branches) in direction_branch_map
for (type, branches) in inter_area_branches
flow_vars = get_variable(container, FlowActivePowerVariable(), type)
for b in branches
b_name = PSY.get_name(b)
_add_to_jump_expression!(sum_of_flows, flow_vars[b_name, t], mult)
end
end
end
con_ub[inter_change_name, t] =
Expand Down

0 comments on commit d3203e3

Please sign in to comment.