Skip to main content

linear constraint of semi-continuous variable

Answered

Comments

2 comments

  • Jaromił Najman
    Gurobi Staff 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
    Conversationalist
    Curious
    Gurobi-versary

    Thank you for your guidance.

     

    Regards,

    Bahar

    0

Please sign in to leave a comment.