Skip to main content

linear constraint of semi-continuous variable

Answered

Comments

3 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.
  • Jaromił Najman
    • Gurobi Staff

    Hi Bahar,

    You can model \(x\) directly as a semicontinuous variable in Gurobi with lower bound \(u_1\) and upper bound \(u_2\). You can then model a conditional statement if \(x \geq \frac{u_1}{2}\) then  \(z=1\) and \(z=0\) else. With this, you can define \(y\) as \(y=b_0 z + b_1 x\). To avoid numerical issues, \(u_1\) should have a value strictly above the FeasibilityTol value. A pseudo Python code could look something like

    u_1 = 2
    u_2 = 4
    b0 = 1
    b1 = 3

    x = model.addVar(lb=u_1, ub=u_2, vtype=GRB.SEMICONT, name="x")
    z = model.addVar(vtype=GRB.BINARY, name="z")
    y = model.addVar(name="y")

    model.addConstr(x >= 0.5*u_1 - u_2*(1-z), name="cond_constr1")
    model.addConstr(x <= 0.5*u_1 + u_2*z, name="cond_constr2")
    model.addConstr(y == b0*z + b1*x)

    With the above, if \(x=0\), then \(z=0\) and \(z=1\) else. Thus, \(y=0\) if \(x=0\) and \(y = b_0\cdot 1 + b_1\cdot x\) else.

    Best regards, 
    Jaromił

     

    0
  • Bahar Nasirian
    • Gurobi-versary
    • Conversationalist
    • Curious

    Thank you for your guidance.

     

    Regards,

    Bahar

    0

Post is closed for comments.