# Decision Optimization

View Only

## Finding minimum of an array of variables but greater than 0

• #### 1.  Finding minimum of an array of variables but greater than 0

Posted Wed December 06, 2023 03:45 AM
Edited by Aarushi Gupta Wed December 06, 2023 05:39 AM

I have an array of variables and I want to find the minimum value in that array which is greater than 0.

Something like this:

``mdl.min([toy_var[i] for i in range(nb_toys) if toy_var[i]>0])``

But since I can't use such logical expressions on the variables, this does not work.

Any suggestions on how I can achieve this in docplex?

------------------------------
Aarushi Gupta
------------------------------

• #### 2.  RE: Finding minimum of an array of variables but greater than 0

Posted Wed December 06, 2023 06:24 AM

For example, you could use min(i in (0..nb_toys-1)) ((toy_var[i]>=1)*toy_var[i] +(toy_var[i]<=0) * BIG_NUMBER):

``````using CP;

int nb_toys = 4;
int BIG = 100000;
dvar int toy_var[0..nb_toys-1];
minimize min(i in (0..nb_toys-1)) ((toy_var[i]>=1)*toy_var[i] +(toy_var[i]<=0) * BIG);

subject to {
toy_var[0] >= 3;
toy_var[1] <= -1;
toy_var[2] >= 5;
toy_var[3] >= 1;
};
``````

------------------------------
Olivier Lhomme
------------------------------