Skip to content

Commit 4ee5d59

Browse files
committed
fix issue #706
1 parent dc44711 commit 4ee5d59

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

src/MOI_wrapper.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ end
149149
MOI.is_empty(optimizer::Optimizer) = optimizer.inner.isempty
150150

151151
function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
152+
153+
#check all model/variable/constraint attributes to
154+
#ensure that everything passed is handled by the solver
155+
copy_to_check_attributes(dest,src)
156+
152157
MOI.empty!(dest)
153158
idxmap = MOIU.IndexMap(dest, src)
154159
assign_constraint_row_ranges!(dest.rowranges, idxmap, src)
@@ -167,6 +172,45 @@ function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike)
167172
return idxmap
168173
end
169174

175+
function copy_to_check_attributes(dest, src)
176+
177+
#allowable model attributes
178+
for attr in MOI.get(src, MOI.ListOfModelAttributesSet())
179+
if attr == MOI.Name() ||
180+
attr == MOI.ObjectiveSense() ||
181+
attr isa MOI.ObjectiveFunction
182+
continue
183+
end
184+
throw(MOI.UnsupportedAttribute(attr))
185+
end
186+
187+
#allowable variable attributes
188+
for attr in MOI.get(src, MOI.ListOfVariableAttributesSet())
189+
if attr == MOI.VariableName() ||
190+
attr == MathOptInterface.VariablePrimalStart()
191+
continue
192+
end
193+
throw(MOI.UnsupportedAttribute(attr))
194+
end
195+
196+
#allowable constraint types and attributes
197+
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
198+
if !MOI.supports_constraint(dest, F, S)
199+
throw(MOI.UnsupportedConstraint{F, S}())
200+
end
201+
for attr in MOI.get(src, MOI.ListOfConstraintAttributesSet{F, S}())
202+
if attr == MOI.ConstraintName() ||
203+
attr == MOI.ConstraintDualStart()
204+
continue
205+
end
206+
throw(MOI.UnsupportedAttribute(attr))
207+
end
208+
end
209+
210+
return nothing
211+
end
212+
213+
170214
"""
171215
Set up index map from `src` variables and constraints to `dest` variables and constraints.
172216
"""

test/MOI_wrapper.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,28 @@ function test_runtests()
6161
MOI.Test.runtests(
6262
model,
6363
config,
64-
exclude = String[
64+
exclude = Union{String, Regex}[
6565
"test_attribute_SolverVersion",
6666
# Expected test failures:
6767
# MathOptInterface.jl issue #1431
6868
"test_model_LowerBoundAlreadySet",
6969
"test_model_UpperBoundAlreadySet",
7070
# FIXME
7171
# See https://github.com/jump-dev/MathOptInterface.jl/issues/1773
72-
"test_infeasible_MAX_SENSE",
73-
"test_infeasible_MAX_SENSE_offset",
74-
"test_infeasible_MIN_SENSE",
75-
"test_infeasible_MIN_SENSE_offset",
76-
"test_infeasible_affine_MAX_SENSE",
77-
"test_infeasible_affine_MAX_SENSE_offset",
78-
"test_infeasible_affine_MIN_SENSE",
79-
"test_infeasible_affine_MIN_SENSE_offset",
72+
r"^test_infeasible_MAX_SENSE$",
73+
r"test_infeasible_MAX_SENSE_offset$",
74+
r"^test_infeasible_MIN_SENSE$",
75+
r"test_infeasible_MIN_SENSE_offset$",
76+
r"^test_infeasible_affine_MAX_SENSE$",
77+
r"test_infeasible_affine_MAX_SENSE_offset$",
78+
r"^test_infeasible_affine_MIN_SENSE$",
79+
r"test_infeasible_affine_MIN_SENSE_offset$",
8080
# FIXME
8181
# See https://github.com/jump-dev/MathOptInterface.jl/issues/1759
82-
"test_unbounded_MAX_SENSE",
83-
"test_unbounded_MAX_SENSE_offset",
84-
"test_unbounded_MIN_SENSE",
85-
"test_unbounded_MIN_SENSE_offset",
82+
r"test_unbounded_MAX_SENSE$",
83+
r"test_unbounded_MAX_SENSE_offset$",
84+
r"^test_unbounded_MIN_SENSE$",
85+
r"test_unbounded_MIN_SENSE_offset$",
8686
# FIXME
8787
"test_model_copy_to_UnsupportedAttribute",
8888
# Segfault

0 commit comments

Comments
 (0)