I have a binary variable X_i and an integer variable Y_i
I want to use Y as a counter in such a way that Y_i is reset to 0 every time X_i = 1
Is it possible to find constraints that would allow me to do it ?
Here is an example :
X : 001011001
Y : 120100120
edit :
Here are the constraints I find, using a linearization of
y(i) = (y(i-1)+1)*(1-x(i))
:
y[1] == (1-x[1])
for i in 2:N
y[i] <= 10000*(1-x[i])
y[i] <= y[i-1] + 1
y[i] >= y[i-1] + 1 - 10000*x[i]
And here are some results I get
x : 0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1
y : 1,2,3,4,5,6,7,8,0,1,2,3,0,1,0,0,0,-9999
or
x : 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1
y : 1,2,3,4,5,6,7,8,9,0,-9999,-19998,-29997,-39996,-49995,-49994,-59993,-69992
What am I doing wrong ?