0

For my consolidation problem in Cplex, I want to make the travel time (leadtime) from origin terminal to gateway terminal 'emerge' with a given probability. The transportation from gateway to the final destination will then depend on this outcome. Here is a simplified version of my code where x is 1 if order n is shipped from terminal i to terminal j at time t:

int leadtime[terminal, terminal] = ...;
dvar int+ x[terminal, terminal, time, order] in 0..1;

forall(i terminal, j in terminal, d in terminal, t in time, n in order) x[i,j,t,n] <= x[j,d,t+leadtime[i,j],n];

The leadtime between origin and gateway is equal to 1 time period in 80% of the times, for example, and equal to 2 time periods in the remaining 20% of the time. I want to include different probability distributions for this. Is there a way to model this?

Thank you very much in advance! Kind regards

FrT
  • 17
  • 3

2 Answers2

0

you can index your data with some scenarii and probabilities and then use array of your decisions variables per scenarii.

Very simple example in Making optimization simple

/*

Now let's suppose all those options have some probabilities and we need to book buses the day before but in real time in the morning we may book some additional buses with an extra price. (+10%) This is stochastic optimization. We want to minimize average cost. We call extra buses recourse variables. In OPL, it is quite simple to move from a deterministic model to a stochastic model: */

int nbKids=300;

{int} nbKidsScenarii={nbKids+i*10 | i in -10..2};
float proba[nbKidsScenarii]=[ 1, 1, 2, 2, 2 ,3 ,3 ,4,  5 ,10 ,50 ,10, 7];

assert sum(s in nbKidsScenarii) proba[s]==100; // total probability is 100

float costBus40=500;
float costBus30=400;

float costIncreaseIfLastMinute=1.1;

// number of buses booked in advance
dvar int+ nbBus40;
dvar int+ nbBus30;
// number of buses booked at the last minute which is far more expensive
// we call those recourse decision
dvar int+ nbBus40onTop[nbKidsScenarii] ;
dvar int+ nbBus30onTop[nbKidsScenarii] ;
 
minimize
 costBus40*nbBus40  +nbBus30*costBus30
 +
1/100*costIncreaseIfLastMinute*
sum(nbKids in nbKidsScenarii) proba[nbKids]*(costBus40*nbBus40onTop[nbKids]  +nbBus30onTop[nbKids]*costBus30);
 
subject to
{


 forall(nbKids in nbKidsScenarii)
   ctKids:40*(nbBus40+nbBus40onTop[nbKids])+(nbBus30+nbBus30onTop[nbKids])*30>=nbKids;
}

execute
{
writeln("nbBus40 = ",nbBus40);
writeln("nbBus30 = ",nbBus30);
writeln();
writeln("nbBus40 on top = ",nbBus40onTop);
writeln("nbBus30 on top = ",nbBus30onTop);
}

gives

// solution (optimal) with objective 3775.5
nbBus40 = 6
nbBus30 = 0
nbBus40 on top =  [0 0 0 0 0 0 0 0 1 0 0 1 2]
nbBus30 on top =  [0 0 0 0 0 1 1 1 0 2 2 1 0]
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Hi Alex, thank you very much for the clarification! Can you please explain what you mean in line 46 with `ctKids`. Kind regards and thanks again for your help so far! – FrT Apr 09 '21 at 17:40
  • ctKids is the name of the constraint which states that in each scenarii we have enough buses to bring all kids to the zoo. – Alex Fleischer Apr 09 '21 at 18:27
  • Hi Alex, thanks a lot! I have now modeled my leadtime as shown below. However, I do not see where I must put the proba[leadtime_scenarios]. Could you please help me out? Thank you in advance! – FrT Apr 10 '21 at 08:19
0

here is a part of my code:

int leadtime = 1;
{int} leadtime_scenarios = {leadtime + a | a in 0..1};
float proba[leadtime_scenarios] = [0.1,0.9];
assert sum(s in leadtime_scenarios) proba[s] == 1;

minimize sum(i in terminal, j in terminal, t in time, n in order) exp_fixed_cost_g[i,j,t,n];

forall(i terminal, j in terminal, d in terminal, t in time, n in order, s in scenario) x[i,j,t,n] <= x[j,d,t+leadtime[i,j,s],n];
forall(i in terminal, j in terminal, t in time, n in order) exp_fixed_cost_g[i,j,t,n] >= fixed_cost[i,j] - Z*(1-x[i,j,t,n]); //Z is a large value

Many thanks for your help. Kind regards

FrT
  • 17
  • 3