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
16 changes: 16 additions & 0 deletions src/MultiObjectiveAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,18 @@ function MOI.set(model::Optimizer, attr::_ATTRIBUTES, args...)
end

function MOI.get(model::Optimizer, attr::_ATTRIBUTES, args...)
if MOI.is_set_by_optimize(attr)
msg = "MOA does not support querying this attribute."
throw(MOI.GetAttributeNotAllowed(attr, msg))
end
return MOI.get(model.inner, attr, args...)
end

function MOI.get(model::Optimizer, attr::_ATTRIBUTES, arg::Vector{T}) where {T}
if MOI.is_set_by_optimize(attr)
msg = "MOA does not support querying this attribute."
throw(MOI.GetAttributeNotAllowed(attr, msg))
end
return MOI.get.(model, attr, arg)
end

Expand Down Expand Up @@ -569,6 +577,14 @@ function MOI.get(
return sol.x[x]
end

function MOI.get(
model::Optimizer,
attr::MOI.VariablePrimal,
x::Vector{MOI.VariableIndex},
)
return MOI.get.(model, attr, x)
end

function MOI.get(model::Optimizer, attr::MOI.ObjectiveValue)
return model.solutions[attr.result_index].y
end
Expand Down
24 changes: 24 additions & 0 deletions test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ function test_solve_time()
return
end

function test_unnsupported_attributes()
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 2)
c = MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
f = MOI.Utilities.operate(vcat, Float64, 1.0 .* x...)
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.optimize!(model)
@test_throws(
MOI.GetAttributeNotAllowed{MOI.RelativeGap},
MOI.get(model, MOI.RelativeGap()),
)
@test_throws(
MOI.GetAttributeNotAllowed{MOI.DualObjectiveValue},
MOI.get(model, MOI.DualObjectiveValue()),
)
@test_throws(
MOI.GetAttributeNotAllowed{MOI.ConstraintDual},
MOI.get(model, MOI.ConstraintDual(), c),
)
return
end

end

TestModel.run_tests()
Loading