0

Please suggest an algorithm or some direction to look into, to find optimal solution for the following problem:
Given n finite sets (of size at most 8) of natural numbers $V_i$ , choose only one $x_i$ from each set that will satisfy the following conditions:
$(x_1)\mod (32)\le d_1$ or $(x_1)\mod(32) \ge d_1+s_1 $
and
$(x_1+x_2)mod(32) \le d_2 $ or $(x_1+x_2)\mod(32) c\ge d_2+s_2 $
and so on ... till nth condition
$(x_1+x_2+...+x_n)\mod (32)\le d_n $
or
$(x_1+x_2+...+x_n)\mod (32)\ge d_n+s_n $
And sum of all $x_i$'s will be maximal.
Thanks in advance,
Denis

Davide Giraudo
  • 172,925
Denis
  • 1

1 Answers1

0

You can rather easily write it as a mixed-integer linear program. The function $z = x\mod k$ can be written as the constraint $z = x - ky, (x/k) - 1 \leq y \leq x/k$ where $y$ is a new decision variable.

The disjunction $z \leq d$ or $z\geq d + s$ can be implemented using a big-M model by introducing a binary variable $\delta$ and the constraints $z\leq d + M(1-\delta)$ and $z \geq d+s-M\delta$.

The remaining 7 constraints are done equivalently.

Johan Löfberg
  • 9,497
  • 1
  • 15
  • 15