Skip to main content

how to add new coloumns into the left side of constraints?

Answered

Comments

1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    You can get the LHS of a linear constraint by calling the getRow() method, which will return a LinExpr object.

    However, what you need in your case is the Column object, which you fill with the respective coefficients and constraints via the addTerms method and then you can call the addVar method and pass this Column object to add the variable to the constraint of interest with pre-defined coefficients.

    In your particular example, this would be something like

    colx3 = gp.Column()
    colx4 = gp.Column()
    colx3.addTerms([a5, a7, 1.0], [c1, c2, c3])
    colx4.addTerms([a6, a8, 1.0], [c1, c2, c3])

    x3 = model.addVar(..., column = colx3)
    x4 = model.addVar(..., column = colx4)

    Please note that the Column object works only with linear constraints.

    Best regards, 
    Jaromił

     

    0

Please sign in to leave a comment.