Hi Guys,
I need to update the model sligtly - boolean ExIsBetween1and11 should be true when variable x is in range 0 < x < 12 (previously it was only single condition x < 12).
I have two questions:
1. I thought the easiest way would be by using XOR:
x = [[model.NewIntVar(0, 100, "") for j in all_j] for i in all_i]
ExIsBetween1and11 = [[model.NewBoolVar("") for j in all_j] for i in all_i]
for j in all_i:
for i in all_j:
model.AddBoolXOr([x[i][j] == 0, x[i][j] >= 12, ExIsBetween1and11[i][j]])
But I got TypeError: NotSupported: model.GetOrMakeBooleanIndex(unnamed_var_0 == 0).
How to do it in the right way?
I tried to make some literals, like below (probably incorrectly), but it did not work:
ExIsZero = x[i][j] == 0
ExIsAtLeast12 = x[i][j] >=12
Should I make more BoolVars, like:
ExIsZero = [[model.NewBoolVar("") for j in range(all_j)] for i in range(all_i)]
ExIsAtLeast12 = [[model.NewBoolVar("") for j in range(all_j)] for i in range(all_i)]
And then
for j in all_i:
for i in all_j:
model.Add(x[i][j] == 0).OnlyEnforceIf(ExIsZero[i][j])
model.Add(x[i][j] != 0).OnlyEnforceIf(ExIsZero[i][j].Not())
model.Add(x[i][j] >= 12).OnlyEnforceIf(ExIsAtLeast12[i][j])
model.Add(x[i][j] < 12).OnlyEnforceIf(ExIsAtLeast12[i][j].Not())
model.AddBoolXOr([ExIsZero[i][j], ExIsAtLeast12[i][j], ExIsBetween1and11[i][j]])
I thought it would be overkill, but maybe it cannot be done more easily?.
2. What would be the most efficient (in terms of optimization/processor efficiency) way of achievieng the mentioned condition (ExIsBetween1and11 == True when 0 < x < 12)?
a) A way descripted above (with XOR and maybe anyhow correct literals instead of all those BoolVars)?
b) Using OnlyEnforceIf, like a variant of:
model.Add(ExIsBetween1and11[i][j]).OnlyEnforceIf([x[i][j] != 0, x[i][j] >=12])
c) using implication, like a variant of:
model.AddImplication([x[i][j] != 0, x[i][j] >=12], ExIsBetween1and11[i][j])
Probably it could be done with some correct literals (instead of all those BoolVars), but in none of my trials I could make it work.
Could you tell me what is the right approach?