@@ -386,26 +386,39 @@ _is_variable_function(::Any) = false
386
386
387
387
function _cost_of_bridging (
388
388
dest:: MOI.ModelLike ,
389
- :: Type{F} ,
390
389
:: Type{S} ,
391
- ) where {F,S}
390
+ ) where {S<: MOI.AbstractScalarSet }
391
+ return (
392
+ MOI. get (dest, MOI. VariableBridgingCost {S} ()) -
393
+ MOI. get (dest, MOI. ConstraintBridgingCost {MOI.SingleVariable,S} ()),
394
+ # In case of ties, we give priority to vector sets. See issue #987.
395
+ false ,
396
+ )
397
+ end
398
+
399
+ function _cost_of_bridging (
400
+ dest:: MOI.ModelLike ,
401
+ :: Type{S} ,
402
+ ) where {S<: MOI.AbstractVectorSet }
392
403
return (
393
404
MOI. get (dest, MOI. VariableBridgingCost {S} ()) -
394
- MOI. get (dest, MOI. ConstraintBridgingCost {F,S} ()),
395
- # In case of ties, we give priority to vector sets.
396
- # See issue #987
397
- F === MOI. SingleVariable,
405
+ MOI. get (dest, MOI. ConstraintBridgingCost {MOI.VectorOfVariables,S} ()),
406
+ # In case of ties, we give priority to vector sets. See issue #987
407
+ true ,
398
408
)
399
409
end
400
410
401
- _cost_of_bridging (arg:: Tuple ) = _cost_of_bridging (arg[1 ], arg[2 ], arg[3 ])
411
+ """
412
+ sorted_variable_sets_by_cost(dest::MOI.ModelLike, src::MOI.ModelLike)
402
413
403
- function _sorted_variable_sets_by_cost (dest:: MOI.ModelLike , src:: MOI.ModelLike )
414
+ Returns a `Vector{Type}` of the set types corresponding to `SingleVariable` and
415
+ `VectorOfVariables` constraints in the order in which they should be added.
416
+ """
417
+ function sorted_variable_sets_by_cost (dest:: MOI.ModelLike , src:: MOI.ModelLike )
404
418
constraint_types = MOI. get (src, MOI. ListOfConstraintTypesPresent ())
405
- single_or_vector_variables_types = Any[
406
- (dest, F, S) for (F, S) in constraint_types if _is_variable_function (F)
407
- ]
408
- return sort! (single_or_vector_variables_types; by = _cost_of_bridging)
419
+ sets = Type[S for (F, S) in constraint_types if _is_variable_function (F)]
420
+ sort! (sets; by = S:: Type -> _cost_of_bridging (dest, S))
421
+ return sets
409
422
end
410
423
411
424
"""
@@ -481,7 +494,7 @@ function default_copy_to(
481
494
else
482
495
Any[
483
496
_try_constrain_variables_on_creation (dest, src, index_map, S)
484
- for (_, F, S) in _sorted_variable_sets_by_cost (dest, src)
497
+ for S in sorted_variable_sets_by_cost (dest, src)
485
498
]
486
499
end
487
500
_copy_free_variables (dest, index_map, vis_src)
0 commit comments