# How can this relationship be modelled?

I declare an array of binary variables as $$y(i), i = 1, ..., N$$

I would like to model the following:

If $$y(i-1) + y(i) = 1$$ then $$y(k) = 0$$ for $$k < i$$ and $$y(m) = 1$$ for $$m \geq i$$

To make the question clear, here is an example:

Suppose I have the following 10 binary variables.

$$y(1), y(2), y(3), y(4), y(5), y(6), y(7), y(8), y(9), y(10)$$

The following is true: $$y(i-1) \leq y(i)$$ for $$i > 2$$

The optimiser is supposed to set the values of the variables in a pattern like the following: $$(y(1), y(2), y(3), y(4), y(5), y(6), y(7), y(8), y(9), y(10)) = ( 0,0,0,0,0,1,1,1,1,1)$$

I know that I will get a pattern like the one mentioned, but I don't know when the first $$1$$ will appear. I need to determine the variable $$y(i)$$ that gets first the value $$1$$ and then set all variables to its right to $$1$$ and all variables to its left to $$0$$. So I need to determine when $$y(i) + y(i-1) = 1$$, knowing that this implies $$y(i) = 1$$ and $$y(i-1)=0$$.

• Hi Marco How can I switch to math mode? Mar 11, 2020 at 23:23
• @Clement you can use LaTeX formatting using MathJax Mar 12, 2020 at 1:26
• Is it a solution? I just wonder if I missed something Mar 12, 2020 at 1:27
• It is a solution. I'm not guaranteeing it's a correct solution (though I think it is), but it seems to me you should post it as a solution and let the OP and/or the community weigh in by voting. Mar 12, 2020 at 1:27

## 2 Answers

New answer based on modified question. If you have constraints $$y_i \ge y_{i-1}$$, the value of $$y_i-y_{i-1}$$ indicates whether $$y_i+y_{i-1}=1$$, and this can happen only once.

• Hi Rob! You are right. The discussion sofar, before the modification, led me to that answer as well. Thank you all, especially Claudio and you! Mar 12, 2020 at 16:39

You could simply write $$y(i) - y(i - 1) \ge 0, \qquad i=2,...,N$$

• Yes, this does seem correct. The $m \ge i$ part implies that $(y_{i-1},y_i)\not=(1,0)$. Mar 12, 2020 at 1:52