Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,17 @@ function load_objective_term!(optimizer::Optimizer, α, vi::MOI.VariableIndex)
return addentry(optimizer.problem, 0, blk, i, j, coef, true)
end

function _check_unsupported_constraints(dest, src)
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
if !MOI.supports_constraint(dest, F, S)
throw(MOI.UnsupportedConstraint{F,S}())
end
end
return
end

function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
_check_unsupported_constraints(dest, src)
MOI.empty!(dest)
index_map = MOI.Utilities.IndexMap()

Expand All @@ -274,7 +284,7 @@ function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
MOI.PositiveSemidefiniteConeTriangle,
)
vis_src = MOI.get(src, MOI.ListOfVariableIndices())
if length(vis_src) < length(index_map.var_map)
if length(vis_src) != length(index_map.var_map)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. I guess this should be a separate PR. Is the current < correct? Shouldn't it be the other way around (or !=)?

_error(
"Free variables are not supported by CSDP",
"to bridge free variables into `x - y` where `x` and `y` are nonnegative.",
Expand Down
12 changes: 12 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ function test_options()
)
end

function test_unsupported_constraint()
model = MOI.Utilities.Model{Float64}();
x = MOI.add_variable(model);
MOI.add_constraint(model, x, MOI.GreaterThan(0.0));
MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(0.0));
@test_throws(
MOI.UsupportedConstraint{MOI.VariableIndex,MOI.GreaterThan{Float64}}(),
MOI.copy_to(CSDP.Optimizer(), model),
)
return
end

function test_runtests()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
Expand Down