'CPLEX - getting minimum of a set of variables over a condition

I have to solve the following problem using CPLEX Java API:

I need to write a condition that will return a minimum of a set of integer variables (let's say x[i], i=1,2,...,n) but considering only the positive ones.

In other words:

min{x[i] | x[i]>0}

I know that CPLEX has the minimum function, but the problem is how to pass it the mentioned condition.



Solution 1:[1]

Create a single continuous variable. Add constraints that this new variable must be <= all of the integer variables. Then just maximise the continuous variable.

Solution 2:[2]

TimChippingtonDerrick's answer is missing the non-negativity constraint for the continuous variable. Moreover, that method does not accommodate the OP's original objective function.

An (expensive) way of doing this is to introduce additional binary variables, one for each integer variable and write big M constraints:

x[i] >= y >= x[i] - M(1-z[i])

SUM(i,z[i]) = 1

Solution 3:[3]

you have to create expression to use min function in cplex this is example to chose minimum value between two value to be greater than 0.3

IloCplex cplex = new IloCplex();
            IloNumVar x1 = cplex.numVar(0.1, Double.MAX_VALUE, "x1");
            IloNumVar x2 = cplex.numVar(0.2, Double.MAX_VALUE, "x2");
IloLinearNumExpr y=cplex.linearNumExpr() ;
            cplex.addGe(cplex.min(x1, x2),0.3);

Solution 4:[4]

In OPL CPLEX I would write

int n=10;

dvar int x[1..n];

dvar int m;

subject to
{
  m==min(i in 1..n) maxl(0,x[i]);

}

but you could do the same with java

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Nehme
Solution 2 Lal
Solution 3 Nada ALainiah
Solution 4 Alex Fleischer