@@ -690,3 +690,75 @@ function MOI.is_empty(model::ModelFilter)
690
690
end
691
691
692
692
MOI. empty! (model:: ModelFilter ) = MOI. empty! (model. inner)
693
+
694
+ # ##
695
+ # ## These methods are deprecated, but unfortunately, they are used by a number
696
+ # ## of downstream packages and JuMP extensions.
697
+ # ##
698
+
699
+ function _try_constrain_variables_on_creation (
700
+ dest:: MOI.ModelLike ,
701
+ src:: MOI.ModelLike ,
702
+ index_map:: IndexMap ,
703
+ :: Type{S} ,
704
+ ) where {S<: MOI.AbstractVectorSet }
705
+ not_added = MOI. ConstraintIndex{MOI. VectorOfVariables,S}[]
706
+ for ci_src in
707
+ MOI. get (src, MOI. ListOfConstraintIndices {MOI.VectorOfVariables,S} ())
708
+ f_src = MOI. get (src, MOI. ConstraintFunction (), ci_src)
709
+ if ! allunique (f_src. variables)
710
+ # Can't add it because there are duplicate variables
711
+ push! (not_added, ci_src)
712
+ elseif any (vi -> haskey (index_map, vi), f_src. variables)
713
+ # Can't add it because it contains a variable previously added
714
+ push! (not_added, ci_src)
715
+ else
716
+ set = MOI. get (src, MOI. ConstraintSet (), ci_src):: S
717
+ vis_dest, ci_dest = MOI. add_constrained_variables (dest, set)
718
+ index_map[ci_src] = ci_dest
719
+ for (vi_src, vi_dest) in zip (f_src. variables, vis_dest)
720
+ index_map[vi_src] = vi_dest
721
+ end
722
+ end
723
+ end
724
+ return not_added
725
+ end
726
+
727
+ function _try_constrain_variables_on_creation (
728
+ dest:: MOI.ModelLike ,
729
+ src:: MOI.ModelLike ,
730
+ index_map:: IndexMap ,
731
+ :: Type{S} ,
732
+ ) where {S<: MOI.AbstractScalarSet }
733
+ not_added = MOI. ConstraintIndex{MOI. VariableIndex,S}[]
734
+ for ci_src in
735
+ MOI. get (src, MOI. ListOfConstraintIndices {MOI.VariableIndex,S} ())
736
+ f_src = MOI. get (src, MOI. ConstraintFunction (), ci_src)
737
+ if haskey (index_map, f_src)
738
+ # Can't add it because it contains a variable previously added
739
+ push! (not_added, ci_src)
740
+ else
741
+ set = MOI. get (src, MOI. ConstraintSet (), ci_src):: S
742
+ vi_dest, ci_dest = MOI. add_constrained_variable (dest, set)
743
+ index_map[ci_src] = ci_dest
744
+ index_map[f_src] = vi_dest
745
+ end
746
+ end
747
+ return not_added
748
+ end
749
+
750
+ function _copy_free_variables (dest:: MOI.ModelLike , index_map:: IndexMap , vis_src)
751
+ if length (vis_src) == length (index_map. var_map)
752
+ return # All variables already added
753
+ end
754
+ x = MOI. add_variables (dest, length (vis_src) - length (index_map. var_map))
755
+ i = 1
756
+ for vi in vis_src
757
+ if ! haskey (index_map, vi)
758
+ index_map[vi] = x[i]
759
+ i += 1
760
+ end
761
+ end
762
+ @assert i == length (x) + 1
763
+ return
764
+ end
0 commit comments