SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
InventoryCRN.java
1package tutorial;
2
3import umontreal.ssj.stat.Tally;
4import umontreal.ssj.util.Chrono;
5
6// Class to simulate and compare two different (S,s) policies with CRNs.
7public class InventoryCRN extends Inventory {
8
9 Tally statDiff = new Tally("stats on difference");
10
11 public InventoryCRN(double lambda, double c, double h, double K, double k, double p) {
12 super(lambda, c, h, K, k, p);
13 }
14
15 public void simulateDiffIRN(int n, int m, int s1, int S1, int s2, int S2) {
16 statDiff.init();
17 for (int i = 0; i < n; i++) {
18 double value1 = simulate(m, s1, S1);
19 double value2 = simulate(m, s2, S2);
20 statDiff.add(value2 - value1);
21 }
22 }
23
24 public void simulateDiffCRN(int n, int m, int s1, int S1, int s2, int S2) {
25 statDiff.init();
26 streamDemand.resetStartStream();
27 streamOrder.resetStartStream();
28 for (int i = 0; i < n; i++) {
29 double value1 = simulate(m, s1, S1);
30 streamDemand.resetStartSubstream();
31 streamOrder.resetStartSubstream();
32 double value2 = simulate(m, s2, S2);
33 statDiff.add(value2 - value1);
34 streamDemand.resetNextSubstream();
35 streamOrder.resetNextSubstream();
36 }
37 }
38
39 public static void main(String[] args) {
40 InventoryCRN system = new InventoryCRN(100.0, 2.0, 0.1, 10.0, 1.0, 0.95);
41 Chrono timer = new Chrono();
42
43 system.simulateDiffIRN(500, 2000, 80, 198, 80, 200);
44 system.statDiff.setConfidenceIntervalStudent();
45 System.out.println(system.statDiff.report(0.9, 3));
46 double varianceIndep = system.statDiff.variance();
47 System.out.println("Total CPU time: " + timer.format() + "\n");
48
49 timer.init();
50 system.simulateDiffCRN(500, 2000, 80, 198, 80, 200);
51 System.out.println(system.statDiff.report(0.9, 3));
52 double varianceCRN = system.statDiff.variance();
53 System.out.println("Total CPU time: " + timer.format());
54 System.out.printf("\nVariance ratio: %8.4g%n", varianceIndep / varianceCRN);
55 }
56}
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
double variance()
Returns the sample variance of the observations since the last initialization.
Definition Tally.java:174
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...
void init()
Initializes this AbstractChrono to zero.
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
Definition Chrono.java:37