Linearize Min Max Index in List as Constraint

55 Views Asked by At

I'm trying to solve an optimization problem by creating an optimization model (which I shall solve using CBC solver) and I need to linearize it. Please help me to reformulate it :

Given Data : A1, A2, A3, A4, ...... An

Ai is real number having value between 0 and 1. It can be 0 also or 1 also.

A1 + A2 + A3 + A4 + .... An = 1

Out of n, if 'n-1' A values are zero then 1 value of A will be equal to one because sum of A = 1. In such case, same Index to be returned for Max and Min.

Requirement : To Find out Index (i) of Maximum Value of A and To Find out Index (i) of Minimum Non-Zero Value of A.

Example1 : A1 = 0.3, A2 = 0.4, A3 = 0.1, A4 = 0.2, A5 = 0, A6 = 0

A1+A2+A3+A4+A5+A6 = 0.3+0.4+0.1+0.2+0+0 = 1.0

Max value of A=0.4 Hence return value = 2

Min Non-Zero value of A=0.1 Hence return value = 3

Required Output : 2 and 3

Example 2 : A1 = 0, A2 = 0, A3 = 1, A4 = 0, A5 = 0, A6 = 0

Max Value of A=1 Hence return value = 3

Min Non-Zero Value of A=1 Hence return value = 3

Required Output = 3 and 3

I have tried various methods like Using Big_M, Binary Variable (δ) etc but to no avail.

1

There are 1 best solutions below

0
On

Let binary variable $x_j$ indicate whether $A_j$ is the maximum, and impose linear constraints \begin{align} \sum_j x_j &= 1 \tag1\label1 \\ A_i - A_j &\le 1 - x_j &&\text{for all $i,j$ such that $i \not= j$} \tag2\label2 \end{align} Constraint \eqref{1} selects exactly one index for the maximum. Constraint \eqref{2} enforces $x_j = 1 \implies A_i \le A_j$. Then $\sum_j j x_j$ is the desired index.

Let $\epsilon > 0$ be a small constant tolerance for positivity. Let binary variable $y_j$ indicate whether $A_j>0$ is the minimum, and impose linear constraints \begin{align} \sum_j y_j &= 1 \tag3\label3 \\ \epsilon y_j &\le A_j &&\text{for all $j$} \tag4\label4 \\ A_j - A_i &\le 1 - y_j &&\text{for all $i,j$ such that $i \not= j$ and $A_i > 0$} \tag5\label5 \end{align} Constraint \eqref{3} selects exactly one index for the minimum. Constraint \eqref{4} enforces $y_j = 1 \implies 0 < A_j$. Constraint \eqref{5} enforces $y_j = 1 \implies A_j \le A_i$. Then $\sum_j j y_j$ is the desired index.