# Integer decision variables as index

The following problem has only two integer variables; however, they appear in the index of the parameters. Appreciate it if anyone has any efficient idea to transform it into a canonical integer programming model.

\begin{alignat*}{2} &&\max \quad & (d_y - d_x)^2 \\ &&\text{s.t.} \quad & d_y - d_x \geq \alpha \\ && & x,y \in \mathbb{Z}_+ \\ \end{alignat*}

• $d:\mathbb{Z}_+ \to \mathbb{R}$ is a fixed sequence? – RobPratt Aug 18 '20 at 17:34
• @RobPratt. Yes. – Mohammad Namakshenas Aug 18 '20 at 17:37
• OK, canonical integer programming does not allow an infinite amount of input. Do you have any upper bound on $x$ and $y$? Or maybe a formula that defines $d$? – RobPratt Aug 18 '20 at 17:45
• @RobPratt. Yes. We have upper bounds on $x$ and $y$. – Mohammad Namakshenas Aug 18 '20 at 17:59

Suppose $$x,y\in\{0,\dots,n\}$$. I think I would just loop over these $$(n+1)^2$$ pairs and keep the best one that satisfies the constraint.
But if you insist on integer programming, introduce binary variables $$x_i$$ and $$y_i$$ for $$i\in\{0,\dots,n\}$$, with the interpretation that $$d_x=\sum_i d_i x_i$$ and $$d_y=\sum_i d_i y_i$$. The problem is to maximize $$\left(\sum_i d_i (y_i - x_i)\right)^2$$ subject to \begin{align} \sum_i x_i &= 1\\ \sum_i y_i &= 1\\ \sum_i d_i (y_i - x_i) &\ge \alpha \end{align} If you want, you can linearize the objective.