@@ -476,6 +476,7 @@ function MOI.is_valid(
476476 v_map = Variable. bridges (b):: Variable.Map
477477 return MOI. is_valid (v_map, ci)
478478 else
479+ # This has the potential to be a false positive. see #2817
479480 return haskey (Constraint. bridges (b), ci)
480481 end
481482 else
@@ -506,6 +507,17 @@ function _delete_variables_in_vector_of_variables_constraint(
506507 end
507508end
508509
510+ function _is_added_by_bridge (c_map, ci:: MOI.ConstraintIndex{F,S} ) where {F,S}
511+ for (i, bridge) in c_map
512+ if i == ci
513+ continue
514+ elseif ci in MOI. get (bridge, MOI. ListOfConstraintIndices {F,S} ())
515+ return true
516+ end
517+ end
518+ return false
519+ end
520+
509521"""
510522 _delete_variables_in_variables_constraints(
511523 b::AbstractBridgeOptimizer,
@@ -520,18 +532,26 @@ function _delete_variables_in_variables_constraints(
520532 vis:: Vector{MOI.VariableIndex} ,
521533)
522534 c_map = Constraint. bridges (b):: Constraint.Map
523- # First, we need to delete any scalar constraints associated with these
524- # variables.
535+ # The point of this function is to delete constraints associated with the
536+ # variables in `vis`.
537+ #
538+ # There are two problematic cases:
539+ #
540+ # 1. A VariableIndex bridged to a VectorOfVariables equivalent. For example,
541+ # x in Interval --> [x] in HyperRectangle
542+ # 2. A VectorOfVariables bridged to a VariableIndex equivalent. For example,
543+ # [x] in Nonnegatives --> x in GreaterThan
525544 #
526- # x in S_s --> [x] in S_v
545+ # First, we need to delete scalar constraints, UNLESS they were added by a
546+ # different constraint bridge.
527547 for vi in vis
528548 # If a bridged `VariableIndex` constraints creates a second one, then we
529549 # will delete the second one when deleting the first one hence we should
530550 # not delete it again in this loop. For this, we reverse the order so
531551 # that we encounter the first one first and we won't delete the second
532552 # one since `MOI.is_valid(b, ci)` will be `false`.
533553 for ci in Iterators. reverse (Constraint. variable_constraints (c_map, vi))
534- if MOI. is_valid (b, ci)
554+ if MOI. is_valid (b, ci) && ! _is_added_by_bridge (c_map, ci)
535555 MOI. delete (b, ci)
536556 end
537557 end
0 commit comments