Skip to main content

Merging a binary decision variable with a continuous variable (semi-binary/continuous)

Answered

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?.
  • Eli Towle
    Gurobi Staff Gurobi Staff

    You can do this by setting the \( \texttt{vtype} \) keyword argument to a \( \texttt{dict} \) that maps each arc to either \( \texttt{GRB.CONTINUOUS} \) or \( \texttt{GRB.BINARY} \). For example:

    import random

    vtypes = {(i, j): GRB.CONTINUOUS if random.random() < 0.5 else GRB.BINARY for (i, j) in arcs}
    x = m.addVars(arcs, vtype=vtypes, name='x')

    If you want the continuous variables to be bounded above by \( 1 \), you should include the argument \( \texttt{ub=1} \) in your call to Model.addVars().

    Alternatively, you could:

    • Set the \( \texttt{vtype} \) argument equal to a list that's the same length as \( \texttt{arcs} \), or
    • After calling Model.addVars(), iterate over the variables and individually set their VType attributes.
    1
  • Vincent
    Gurobi-versary
    Curious
    Conversationalist

    Thanks very much for your quick and detailed response.

    0

Post is closed for comments.