Skip to main content

Adding new variables to existing model

Answered

Comments

8 comments

  • Official comment
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Marika Karbstein
    • Gurobi Staff

    Hi Jonas,

    The lines

    for j in second_set:
    x[3,j] = m.addVar(3,j, vtype=GRB.CONTINUOUS)

    add variables with lower bound 3 and upper bound j=0/1/2 which is infeasible.

    In general, the article How do I determine why my model is infeasible? might help.

    Best regards,
    Marika

    0
  • Marika Karbstein
    • Gurobi Staff

    You probably wanted to do something like

    x[3] = m.addVars(second_set, vtype=GRB.CONTINUOUS)

    which adds multiple variables without defining specific bounds?

    0
  • Jonas Grundler
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi Marika,

    thanks, this helps!
    However, the new variables are not forced to fulfill the following constraint:

    m.addConstrs(quicksum(x[i,j] for j in second_set) >= 1 for i in first_set)

    How can I change this? Thanks!

    Best wishes,
    Jonas

    0
  • Marika Karbstein
    • Gurobi Staff
    In your example, it was not clear that "3" is an index of first_set and that you need a variable for each pair of first_set, second_set.
    Did you try
    x = m.addVars(first_set, second_set, vtype=GRB.CONTINUOUS)
    ?
    Then your constraints should work.
    0
  • Jonas Grundler
    • Gurobi-versary
    • Conversationalist
    • First Question

    Yes, I tried, but unfortunately it does not work. Do I have to use the 'column' attribute here? Or is there a more convenient way?

    0
  • Marika Karbstein
    • Gurobi Staff

    Ok, I see.
    Yes, you need to use the column argument like in the feasopt.py example (see also Modify a model) and add the variables individually with addVar().

    0
  • Jonas Grundler
    • Gurobi-versary
    • Conversationalist
    • First Question

    Okay, I see. Thanks a lot!

    0

Post is closed for comments.