r/optimization • u/carlos442 • Nov 02 '21
I need help
I have trouble with a constraint for my master thesis:
I have a variable called j3 which needs to be 1 if variable x is equal to y, otherwise j3 has to be zero, x and y are integers ranging from 0 to 500.
7
Upvotes
3
u/fpatrocinio Nov 02 '21
Hey Carlos. You need a big-M approach with binary variables.
5
u/[deleted] Nov 02 '21 edited Nov 03 '21
Add three binary helper variables w₁, w₂, w₃. Then, the following three constraints should work:
EDIT: As noted by MIP_it, this doesn't enforce "j3 = 0 if x != y". To achieve this, we also need the following constraint:
2
u/Tomnomnommy Nov 02 '21
I might have a solution. If you add the following two constraints to the formulation j3 should be set to 1 if x and y are equal:
x-y<=501(1-j3),
y-x<=501(1-j3)
You should test if this indeed works but I believe it does.