5

I'm modeling a problem where I have a set of binary decision variables $x_{ij}$ that has a value of 1 if the person $i$ is allocated to day $j$ or 0 otherwise.

I have another set of binary decision variables $n_{jk}$ that has a value of 1 if the $j$'s day has $k$ persons assigned to it.

I need a way to force the $n_{jk}$ to 1 if the $\sum x_{ij} = k$, 0 otherwise.

EhsanK
  • 5,864
  • 3
  • 17
  • 54
dhfg
  • 53
  • 2
  • Welcome to OR.SE! Have you looked at other related questions on the site, such as this one? – EhsanK Dec 28 '22 at 15:01
  • Thank you, yes I have, but I had to insert another binary variable in my model, it worked too. But the answer by @RobPratt worked as well without additional variables. Thank you again. – dhfg Dec 28 '22 at 17:28

1 Answers1

7

\begin{align} \sum_k n_{jk} &= 1 &&\text{for all $j$} \tag1\label1 \\ \sum_k k n_{jk} &= \sum_i x_{ij} &&\text{for all $j$} \tag2\label2 \end{align} Constraint \eqref{1} selects one count for each day. Constraint \eqref{2} makes the selected count consistent with $x$ for each day.

RobPratt
  • 32,006
  • 1
  • 44
  • 84