SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
Inventory.java
1package tutorial;
2
3import umontreal.ssj.rng.*;
4import umontreal.ssj.randvar.*;
5import umontreal.ssj.probdist.PoissonDist;
6import umontreal.ssj.stat.Tally;
7import umontreal.ssj.util.*;
8
9public class Inventory {
10
11 double lambda; // Mean demand size for a day.
12 double c; // Sale price per item.
13 double h; // Inventory cost per item per day.
14 double K; // Fixed ordering cost per order.
15 double k; // Marginal ordering cost per item.
16 double p; // Probability that an order arrives.
17
18 RandomVariateGenInt genDemand;
19 RandomStream streamDemand = new MRG32k3a();
20 RandomStream streamOrder = new MRG32k3a();
21 Tally statProfit = new Tally("stats on profit");
22
23 public Inventory(double lambda, double c, double h, double K, double k, double p) {
24 this.lambda = lambda;
25 this.c = c;
26 this.h = h;
27 this.K = K;
28 this.k = k;
29 this.p = p;
30 genDemand = new PoissonGen(streamDemand, new PoissonDist(lambda));
31 }
32
33 // Simulates the system for m days, with the (s,S) policy,
34 // and returns the average profit per day.
35 public double simulate(int m, int s, int S) {
36 int Xj = S; // Stock in the morning.
37 int Yj; // Stock in the evening.
38 double profit = 0.0; // Cumulated profit.
39 for (int j = 0; j < m; j++) {
40 Yj = Xj - genDemand.nextInt(); // Subtract demand for the day.
41 if (Yj < 0)
42 Yj = 0; // Lost demand.
43 profit += c * (Xj - Yj) - h * Yj;
44 if ((Yj < s) && (streamOrder.nextDouble() < p)) {
45 // We have a successful order.
46 profit -= K + k * (S - Yj);
47 Xj = S;
48 } else
49 Xj = Yj;
50 }
51 return profit / m;
52 }
53
54 // Performs n independent simulation runs of the system for m days,
55 // with the (s,S) policy, and returns a report with a 90% confidence
56 // interval on the expected average profit per day.
57 public void simulateRuns(int n, int m, int s, int S) {
58 for (int i = 0; i < n; i++)
59 statProfit.add(simulate(m, s, S));
60 }
61
62 public static void main(String[] args) {
63 Inventory system = new Inventory(100.0, 2.0, 0.1, 10.0, 1.0, 0.95);
64 Chrono timer = new Chrono();
65 system.simulateRuns(500, 2000, 80, 200);
66 system.statProfit.setConfidenceIntervalStudent();
67 System.out.println(system.statProfit.report(0.9, 3));
68 System.out.println("Total CPU time: " + timer.format() + "\n");
69 }
70}
Extends the class DiscreteDistributionInt for the Poisson distribution slaw00a  (page 325) with mean.
This class implements random variate generators having the Poisson distribution.
This is the base class for all generators of discrete random variates over the set of integers.
Extends the abstract class RandomStreamBase by using as a backbone (or main) generator the combined m...
Definition MRG32k3a.java:46
A subclass of StatProbe.
Definition Tally.java:47
void setConfidenceIntervalStudent()
Indicates that a confidence interval on the true mean, based on the normality assumption,...
Definition Tally.java:582
String report()
Returns a formatted string that contains a report on this probe.
Definition Tally.java:397
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
Definition Chrono.java:37
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...