Skip to content

Commit 3bb845b

Browse files
authored
Add support for complementarity constraints (#206)
1 parent 2bf9558 commit 3bb845b

3 files changed

Lines changed: 23 additions & 32 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ List of supported constraint types:
106106
* [`MOI.VariableIndex`](@ref) in [`MOI.Interval{Float64}`](@ref)
107107
* [`MOI.VariableIndex`](@ref) in [`MOI.LessThan{Float64}`](@ref)
108108
* [`MOI.VariableIndex`](@ref) in [`MOI.ZeroOne`](@ref)
109+
* [`MOI.VectorOfVariables`](@ref) in [`MOI.Complements`](@ref)
110+
* [`MOI.VectorAffineFunction`](@ref) in [`MOI.Complements`](@ref)
111+
* [`MOI.VectorQuadraticFunction`](@ref) in [`MOI.Complements`](@ref)
112+
* [`MOI.VectorNonlinearFunction`](@ref) in [`MOI.Complements`](@ref)
109113

110114
List of supported model attributes:
111115

@@ -115,7 +119,7 @@ List of supported model attributes:
115119

116120
Note that some solver executables may not support the full list of constraint
117121
types. For example, `Ipopt_jll` does not support `MOI.Integer` or `MOI.ZeroOne`
118-
constraints.
122+
constraints, nor does it support the `MOI.Complements` set.
119123

120124
## Options
121125

src/AmplNLWriter.jl

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -223,42 +223,18 @@ function MOI.set(model::Optimizer, attr::MOI.RawOptimizerAttribute, value)
223223
return
224224
end
225225

226-
const _SCALAR_FUNCTIONS = Union{
227-
MOI.VariableIndex,
228-
MOI.ScalarAffineFunction{Float64},
229-
MOI.ScalarQuadraticFunction{Float64},
230-
MOI.ScalarNonlinearFunction,
231-
}
232-
233-
const _SCALAR_SETS = Union{
234-
MOI.LessThan{Float64},
235-
MOI.GreaterThan{Float64},
236-
MOI.EqualTo{Float64},
237-
MOI.Interval{Float64},
238-
}
239-
240226
function MOI.supports_constraint(
241-
::Optimizer,
242-
::Type{<:_SCALAR_FUNCTIONS},
243-
::Type{<:_SCALAR_SETS},
244-
)
245-
return true
227+
model::Optimizer,
228+
::Type{F},
229+
::Type{S},
230+
) where {F<:MOI.AbstractFunction,S<:MOI.AbstractSet}
231+
return MOI.supports_constraint(model.inner, F, S)
246232
end
247233

248-
function MOI.supports_constraint(
249-
::Optimizer,
250-
::Type{MOI.VariableIndex},
251-
::Type{<:Union{MOI.ZeroOne,MOI.Integer}},
252-
)
253-
return true
234+
function MOI.supports(model::Optimizer, attr::MOI.AbstractModelAttribute)
235+
return MOI.supports(model.inner, attr)
254236
end
255237

256-
MOI.supports(::Optimizer, ::MOI.ObjectiveFunction{<:_SCALAR_FUNCTIONS}) = true
257-
258-
MOI.supports(::Optimizer, ::MOI.ObjectiveSense) = true
259-
260-
MOI.supports(::Optimizer, ::MOI.NLPBlock) = true
261-
262238
function MOI.supports(
263239
::Optimizer,
264240
::MOI.VariablePrimalStart,

test/MOI_wrapper.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function test_ipopt_runtests()
8181
"_SOS2_",
8282
"test_linear_integer_",
8383
"test_cpsat_",
84+
# Ipopt doesn't support complementarity
85+
"_complementarity",
8486
],
8587
)
8688
return
@@ -294,6 +296,15 @@ function test_supports_incremental_interface()
294296
return
295297
end
296298

299+
function test_supports_complements()
300+
model = AmplNLWriter.Optimizer()
301+
inner = MOI.FileFormats.NL.Model()
302+
F, S = MOI.VectorOfVariables, MOI.Complements
303+
@test MOI.supports_constraint(model, F, S) ==
304+
MOI.supports_constraint(inner, F, S)
305+
return
306+
end
307+
297308
end # module
298309

299310
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)