Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

MultirowChange overwrites other constraints #104

@mtanneau

Description

@mtanneau
import Gurobi
import MathOptInterface
MOI = MathOptInterface

m = Gurobi.Optimizer()

x = MOI.add_variable(m)

# Create two linear constraints, wrapped in a single VectorAffineFunction constraint
n = 2
c1 = MOI.add_constraint(m,
    MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0),
    MOI.EqualTo(0.0)
)
# Add another linear constraint
c2 = MOI.add_constraint(m,
    MOI.VectorAffineFunction(
        [MOI.VectorAffineTerm(i, MOI.ScalarAffineTerm(1.0, x)) for i in 1:n],
        zeros(n)
    ), MOI.Zeros(n)
)

# Now create another variable
y = MOI.add_variable(m)

# Multi-row change
# That Multirow should raise an error, because the output dimension of c1 is 2
MOI.modify(m, c2, MOI.MultirowChange(y, [(1, 1.1), (2, 2.2), (3, 3.3)]))

# The above call did not raise an error, and modified c1
MOI.get(m, MOI.ConstraintFunction(), c1)

outputs

MathOptInterface.ScalarAffineFunction{Float64}(MathOptInterface.ScalarAffineTerm{Float64}[ScalarAffineTerm{Float64}(2.0, VariableIndex(1)), ScalarAffineTerm{Float64}(1.1, VariableIndex(2))], 0.0)

It appears that MOI.modify with a MultirowChange ends up calling LQOI.change_matrix_coefficient!, which simply re-writes matrix coefficients without any checks.
In particular:

  • Other constraints can be over-written (cf example above)
  • Instead of changing coeff of variable j of the i-th output dimension of the vector-valued constraint, it changes coeff (i, j) of the whole problem's constraint matrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions