|
| 1 | +""" |
| 2 | + ZerosBridge{T} <: Bridges.Variable.AbstractBridge |
| 3 | +
|
| 4 | +Transforms constrained variables in [`MathOptInterface.Zeros`](@ref) zeros, |
| 5 | +which ends up creating no variables in the underlying model. |
| 6 | +The bridged variables are therefore similar to parameters with zero values. |
| 7 | +Parameters with non-zero value can be created with constrained variables in |
| 8 | +[`MOI.EqualTo`](@ref) by combining a [`VectorizeBridge`](@ref) and this bridge. |
| 9 | +The dual values cannot be determined by the bridged hence they are determined |
| 10 | +by the bridged optimizer using [`MathOptInterface.Utilities.get_fallback`](@ref). |
| 11 | +""" |
| 12 | +struct ZerosBridge{T} <: AbstractBridge |
| 13 | + n::Int # Number of variables |
| 14 | +end |
| 15 | +function bridge_constrained_variables(::Type{ZerosBridge{T}}, |
| 16 | + model::MOI.ModelLike, |
| 17 | + set::MOI.Zeros) where T |
| 18 | + return ZerosBridge{T}(MOI.dimension(set)) |
| 19 | +end |
| 20 | + |
| 21 | +function supports_constrained_variables( |
| 22 | + ::Type{<:ZerosBridge}, ::Type{MOI.Zeros}) |
| 23 | + return true |
| 24 | +end |
| 25 | +function MOIB.added_constrained_variable_types(::Type{<:ZerosBridge}) |
| 26 | + return Tuple{DataType}[] |
| 27 | +end |
| 28 | +function MOIB.added_constraint_types(::Type{<:ZerosBridge}) |
| 29 | + return Tuple{DataType, DataType}[] |
| 30 | +end |
| 31 | + |
| 32 | +# Attributes, Bridge acting as a model |
| 33 | +MOI.get(bridge::ZerosBridge, ::MOI.NumberOfVariables) = 0 |
| 34 | +function MOI.get(bridge::ZerosBridge, ::MOI.ListOfVariableIndices) |
| 35 | + return MOI.VariableIndex[] |
| 36 | +end |
| 37 | + |
| 38 | +# Attributes, Bridge acting as a constraint |
| 39 | + |
| 40 | +function MOI.get(::MOI.ModelLike, ::MOI.ConstraintPrimal, |
| 41 | + bridge::ZerosBridge{T}) where T |
| 42 | + return zeros(T, bridge.n) |
| 43 | +end |
| 44 | +MOIB.needs_fallback(::MOI.ModelLike, ::MOI.ConstraintDual, ::ZerosBridge) = true |
| 45 | + |
| 46 | +function MOI.get(::MOI.ModelLike, ::MOI.VariablePrimal, |
| 47 | + ::ZerosBridge{T}, ::IndexInVector) where T |
| 48 | + return zero(T) |
| 49 | +end |
| 50 | + |
| 51 | +function MOIB.bridged_function(::ZerosBridge{T}, ::IndexInVector) where T |
| 52 | + return zero(MOI.ScalarAffineFunction{T}) |
| 53 | +end |
| 54 | +function unbridged_map(::ZerosBridge, ::MOI.VariableIndex, |
| 55 | + ::IndexInVector) |
| 56 | + return nothing |
| 57 | +end |
0 commit comments