Skip to main content

Different upper bound and lower bound for a list of variables

Answered

Comments

2 comments

  • Ruoyun Chen
    Gurobi-versary
    First Comment
    First Question

    I guess a more easier way is to change the upper bound and lower bound for the existing variables. How should I do that?

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Ruoyun,

    You can use variable attributes to set the lower and upper bounds after you added the variables to your model.

    An example would be

    import gurobipy 
    from gurobipy import *

    m = Model('test')
    Candidate = [(1,1), (1,2), (1,3), (2,1), (2,2), (2,3)]
    load = m.addVars(Candidate, name="load")

    for c in Candidate:
    if c[0] > 1: # if first number of the tuple is > 1
    load[c].lb = -2 # some lower bound
    if c[1] < 2: # if second number of the tuple is <2
    load[c].ub = 3 # some upper bound

    m.write("myLP.lp") # write LP file to check whether it worked

    Best regards,
    Jaromił

    2

Please sign in to leave a comment.