Skip to main content

Fix Certain Variables and Optimize the Rest

Ongoing

Comments

2 comments

  • 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

Please sign in to leave a comment.