Skip to content

Commit 9c79422

Browse files
committed
Support MOI.VectorNonlinearFunction
1 parent 1a4a6f0 commit 9c79422

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/MOI_wrapper.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ end
7979
### `supports_constraint`
8080
###
8181

82-
MOI.supports_constraint(::Optimizer, ::Type{VI}, ::Type{<:ALS}) = true
82+
MOI.supports_constraint(::Optimizer, ::Type{VI} , ::Type{<:ALS}) = true
8383
MOI.supports_constraint(::Optimizer, ::Type{SAF}, ::Type{<:ALS}) = true
84-
MOI.supports_constraint(::Optimizer, ::Type{MOI.ScalarNonlinearFunction}, ::Type{<:ALS}) = true
8584
MOI.supports_constraint(::Optimizer, ::Type{VAF}, ::Type{<:VLS}) = true
8685
MOI.supports_constraint(::Optimizer, ::Type{SQF}, ::Type{<:ALS}) = true
8786
MOI.supports_constraint(::Optimizer, ::Type{VQF}, ::Type{<:VLS}) = true
87+
MOI.supports_constraint(::Optimizer, ::Type{SNF}, ::Type{<:ALS}) = true
88+
MOI.supports_constraint(::Optimizer, ::Type{VNF}, ::Type{<:VLS}) = true
8889

8990
function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
9091
if !haskey(dest.options, "solver")

src/utils.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const SQF = MOI.ScalarQuadraticFunction{Float64} # ScalarQuadraticFunction{T}(a
1919
const VQF = MOI.VectorQuadraticFunction{Float64} # VectorQuadraticFunction{T}(affine_terms, quadratic_terms, constants)
2020
const QF = Union{SQF, VQF}
2121

22+
# ScalarNonlinearFunction and VectorNonlinearFunction
23+
const SNF = MOI.ScalarNonlinearFunction
24+
const VNF = MOI.VectorNonlinearFunction
25+
const NF = Union{SNF, VNF}
26+
2227
# AffLinSets and VecLinSets
2328
const ALS = Union{
2429
MOI.EqualTo{Float64},
@@ -375,11 +380,7 @@ function parser_MOI(moimodel, index_map, nvar)
375380

376381
contypes = MOI.get(moimodel, MOI.ListOfConstraintTypesPresent())
377382
for (F, S) in contypes
378-
F <: AF ||
379-
F <: QF ||
380-
F == MOI.ScalarNonlinearFunction ||
381-
F == VI ||
382-
error("Function $F is not supported.")
383+
F <: AF || F <: QF || F == NF || F == VI || error("Function $F is not supported.")
383384
S <: LS || error("Set $S is not supported.")
384385

385386
conindices = MOI.get(moimodel, MOI.ListOfConstraintIndices{F, S}())
@@ -431,7 +432,7 @@ _nlp_model(::MOI.Nonlinear.Model, ::MOI.ModelLike, ::Type, ::Type) = false
431432
function _nlp_model(
432433
dest::MOI.Nonlinear.Model,
433434
src::MOI.ModelLike,
434-
F::Type{<:Union{MOI.ScalarNonlinearFunction, MOI.VectorNonlinearFunction}},
435+
F::Type{<:NF},
435436
S::Type,
436437
)
437438
has_nonlinear = false
@@ -460,7 +461,7 @@ function _nlp_model(model::MOI.ModelLike)::Union{Nothing, MOI.Nonlinear.Model}
460461
has_nonlinear |= _nlp_model(nlp_model, model, F, S)
461462
end
462463
F = MOI.get(model, MOI.ObjectiveFunctionType())
463-
if F <: MOI.ScalarNonlinearFunction
464+
if F <: SNF
464465
MOI.Nonlinear.set_objective(nlp_model, MOI.get(model, MOI.ObjectiveFunction{F}()))
465466
has_nonlinear = true
466467
end

0 commit comments

Comments
 (0)