Skip to content

Commit 249ab2e

Browse files
authored
Throw UnsupportedConstraint error in copy_to (#80)
1 parent 57a0c19 commit 249ab2e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/MOI_wrapper.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,20 @@ function load_objective_term!(optimizer::Optimizer, α, vi::MOI.VariableIndex)
261261
return addentry(optimizer.problem, 0, blk, i, j, coef, true)
262262
end
263263

264+
function _check_unsupported_constraints(dest, src)
265+
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
266+
constrained_variable =
267+
F == MOI.VectorOfVariables &&
268+
MOI.supports_add_constrained_variables(dest, S)
269+
if !(MOI.supports_constraint(dest, F, S) || constrained_variable)
270+
throw(MOI.UnsupportedConstraint{F,S}())
271+
end
272+
end
273+
return
274+
end
275+
264276
function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
277+
_check_unsupported_constraints(dest, src)
265278
MOI.empty!(dest)
266279
index_map = MOI.Utilities.IndexMap()
267280

test/MOI_wrapper.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ function test_options()
3636
)
3737
end
3838

39+
function test_unsupported_constraint()
40+
model = MOI.Utilities.Model{Float64}()
41+
x = MOI.add_variable(model)
42+
MOI.add_constraint(model, x, MOI.GreaterThan(0.0))
43+
MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(0.0))
44+
@test_throws(
45+
MOI.UnsupportedConstraint{MOI.VariableIndex,MOI.GreaterThan{Float64}}(),
46+
MOI.copy_to(CSDP.Optimizer(), model),
47+
)
48+
return
49+
end
50+
3951
function test_runtests()
4052
model = MOI.Utilities.CachingOptimizer(
4153
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),

0 commit comments

Comments
 (0)