Skip to main content

Fix Certain Variables and Optimize the Rest

Ongoing

Comments

3 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi,

    You can fix variables by setting their lower bound and upper bound attributes to the same value, e.g.,

    x.lb = 5
    x.ub = 5

    You can use the chgCoeff function to change coefficients of linear constraints. The right-hand side of linear constraints can be changed via the RHS attribute. The objective coefficients of variables participating linearly in the objective function can be adjusted via the Obj attribute.

    If you are interested in fixing of integers only, you might want to have a look at the fixed function.

    Quadratic objects are more complex and you have to replace the quadratic constraint completely by adding a new one and removing the old one. However, you can change the right-hand side or the sense of a quadratic constraint via attributes without having the add and remove something.

    Best regards,
    Jaromił

     

    0
  • Bojing Jia
    Gurobi-versary
    First Comment
    First Question

    Is this possible for a matrix? ie.

    m = gp.Model("example")
    N = 10
    x = m.addMVar(N, vtype=GRB.CONTINUOUS, name='x')

    for i in range(N):
    x[i].lb = 5

    For reasons that are unclear to me, this returns the error: 

    IndexError: index 11 is out of bounds for axis 0 with size 10
    0

Post is closed for comments.