Skip to content

Optimization Problem with Array Index as decision variable

An answer to this question on the Scientific Computing Stack Exchange.

Question

I am trying to formulate an optimization problem where the decision variable is an index of the input array as part of the formulation.

For example, I have the following term (this is simplified):

$A[ max_t ( \alpha[t] * t ) ] $

  • A is an input 1D-array
  • $\alpha[t]$ is the integer decision variable

So my questions are:

  1. Is it correct to formulate an optimization problem where the decision variable is used to index a value in the input
  2. If the answer is yes, what solver allows such format?
  3. I tried Gekko solver, but I could not implement it, for example, a tiny code for Gekko:

x = [0, 1, 2, 3, -100, -500]

then if I try:

x[alpha[i]*(i)]

It would fails to run as the index of x must be an integer rather than a Gekko operator.

Edit:

For the original problem, I have decision variable $\alpha[t]$ and it gets assigned 0 and 1 as its an integer variable.

Then, $\forall t$ , I want to find $t'$, where $t'$ is the last time where $\alpha[t]$ is 1 such that $t'<t$, then I want to use $x[t']$ in a constraint (e.g. $x[t] - x[t'] > 0$)

Answer

Can you do the following?

xc = x0*xb1 + x1*xb1 + ...
SOS1(xb)

That is, associate each value of your x array with a binary variable and put these binary variables into a Type 1 SOS collection (special ordered set). That will ensure that only one of the binary variables is true at a time, effectively selecting one element from the array.