import umontreal.iro.lecuyer.simevents.*; import umontreal.iro.lecuyer.simprocs.*; import umontreal.iro.lecuyer.rng.*; import umontreal.iro.lecuyer.randvar.*; import umontreal.iro.lecuyer.stat.Tally; /** * This example simulates the Cafeteria from * A. M. Law and W. D. Kelton, Simulation Modeling and Analysis, * Second Edition, McGraw-Hill, New York, 1991, * exercise 2.30, p. 224. */ public class Cafeteria { static final int Hotfood = 0; static final int Sandwich = 1; static final int Drinks = 2; static final double minHotST = 50.0; static final double maxHotST = 120.0; static final double minSandST = 60.0; static final double maxSandST = 180.0; static final double minDrinkST = 5.0; static final double maxDrinkST = 20.0; static final double minHotACT = 20.0; static final double maxHotACT = 40.0; static final double minSandACT = 5.0; static final double maxSandACT = 15.0; static final double minDrinkACT= 5.0; static final double maxDrinkACT= 10.0; static final double meanArr = 30.0; int NbCaisses; // Nb de caisses. double Nb; // Nb de clients dans le systeme. int NbAttente = 0; // Nb. en attente pour caisses. double NbHot, NbSand; // Nb. serveurs au HotFood et aux Sandwichs. RandomStream streamArr = new MRG32k3a(), streamGrSize = new MRG32k3a(), streamRoute = new MRG32k3a(), streamHotServ = new MRG32k3a(), streamSandServ = new MRG32k3a(), streamDrinksServ = new MRG32k3a(), streamHotACT = new MRG32k3a(), streamSandACT = new MRG32k3a(), streamDrinksACT = new MRG32k3a(); RandomVariateGen genArr = new ExponentialGen (streamArr, 1.0/meanArr); Resource HotServ = new Resource(1,"Service repas chauds"); Resource SandServ = new Resource(1,"Service sandwich"); Resource Caisse[] = new Resource[3]; Accumulate NbClients = new Accumulate ("Nb. de clients dans le systeme"); Accumulate CaissesNb = new Accumulate ("Nb. en attente pour les caisses"); Tally CaissesAttente = new Tally ("Temps d'attente pour caisses"); Tally AttClient[] = new Tally[3]; // Temps d'attente, par type de client. class ProcGenArr extends SimProcess { // Processus de generation des arrivees des clients. public void actions() { double u; while (true){ delay (genArr.nextDouble()); u = streamGrSize.nextDouble(); new ProcClient().schedule (0.0); if (u > 0.5) new ProcClient().schedule (0.0); if (u > 0.8) new ProcClient().schedule (0.0); if (u > 0.9) new ProcClient().schedule (0.0); } } } class ProcClient extends SimProcess { // Comportement d'un client. double u, ACT, TArr, Attente; int T; // Type de client public void actions() { Nb += 1.0; NbClients.update(Nb); TArr = Sim.time(); u = streamRoute.nextDouble(); if (u < 0.8) { T = Hotfood; HotServ.request(1); Attente = Sim.time() - TArr; delay (UniformGen.nextDouble (streamHotServ, minHotST/NbHot, maxHotST/NbHot)); HotServ.release (1); ACT = UniformGen.nextDouble (streamHotACT, minHotACT, maxHotACT); } else if ( u < 0.95) { T = Sandwich; SandServ.request (1); Attente = Sim.time() - TArr; delay (UniformGen.nextDouble (streamSandServ, minSandST/NbSand, maxSandST/NbSand)); SandServ.release (1); ACT = UniformGen.nextDouble (streamSandACT, minSandACT, maxSandACT); } else T = Drinks; delay (UniformGen.nextDouble (streamDrinksServ, minDrinkST, maxDrinkST)); ACT += UniformGen.nextDouble (streamDrinksACT, minDrinkACT, maxDrinkACT); int c = 0; // c sera la caisse choisie. for (int i=1; i