coin-or / Clp

COIN-OR Linear Programming Solver
Other
396 stars 82 forks source link

Add coefficient of new variable to existing constraint #171

Open svrouwenvelder opened 3 years ago

svrouwenvelder commented 3 years ago

While using the C interface to link CLP to Java, I stumbled upon the fact that constraints can not be extended with new variables.

Given a constraint a*x1 + b*x2 <= 5.0. After introducing a new variable x3, then it is not possible to introduce x3 in the aforementioned constraint. With the function Clp_resize (see Clp_C_Interface.h) one can resize the rim part of the model, though the following three functions do not allow for the addition of a new variable:

Clp_getIndices (i.e. [0,1,2,0,1,2,3] Clp_getVectorStarts (i.e. [0,3,6,7] Clp_getVectorLengths (i.e. [3,3,1]

(the example implies that x1 is in constraint 0,1 and 2, x2 is in 0,1 and 2; x3 is only in constraint 3)

Would it be an option/ beneficial for CLP to have this flexibility (i.e. resize constraints with new variables, setting their coefficients to 0 by default)?

It is very well possible to create a new constraint with variable x3. As in my code CLP is part of an iterative process, my code removes the old constraint and introduce a copy of it with the desired changes.