Good morning ! I would like to implement this constraint using CP-SAT (see image below).
x_i,j is a boolean variable, a and b are given. The problem is that I don't know how to implement the indicator function in a constraint. I tried with int() function but it cannot be applied with a BoundedLinearExpression. Here is my code:
for i in range(20):
for j in range(30):
x[(i,j)] = model.NewBoolVar('variable%ii%ij' % (i,j))
model.Add(a <= sum( int( sum(x[(i,j)] for j in range(30)) >= 5 ) for i in range(20) ) <= b)
Any idea on how to solve it ?
b = [model.NewBoolVar('b%i' % (i)) for i in range(20)] for i in range(20): model.Add( sum(x[(i,j)] for j in range(30) ) >= 5).OnlyEnforceIf(b[i])
So now I have all my indicator functions, but I struggle a bit for the second sum. Is it simply this following line that I need to add ?model.AddLinearConstraint(sum(b[i] for i in range(20)), a, b)
$\endgroup$