メインコンテンツへスキップ

Different upper bound and lower bound for a list of variables

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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?.
  • 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

    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

投稿コメントは受け付けていません。