# How to write a constraint to find the index of the min value in a set?

Consider this example with set A={100,50,150}. Min value in this set is 50. How to find out that the index of 50 is 2 in this set? I need 2 as the answer to put it in another constraint

• Are the entries in $A$ variables in your model?
– prubin
Mar 16 at 20:13
• Yes , A variables are answer of another constraint ! I want find index of min between them to put index number as input in next constraint .@prubin Mar 17 at 5:18

I think it likely would be an algorithmic way rather than being an optimization model. B.T.W, you can do what you want by the following MIP model:

$$\begin{array}{l} \text{Min} \ z = \sum_{i} A.val_i*x_i\\ \text{subject to:} \\ \sum_i x_i = 1\\ y_i = i .x_i \quad i=1, \ldots, m\\ x_{i} \in\{0,1\}, y_{i} \in \mathbb{Z}^+ \quad i\in m\\ \end{array}$$

As a simple example, with your data, the results are:

----     15 VARIABLE min_.L                =       50.000

----     15 VARIABLE x.L

50 1.000

----     15 VARIABLE y.L

50 2.000

• Or may be like $\max \sum_i a_ix_i$ s.t. $\sum_i a_ix_i \le a_i \quad \forall i= 1...n$ and ofcourse $y_i = \sum_i ix_i$ Mar 17 at 1:32
• I think its need sum(i in n) x[i]=1; isnt it ? Mar 17 at 9:10
• Since the A values are variables, the objective here is (nonconvex) quadratic. Fortunately, it can be linearized by the usual tricks, assuming that finite a priori bounds for the A variables exist.
– prubin
Mar 17 at 19:01