Skip to main content

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

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff

    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.

  • Jaromił Najman
    • 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

Post is closed for comments.