Skip to content

Commit 05446cc

Browse files
authored
Throw SetAttributeNotAllowed when NLPBlock has objective function (#326)
1 parent 41aa699 commit 05446cc

File tree

2 files changed

+17
-57
lines changed

2 files changed

+17
-57
lines changed

src/MOI_wrapper/nonlinear_constraints.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
MOI.supports(::Optimizer, ::MOI.NLPBlock) = true
77

8-
function MOI.set(o::Optimizer, ::MOI.NLPBlock, data::MOI.NLPBlockData)
8+
function MOI.set(o::Optimizer, attr::MOI.NLPBlock, data::MOI.NLPBlockData)
99
# We don't actually store the data (to be queried later during the solve
1010
# process). Instead, we extract the expression graphs and add the
1111
# corresponding constraints to the model directly.
1212
if data.has_objective
13-
error("Nonlinear objective not supported by SCIP.jl!")
13+
msg = "Nonlinear objective not supported by SCIP.jl!"
14+
throw(MOI.SetAttributeNotAllowed(attr, msg))
1415
end
1516
# go back to problem stage
1617
allow_modification(o)

test/MOI_tests.jl

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ function runtests()
2424
return
2525
end
2626

27-
const _EXCLUDE_NONLINEAR_OBJECTIVES = [
28-
# SCIP does not support nonlinear objective functions.
29-
r"^test_nonlinear_hs071_NLPBlockDual$",
30-
r"^test_nonlinear_invalid$",
31-
r"^test_nonlinear_objective$",
32-
r"^test_nonlinear_objective_and_moi_objective_test$",
33-
]
27+
const CONFIG = MOI.Test.Config(;
28+
atol=5e-3,
29+
rtol=1e-4,
30+
exclude=Any[
31+
MOI.ConstraintDual,
32+
MOI.DualObjectiveValue,
33+
MOI.VariableBasisStatus,
34+
MOI.ConstraintBasisStatus,
35+
],
36+
)
3437

3538
function test_runtests_cached()
3639
model = MOI.Bridges.full_bridge_optimizer(
@@ -41,66 +44,22 @@ function test_runtests_cached()
4144
Float64,
4245
)
4346
MOI.set(model, MOI.Silent(), true)
44-
MOI.Test.runtests(
45-
model,
46-
MOI.Test.Config(;
47-
atol=5e-3,
48-
rtol=1e-4,
49-
exclude=Any[
50-
MOI.ConstraintDual,
51-
MOI.DualObjectiveValue,
52-
MOI.VariableBasisStatus,
53-
MOI.ConstraintBasisStatus,
54-
],
55-
);
56-
exclude=_EXCLUDE_NONLINEAR_OBJECTIVES,
57-
)
47+
MOI.Test.runtests(model, CONFIG)
5848
return
5949
end
6050

6151
function test_runtests_bridged()
6252
model = MOI.Bridges.full_bridge_optimizer(SCIP.Optimizer(), Float64)
6353
MOI.set(model, MOI.Silent(), true)
64-
MOI.Test.runtests(
65-
model,
66-
MOI.Test.Config(;
67-
atol=5e-3,
68-
rtol=1e-4,
69-
exclude=Any[
70-
MOI.ConstraintDual,
71-
MOI.DualObjectiveValue,
72-
MOI.VariableBasisStatus,
73-
MOI.ConstraintBasisStatus,
74-
],
75-
);
76-
warn_unsupported=false,
77-
exclude=vcat(
78-
_EXCLUDE_NONLINEAR_OBJECTIVES,
79-
# TODO(odow): bugs to fix
80-
r"^test_model_delete$",
81-
),
82-
)
54+
# TODO(odow): bugs to fix
55+
MOI.Test.runtests(model, CONFIG; exclude=[r"^test_model_delete$"])
8356
return
8457
end
8558

8659
function test_runtests_direct()
8760
model = SCIP.Optimizer()
8861
MOI.set(model, MOI.Silent(), true)
89-
MOI.Test.runtests(
90-
model,
91-
MOI.Test.Config(;
92-
atol=5e-3,
93-
rtol=1e-4,
94-
exclude=Any[
95-
MOI.ConstraintDual,
96-
MOI.DualObjectiveValue,
97-
MOI.VariableBasisStatus,
98-
MOI.ConstraintBasisStatus,
99-
],
100-
);
101-
warn_unsupported=false,
102-
exclude=_EXCLUDE_NONLINEAR_OBJECTIVES,
103-
)
62+
MOI.Test.runtests(model, CONFIG)
10463
return
10564
end
10665

0 commit comments

Comments
 (0)