I have an array of decision variables that represent an amount of product. I want that each of them could be 0 (if it is not selected) or in some interval ([0.2;0.8]). forall is not working.
{string} Produkti = ...;
{string} Vielas = ...;
float Izmaksas[Produkti] = ...;
float vielVertibas[Produkti][Vielas]= ...;
float Normas[Vielas]= ...;
dvar float+ prodApjoms[Produkti];
minimize
sum(p in Produkti) Izmaksas[p] * prodApjoms[p];
subject to{
forall(v in Vielas) sum (p in Produkti) vielVertibas[p][v] * prodApjoms[p] >= Normas[v]*0.95;
forall(v in Vielas) sum (p in Produkti) vielVertibas[p][v] * prodApjoms[p] <= (Normas[v]*1.05);
sum (p in Produkti) prodApjoms[p] <= 15;
sum (p in Produkti) prodApjoms[p] >= 5;
}
forall(p in Produkti)
(prodApjoms[p]==0) || ((0.2<=prodApjoms[p]) && (prodApjoms[p]<=0.8));
will do the job
And full working example in https://github.com/AlexFleischerParis/zooopl/blob/master/zoosemiinteger.mod
int nbKids=300;
float costBus40=500;
float costBus30=400;
dvar int+ nbBus40;
dvar int+ nbBus30;
minimize
costBus40*nbBus40 +nbBus30*costBus30;
subject to
{
(nbBus40==0) || (4<=nbBus40<=20);
(nbBus30==0) || (4<=nbBus30<=20);
40*nbBus40+nbBus30*30>=nbKids;
}
/*
which gives
nbBus40 = 8;
nbBus30 = 0;
*/