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
------------------------------
Original Message:
Sent: Wed December 06, 2023 03:44 AM
From: Aarushi Gupta
Subject: Finding minimum of an array of variables but greater than 0
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?
#DecisionOptimization#docplex#AIandDSSkills
------------------------------
Aarushi Gupta
------------------------------