Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ext/IpoptMathOptInterfaceExt/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,26 @@ function MOI.get(model::Optimizer, ::MOI.NLPBlock)
return MOI.NLPBlockData(model.evaluator)
end

function MOI.set(model::Optimizer, ::MOI.NLPBlock, nlp_data::MOI.NLPBlockData)
function MOI.set(
model::Optimizer,
attr::MOI.NLPBlock,
nlp_data::MOI.NLPBlockData,
)
P = MOI.Parameter{Float64}
if model.number_of_nonlinear_constraints > 0 ||
model.has_nonlinear_objective ||
MOI.get(model.model, MOI.NumberOfConstraints{MOI.VariableIndex,P}()) > 0
error("Cannot mix the new and legacy nonlinear APIs")
end
if model.nlp_data.has_objective && !nlp_data.has_objective
throw(
MOI.SetAttributeNotAllowed(
attr,
"Cannot replace a legacy NLP block that has an objective " *
"with one that has no objective. Rebuild the model instead.",
),
)
end
model.nlp_data = nlp_data
model.uses_nlp_block = !(nlp_data.evaluator isa _EmptyNLPEvaluator)
if model.uses_nlp_block
Expand Down
9 changes: 9 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,15 @@ function test_NLPBlock_objective_only_with_quadratic_constraint()
atol = 1e-6,
)
end
attr = MOI.NLPBlock()
constraints_only = MOI.NLPBlockData([], data.evaluator, false)
@test_throws MOI.SetAttributeNotAllowed{typeof(attr)} MOI.set(
model,
attr,
constraints_only,
)
@test MOI.get(model, attr) === data
MOI.set(model, attr, data)
end
return
end
Expand Down
Loading