Skip to content

Commit 20b7294

Browse files
committed
Use the patch of Oscar
1 parent 3aa2b9e commit 20b7294

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/utils.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -426,47 +426,46 @@ function parser_MOI(moimodel, index_map, nvar)
426426
end
427427

428428
# Affine or quadratic, nothing to do
429-
function _nlp_model(model::Union{Nothing, MOI.Nonlinear.Model}, ::MOI.ModelLike, ::Type, ::Type)
430-
return model
431-
end
429+
_nlp_model(::MOI.Nonlinear.Model, ::MOI.ModelLike, ::Type, ::Type) = false
432430

433431
function _nlp_model(
434-
dest::Union{Nothing, MOI.Nonlinear.Model},
432+
dest::MOI.Nonlinear.Model,
435433
src::MOI.ModelLike,
436434
F::Type{<:Union{MOI.ScalarNonlinearFunction, MOI.VectorNonlinearFunction}},
437435
S::Type,
438436
)
437+
has_nonlinear = false
439438
for ci in MOI.get(src, MOI.ListOfConstraintIndices{F, S}())
440-
if isnothing(dest)
441-
dest = MOI.Nonlinear.Model()
442-
end
443439
MOI.Nonlinear.add_constraint(
444440
dest,
445441
MOI.get(src, MOI.ConstraintFunction(), ci),
446442
MOI.get(src, MOI.ConstraintSet(), ci),
447443
)
444+
has_nonlinear = true
448445
end
449-
return dest
446+
return has_nonlinear
450447
end
451448

452-
function _nlp_model(model::MOI.ModelLike)
453-
nlp_model = nothing
454-
for op in MOI.get(model, MOI.ListOfSupportedNonlinearOperators())
455-
if isnothing(nlp_model)
456-
nlp_model = MOI.Nonlinear.Model()
449+
function _nlp_model(model::MOI.ModelLike)::Union{Nothing,MOI.Nonlinear.Model}
450+
nlp_model = MOI.Nonlinear.Model()
451+
has_nonlinear = false
452+
for attr in MOI.get(model, MOI.ListOfModelAttributesSet())
453+
if attr isa MOI.UserDefinedFunction
454+
has_nonlinear = true
455+
args = MOI.get(model, attr)
456+
MOI.Nonlinear.register_operator(nlp_model, attr.name, attr.arity, args...)
457457
end
458-
MOI.Nonlinear.register_operator(nlp_model, op.name, op.arity)
459458
end
460459
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
461-
nlp_model = _nlp_model(nlp_model, model, F, S)
460+
has_nonlinear |= _nlp_model(nlp_model, model, F, S)
462461
end
463462
F = MOI.get(model, MOI.ObjectiveFunctionType())
464463
if F <: MOI.ScalarNonlinearFunction
465-
if isnothing(nlp_model)
466-
nlp_model = MOI.Nonlinear.Model()
467-
end
468-
attr = MOI.ObjectiveFunction{F}()
469-
MOI.Nonlinear.set_objective(nlp_model, MOI.get(model, attr))
464+
MOI.Nonlinear.set_objective(nlp_model, MOI.get(model, MOI.ObjectiveFunction{F}()))
465+
has_nonlinear = true
466+
end
467+
if !has_nonlinear
468+
return nothing
470469
end
471470
return nlp_model
472471
end

0 commit comments

Comments
 (0)