CP-SAT: Int/Boolean Constraint #3208
-
Hi, I am having trouble modelling a constraint. I have a list of boolean variables - x0, x1, ...x49(~50 variables) I want to have another variable to track the sum of the list of boolean variables: y = sum(x1, x2, ...x50) And if the sum of these 50 exceeds 20 (y>20), then I will set another new boolean variable z = true I tried something like this: ` b = model.NewBoolVar('b') # intermediate variable b implies sum of list is >20using b as intermediate variable for channelingmodel.Add(sum(xx[i] for i in range(50)) >20).OnlyEnforceIf(b) model.Add(z==1).OnlyEnforceIf(b) I didnt include y variable here but used b as an intermediate variable like what I read here: However, I am getting this error Is this the right way to create a variable based on other boolean variables? Appreciate any help !! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
works flawlessly you forgot the () after the last Not and in you example, you can simple set model.Add(z == b), or even better only use one variable. |
Beta Was this translation helpful? Give feedback.
works flawlessly
you forgot the () after the last Not
and in you example, you can simple set model.Add(z == b), or even better only use one variable.