[Python] Binary indicator variable related to another variable

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    In PulP modeling, I have an integer variable s that can take on values 0, 1, or 2. I want a binary indicator variable y such that y=1 if s=0 or s=2, and y=0 if s=1.

    I tried defining three binary variables z1, z2, and y, and setting up these constraints:

    z1 <= s <= 2 * z1

    2z2 <= s s < 2z2 + 2

    y = z1 * (1 - z2)

    Essentially, z1=1 means s>0, and z2=0 means s<2. Hence y=1 means s=1, and y=0 means s=0 or 2.

    However, this makes y non-linear, since it is a product of 2 variables.

    Is there a way to define y using only linear constraints?

    Continue reading...

Compartilhe esta Página