Skip to content

Commit d885391

Browse files
committed
Update
1 parent 3ced5b7 commit d885391

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/Bridges/bridge_optimizer.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,17 @@ function _delete_variables_in_vector_of_variables_constraint(
517517
func = MOI.get(b, MOI.ConstraintFunction(), ci)
518518
if vis == func.variables
519519
MOI.delete(b, ci)
520-
return
521-
end
522-
variables = copy(func.variables)
523-
for vi in vis
524-
i = findfirst(isequal(vi), variables)
525-
if i === nothing
526-
continue
527-
elseif MOI.supports_dimension_update(S)
528-
call_in_context(MOI.delete, b, ci, IndexInVector(i))
529-
else
530-
MOI.Utilities.throw_delete_variable_in_vov(vi)
520+
else
521+
variables = copy(func.variables)
522+
for vi in vis
523+
i = findfirst(isequal(vi), variables)
524+
if i !== nothing
525+
if MOI.supports_dimension_update(S)
526+
call_in_context(MOI.delete, b, ci, IndexInVector(i))
527+
else
528+
MOI.Utilities.throw_delete_variable_in_vov(vi)
529+
end
530+
end
531531
end
532532
end
533533
return
@@ -536,7 +536,7 @@ end
536536
"""
537537
_is_added_by_bridge(
538538
c_map,
539-
cache::Dict{Any,Any},
539+
cache::Dict{Any,Set{Int64}},
540540
ci::MOI.ConstraintIndex{F,S},
541541
) where {F,S}
542542
@@ -547,17 +547,19 @@ so that we don't have to keep lopping through the bridges.
547547
"""
548548
function _is_added_by_bridge(
549549
c_map,
550-
cache::Dict{Any,Any},
550+
cache::Dict{Any,Set{Int64}},
551551
ci::MOI.ConstraintIndex{F,S},
552552
) where {F,S}
553553
ret = get!(cache, (F, S)) do
554-
list = MOI.ConstraintIndex{F,S}[]
554+
set = Set{Int64}()
555555
for bridge in values(c_map)
556-
append!(list, MOI.get(bridge, MOI.ListOfConstraintIndices{F,S}()))
556+
for ci in MOI.get(bridge, MOI.ListOfConstraintIndices{F,S}())
557+
push!(set, ci.value)
558+
end
557559
end
558-
return list
559-
end
560-
return ci in ret
560+
return set
561+
end::Set{Int64}
562+
return ci.value in ret
561563
end
562564

563565
"""
@@ -585,7 +587,7 @@ function _delete_variables_in_variables_constraints(
585587
vis::Vector{MOI.VariableIndex},
586588
)
587589
c_map = Constraint.bridges(b)::Constraint.Map
588-
cache = Dict{Any,Any}()
590+
cache = Dict{Any,Set{Int64}}()
589591
for vi in vis
590592
for ci in Constraint.variable_constraints(c_map, vi)
591593
if !_is_added_by_bridge(c_map, cache, ci)

0 commit comments

Comments
 (0)