jump-dev / MathOptInterface.jl

A data structure for mathematical optimization problems
http://jump.dev/MathOptInterface.jl/
Other
394 stars 87 forks source link

[FileFormats.CBF] bug copying unsupported variable bounds to CBF #2570

Open odow opened 17 hours ago

odow commented 17 hours ago

Reported as https://discourse.julialang.org/t/jump-moi-wrapper-interface-problem/121776/5

julia> import MathOptInterface as MOI

julia> model = MOI.Utilities.Model{Float64}()
MOIU.Model{Float64}
├ ObjectiveSense: FEASIBILITY_SENSE
├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
├ NumberOfVariables: 0
└ NumberOfConstraints: 0

julia> x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(1.0))
(MOI.VariableIndex(1), MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.GreaterThan{Float64}}(1))

julia> dest = MOI.FileFormats.CBF.Model()
MOI.FileFormats.CBF.Model
├ ObjectiveSense: FEASIBILITY_SENSE
├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
├ NumberOfVariables: 0
└ NumberOfConstraints: 0

julia> MOI.copy_to(dest, model)
MathOptInterface.Utilities.IndexMap with 2 entries:
  MOI.VariableIndex(1)                                    => MOI.VariableIndex(1)
  ConstraintIndex{VariableIndex, GreaterThan{Float64}}(1) => ConstraintIndex{VariableIndex, GreaterThan{Float64}}(1)

julia> print(dest)
Feasibility

Subject to:

VariableIndex-in-GreaterThan{Float64}
blegat commented 2 hours ago

I'm not sure to understand why we need this. If it's not supported, add_constraint is already throwing UnsupportedConstraint so we shouldn't have to call supports_constraint. If the model does not throw correctly then the model should be fixed, we should not complicate copy_to just to make bugs occur less frequently (as they will still appear if the user calls add_constraint directly).