0

I have seen comparable questions in other programming languages but haven't been able to solve the below in CPLEX.

I have two conditions that need to be met.

  1. Produced icecreams can only be used per flavoured batch of 60 and consumable for the same day.

forall(f in flavour, t in time) quantity of production quantity should be dividable by 60.

The code I tried below does not work.

forall(f in flavour, t in time) quantity[f][d] % 60 == 0;
  1. Outsourced icecreams can only be purchased per 5 units regardless of flavour

forall(t in time) quantity of outsourced ice creams should be dividable by 5

Can anyone help with one of the above functions?

BST
  • 11
  • 1

1 Answers1

0

modulo is not linear so you should introduce new decision variables.

See example Modulo from Making Optimization Simple

int nbKids=300;
float costBus40=500;
float costBus30=400;
 
dvar int+ nbBus40;
dvar int+ nbBus30;

dvar int+ nbBus40div3;
dvar int+ nbBus30div3;
 
minimize
 costBus40*nbBus40  +nbBus30*costBus30;
 
subject to
{
 40*nbBus40+nbBus30*30>=nbKids;
 
 // Plus let s add that numbers of buses have to be 3 multipliers
 
 nbBus40==3*nbBus40div3;
 nbBus30==3*nbBus30div3;
 
 
} 
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • 1
    Just to clarify the logic that Alex is using, in your case you want e.g. quantity[f][d] to be a multiple of 60. So you actually want an integer number of batches of 60. So you want to declare some integer variables something like dvar int+ nbBatches[f][d] and then add constraints something like quantity[f][d] = 60 * nbBatches[f][d] – TimChippingtonDerrick Nov 16 '21 at 08:40