SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BatchMeansSim.java
1/*
2 * Class: BatchMeansSim
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Éric Buist
9 * @since 2007
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.simexp;
25
26import java.lang.ref.SoftReference;
27import cern.colt.list.DoubleArrayList;
28import cern.colt.matrix.DoubleMatrix1D;
29import cern.colt.matrix.DoubleMatrix2D;
30import umontreal.ssj.simevents.Event;
31import umontreal.ssj.simevents.Simulator;
32import umontreal.ssj.util.Misc;
33
156public abstract class BatchMeansSim extends SimExp {
157 private DoubleArrayList batchTimes = new DoubleArrayList();
158 private boolean batchLengths;
159 private boolean aggregation;
160 private int minBatches;
161 private int maxBatches;
162 private double warmupTime;
163 private EndSimEvent endSimEvent;
164
165 private boolean warmupDone;
166 private int targetBatches;
167 private int doneBatches;
168 private int droppedBatches;
169 private double batchFraction;
170 private double batchSizeMultiplier;
171 private boolean aggregateUpdated;
172 private double batchSize;
173
174 private int nAgr;
175
189 public BatchMeansSim(int minBatches, double batchSize, double warmupTime) {
190 this(minBatches, Integer.MAX_VALUE, batchSize, warmupTime);
191 }
192
207 public BatchMeansSim(int minBatches, int maxBatches, double batchSize, double warmupTime) {
208 this(Simulator.getDefaultSimulator(), minBatches, maxBatches, batchSize, warmupTime);
209 }
210
222 public BatchMeansSim(Simulator sim, int minBatches, double batchSize, double warmupTime) {
223 this(sim, minBatches, Integer.MAX_VALUE, batchSize, warmupTime);
224 }
225
238 public BatchMeansSim(Simulator sim, int minBatches, int maxBatches, double batchSize, double warmupTime) {
239 super(sim);
240 if (minBatches <= 0)
241 throw new IllegalArgumentException("minBatches <= 0");
242 if (maxBatches < minBatches)
243 throw new IllegalArgumentException("maxBatches < minBatches");
244 if (warmupTime < 0)
245 throw new IllegalArgumentException("Warmup time must not be negative");
246 if (batchSize <= 0)
247 throw new IllegalArgumentException("Batch size must not be 0 or negative");
248 this.minBatches = minBatches;
249 this.maxBatches = maxBatches;
250 this.warmupTime = warmupTime;
251 this.batchSize = batchSize;
252 targetBatches = minBatches;
253 }
254
263 public boolean getBatchAggregation() {
264 return aggregation;
265 }
266
275 public void setBatchAggregation(boolean a) {
276 if (warmupDone && simulating)
277 throw new IllegalStateException("Cannot change the aggregation status during simulation");
278 aggregation = a;
279 }
280
288 public boolean getBatchLengthsKeeping() {
289 return batchLengths;
290 }
291
300 public void setBatchLengthsKeeping(boolean b) {
301 if (warmupDone && simulating)
302 throw new IllegalStateException("Cannot change the aggregation status during simulation");
303 batchLengths = b;
304 }
305
313 public int getMinBatches() {
314 return minBatches;
315 }
316
324 public void setMinBatches(int minBatches) {
325 if (minBatches <= 0)
326 throw new IllegalArgumentException("minBatches <= 0");
327 this.minBatches = minBatches;
328 if (maxBatches < minBatches)
329 maxBatches = minBatches;
330 }
331
341 public int getMaxBatches() {
342 return maxBatches;
343 }
344
353 public void setMaxBatches(int maxBatches) {
354 if (maxBatches < minBatches)
355 throw new IllegalArgumentException("maxBatches < minBatches");
356 this.maxBatches = maxBatches;
357 }
358
367 public double getBatchSize() {
368 return batchSize;
369 }
370
377 public void setBatchSize(double batchSize) {
378 if (batchSize <= 0)
379 throw new IllegalArgumentException("batchSize <= 0");
380 this.batchSize = batchSize;
381 }
382
390 public double getWarmupTime() {
391 return warmupTime;
392 }
393
401 public void setWarmupTime(double warmupTime) {
402 if (warmupTime < 0)
403 throw new IllegalArgumentException("warmupTime < 0");
404 this.warmupTime = warmupTime;
405 }
406
427 public double getBatchFraction() {
428 return batchFraction;
429 }
430
443 public double getBatchSizeMultiplier() {
444 return batchSizeMultiplier;
445 }
446
456 public int getTargetBatches() {
457 return targetBatches;
458 }
459
470 public void setTargetBatches(int targetBatches) {
471 if (targetBatches < minBatches)
472 throw new IllegalArgumentException("Target number of batches too small");
473 if (targetBatches > maxBatches)
474 throw new IllegalArgumentException("Target number of batches too large");
475 this.targetBatches = targetBatches;
476 }
477
484 return doneBatches;
485 }
486
498 return droppedBatches;
499 }
500
509 public void dropFirstRealBatches(int n) {
510 if (n < 0 || n > doneBatches - droppedBatches)
511 throw new IllegalArgumentException(
512 "Cannot drop less than 0 or more than " + (doneBatches - droppedBatches) + " real batches");
513 if (batchLengths || aggregation)
514 batchTimes.removeFromTo(0, n - 1);
515 droppedBatches += n;
516 }
517
526 public int getBatch(double time) {
527 if (!warmupDone)
528 return -1;
529 if (!batchLengths && !aggregation)
530 return -1;
531 if (batchTimes.size() == 0)
532 return -1;
533 return Misc.getTimeInterval(batchTimes.elements(), 0, doneBatches, time);
534 }
535
541 public boolean isWarmupDone() {
542 return warmupDone;
543 }
544
555 public int getNumAggregates() {
556 if (nAgr == 0)
557 throw new IllegalStateException("Number of real batches not available");
558 return nAgr;
559 }
560
573 public double getRealBatchLength(int batch) {
574 if (batchLengths || aggregation)
575 // The first get will fail if batch + 1 is out of bounds.
576 // If the first get succeeds, the second will, so we can
577 // use getQuick to eliminate a check.
578 return batchTimes.get(batch + 1 - droppedBatches) - batchTimes.getQuick(batch - droppedBatches);
579 else if (batch != doneBatches - 1)
580 throw new IllegalArgumentException("Unavailable batch length");
581 else
582 return batchTimes.getQuick(1) - batchTimes.getQuick(0);
583 }
584
591 public double getRealBatchStartingTime(int batch) {
592 if (batchLengths || aggregation)
593 return batchTimes.get(batch);
594 else if (batch != doneBatches - 1)
595 throw new IllegalArgumentException("Unavailable batch time");
596 else
597 return batchTimes.getQuick(0);
598 }
599
606 public double getRealBatchEndingTime(int batch) {
607 if (batchLengths || aggregation)
608 return batchTimes.get(batch + 1);
609 else if (batch != doneBatches - 1)
610 throw new IllegalArgumentException("Unavailable batch time");
611 else
612 return batchTimes.getQuick(1);
613 }
614
633 public void allocateCapacity(int capacity) {
634 throw new UnsupportedOperationException();
635 }
636
668 public void regroupRealBatches(int x) {
669 throw new UnsupportedOperationException();
670 }
671
672 private final void allocateCapacity() {
673 // Preallocate the necessary memory to store
674 // all the observations when using fixed
675 // number of batches.
676 // A maximal number of batches is used
677 // to prevent memory overflow problems.
678 // Unfortunately, in Java, we can only
679 // use heuristics to prevent the memory
680 // problem. In addition to a maximum
681 // number of batches, we use a soft reference
682 // that will be cleared before the OutOfMemoryError
683 // is thrown.
684 // The size of the referent can be tuned; it is only
685 // an heuristic.
686 SoftReference<?> softRef = new SoftReference<double[]>(new double[50000]);
687 batchFraction = 1.0;
688 batchSizeMultiplier = 1.0;
689 int currentCapacity = doneBatches;
690 while (currentCapacity < targetBatches && softRef.get() != null) {
691 // Try to double the capacity
692 int newCapacity = Math.min(2 * currentCapacity + 1, targetBatches);
693 // Since we want all collectors to have the same capacity
694 // we must not stop the for loop if the softRef
695 // is cleared.
696 if (aggregation || batchLengths)
697 batchTimes.ensureCapacity(newCapacity + 1);
698 try {
699 allocateCapacity(newCapacity);
700 } catch (UnsupportedOperationException use) {
701 return;
702 }
703 currentCapacity = newCapacity;
704 }
705 if (currentCapacity < targetBatches && softRef.get() == null) {
706 if (!aggregation)
707 throw new IllegalStateException("Cannot increase batch size");
708 // The soft reference was cleared.
709 // The memory taken by the simulation
710 // could crash the program.
711 // To try avoiding that, we will stop taking memory
712 // by increasing the batch size.
713 double ftargetBatches = targetBatches;
714 double fdoneBatches = doneBatches;
715 while (targetBatches > currentCapacity) {
716 batchSizeMultiplier *= 2;
717 // From now, we can have a fraction of batches done
718 fdoneBatches /= 2;
719 ftargetBatches /= 2;
720 targetBatches = (int) ftargetBatches;
721 doneBatches = (int) fdoneBatches;
722 if (aggregation || batchLengths) {
723 for (int i = 0; i < batchTimes.size() / 2; i++)
724 batchTimes.setQuick(i, batchTimes.getQuick(2 * i));
725 batchTimes.setSize(batchTimes.size() / 2);
726 }
728 // Compute the remaining fraction of batch to simulate
729 batchFraction = 1.0 - (fdoneBatches - doneBatches);
730 }
731 // Round the new total number of batches to a multiple
732 // of minBatches.
733 if (targetBatches % minBatches != 0) {
734 targetBatches /= minBatches;
735 targetBatches *= minBatches;
736 targetBatches += minBatches;
737 }
738 }
739 }
740
745 public abstract void initSimulation();
746
751 public abstract void initBatchStat();
752
757 public abstract void initRealBatchProbes();
758
764 public abstract void initEffectiveBatchProbes();
765
770 public abstract void addRealBatchObs();
771
779 public abstract void addEffectiveBatchObs(int s, int h, double l);
780
797 return 0;
798 }
799
805 public void init() {
806 if (simulating)
807 throw new IllegalStateException("Already simulating");
808 nAgr = 0;
809 warmupDone = false;
810 doneBatches = 0;
811 droppedBatches = 0;
812 if (targetBatches < minBatches)
813 targetBatches = minBatches;
814 if (aggregation && targetBatches % minBatches != 0) {
815 targetBatches /= minBatches;
816 targetBatches += minBatches;
817 if (targetBatches + minBatches <= maxBatches)
818 targetBatches += minBatches;
819 }
820 aggregateUpdated = false;
821 simulator().init();
822 endSimEvent = new EndSimEvent(simulator());
824 }
825
831 return endSimEvent;
832 }
833
843 public void warmup() {
844 warmup(warmupTime);
845 }
846
856 public void warmup(double warmupTime) {
857 if (warmupDone)
858 throw new IllegalStateException("Warmup already done");
859 if (!Double.isInfinite(warmupTime) && !Double.isNaN(warmupTime))
860 endSimEvent.schedule(warmupTime);
861 simulator().start();
862 endSimEvent.cancel();
864 if (!aggregation)
866 if (aggregation || batchLengths) {
867 batchTimes.setSize(0);
868 batchTimes.add(simulator().time());
869 } else {
870 batchTimes.setSize(2);
871 batchTimes.trimToSize();
872 batchTimes.setQuick(0, simulator().time());
873 batchTimes.setQuick(1, simulator().time());
874 }
875 warmupDone = true;
876 }
877
889 public void simulateBatch() {
890 double f = getBatchSizeMultiplier();
891 if (f > 1)
892 batchSize *= f;
893 simulateBatch(batchSize * getBatchFraction());
894 }
895
906 public void simulateBatch(double batchLength) {
908 endSimEvent.schedule(batchLength);
909 simulator().start();
910 endSimEvent.cancel();
911 batchFraction = 1.0;
912 batchSizeMultiplier = 1.0;
913 aggregateUpdated = false;
914 ++doneBatches;
915 if (batchLengths || aggregation)
916 batchTimes.add(simulator().time());
917 else {
918 batchTimes.setQuick(0, batchTimes.getQuick(1));
919 batchTimes.setQuick(1, simulator().time());
920 }
922 if (!aggregation) {
923 nAgr = 1;
924 addEffectiveBatchObs(doneBatches - 1, 1, getRealBatchLength(doneBatches - 1));
925 }
926 }
927
935 public void adjustTargetBatches(int numNewBatches) {
936 if (doneBatches + numNewBatches > maxBatches) {
937 numNewBatches = maxBatches - doneBatches;
938 if (aggregation && numNewBatches < minBatches)
939 // We must simulate at least minBatches real batches, so
940 // do nothing
941 return;
942 }
943 if (aggregation) {
944 // For effective batches to change,
945 // we need to simulate at least minBatches additional real batches.
946 // The number of new batches is therefore rounded to
947 // the smallest multiple greater than or
948 // equal to minBatches.
949 if (numNewBatches % minBatches != 0) {
950 numNewBatches /= minBatches;
951 numNewBatches *= minBatches;
952 if (doneBatches + numNewBatches + minBatches <= maxBatches)
953 numNewBatches += minBatches;
954 }
955 }
956 targetBatches = doneBatches + numNewBatches;
957 }
958
967 public void simulateBatches() {
968 if (doneBatches < targetBatches)
969 // Increased the target number of required batches
970 // and allocate memory to store the observations
971 // if this is required.
973 while (doneBatches < targetBatches)
974 // targetBatches may be changed by a simulation event.
975 // This can be used to stop the simulation before the
976 // desired number of batches is obtained, e.g., when
977 // the simulated system seems unstable.
979 if (aggregation)
980 makeAggregateBatches();
981 }
982
989 public void simulate() {
990 init();
991 simulating = true;
992 try {
993 warmup(warmupTime);
994 while (doneBatches < targetBatches) {
997 }
998 if (aggregation && !aggregateUpdated)
999 makeAggregateBatches();
1000 } finally {
1001 simulating = false;
1002 }
1003 }
1004
1005 private final void makeAggregateBatches() {
1006 // When using fixed number of batches, we must
1007 // add the observations to statistical collectors
1008 // only at the end of the simulation.
1010 // nAgr gives the number of real batches in each effective batch
1011 nAgr = (doneBatches - droppedBatches) / minBatches;
1012 // tnb gives the number of observations in the statistical counters
1013 int tnb = minBatches;
1014 if (nAgr == 0) {
1015 // doneBatches is smaller than minBatches, but we would like
1016 // observations to be collected and displayed.
1017 // We will have less than minBatches observations.
1018 nAgr = 1;
1019 tnb = doneBatches - droppedBatches;
1020 }
1021 for (int i = 0; i < tnb; i++) {
1022 int startAgr = i * nAgr + droppedBatches;
1023 addEffectiveBatchObs(startAgr, nAgr,
1024 batchTimes.getQuick(startAgr - droppedBatches + nAgr) - batchTimes.getQuick(startAgr - droppedBatches));
1025 }
1026 aggregateUpdated = true;
1027 }
1028
1029 private static final class EndSimEvent extends Event {
1030 public EndSimEvent(Simulator sim) {
1031 super(sim);
1032 }
1033
1034 public void actions() {
1035 simulator().stop();
1036 }
1037 }
1038
1039 public String toString() {
1040 StringBuffer sb = new StringBuffer(getClass().getName());
1041 sb.append('[');
1042 sb.append("minimal number of batches: ").append(minBatches);
1043 if (maxBatches < Integer.MAX_VALUE)
1044 sb.append(", maximal number of batches: ").append(maxBatches);
1045 sb.append(", target number of batches: ").append(targetBatches);
1046 sb.append(", warmup time: ").append(warmupTime);
1047 if (simulating)
1048 sb.append(", simulation in progress");
1049 else
1050 sb.append(", simulation stopped");
1051 if (warmupDone)
1052 sb.append(", number of completed batches: ").append(doneBatches);
1053 else
1054 sb.append(", warmup not completed");
1055 if (aggregation)
1056 sb.append(", batch aggregation turned ON");
1057 else {
1058 sb.append(", batch aggregation turned OFF");
1059 if (batchLengths)
1060 sb.append(", batch lengths are kept");
1061 else
1062 sb.append(", batch lengths are not kept");
1063 }
1064 sb.append(']');
1065 return sb.toString();
1066 }
1067
1083 public static double getSum(double[] a, int start, int length) {
1084 if (start < 0)
1085 throw new IndexOutOfBoundsException("start must not be negative");
1086 if (length < 0)
1087 throw new IllegalArgumentException("length is negative");
1088 if (start + length > a.length)
1089 throw new IndexOutOfBoundsException("Not enough elements in the array");
1090 double s = 0;
1091 for (int i = start; i < start + length; i++)
1092 s += a[i];
1093 return s;
1094 }
1095
1110 public static double getSum(DoubleArrayList l, int start, int length) {
1111 if (start < 0)
1112 throw new IndexOutOfBoundsException("start must not be negative");
1113 if (length < 0)
1114 throw new IllegalArgumentException("length is negative");
1115 if (start + length > l.size())
1116 throw new IndexOutOfBoundsException("Not enough elements in the array list");
1117 double s = 0;
1118 for (int i = start; i < start + length; i++)
1119 s += l.getQuick(i);
1120 return s;
1121 }
1122
1137 public static double getSum(DoubleMatrix1D m, int start, int length) {
1138 if (start < 0)
1139 throw new IndexOutOfBoundsException("start must not be negative");
1140 if (length < 0)
1141 throw new IllegalArgumentException("length is negative");
1142 if (start + length > m.size())
1143 throw new IndexOutOfBoundsException("Not enough elements in the matrix");
1144 double s = 0;
1145 for (int i = start; i < start + length; i++)
1146 s += m.getQuick(i);
1147 return s;
1148 }
1149
1168 public static double[] getSum(double[][] a, int startColumn, int numColumns) {
1169 if (a.length == 0)
1170 return new double[0];
1171 if (startColumn < 0)
1172 throw new IndexOutOfBoundsException("startColumn must not be negative");
1173 if (numColumns < 0)
1174 throw new IllegalArgumentException("numColumns is negative");
1175 if (startColumn + numColumns > a[0].length)
1176 throw new IndexOutOfBoundsException("Not enough elements in the array");
1177 double[] res = new double[a.length];
1178 for (int i = 0; i < res.length; i++)
1179 for (int j = startColumn; j < startColumn + numColumns; j++)
1180 res[i] += a[i][j];
1181 return res;
1182 }
1183
1199 public static double[] getSum(DoubleMatrix2D m, int startColumn, int numColumns) {
1200 if (startColumn < 0)
1201 throw new IndexOutOfBoundsException("startColumn must not be negative");
1202 if (numColumns < 0)
1203 throw new IllegalArgumentException("numColumns is negative");
1204 if (startColumn + numColumns > m.columns())
1205 throw new IndexOutOfBoundsException("Not enough columns in the matrix");
1206 double[] res = new double[m.rows()];
1207 for (int i = 0; i < res.length; i++)
1208 for (int j = startColumn; j < startColumn + numColumns; j++)
1209 res[i] += m.getQuick(i, j);
1210 return res;
1211 }
1212
1226 public static void regroupElements(double[] a, int x) {
1227 if (x < 1)
1228 throw new IllegalArgumentException("x < 1");
1229 int gs = a.length / x;
1230 for (int i = 0; i < gs; i++) {
1231 double o = 0;
1232 for (int j = 0; j < x; j++)
1233 o += a[i * x + j];
1234 a[i] = o;
1235 }
1236 int m = a.length % x;
1237 if (m > 0) {
1238 double o = 0;
1239 int r = a.length - x * gs;
1240 for (int j = 0; j < r; j++)
1241 o += a[gs * x + j];
1242 a[gs] = o;
1243 ++gs;
1244 }
1245 for (int i = gs; i < a.length; i++)
1246 a[i] = 0;
1247 }
1248
1258 public static void regroupElements(DoubleArrayList l, int x) {
1259 if (x < 1)
1260 throw new IllegalArgumentException("x < 1");
1261 int gs = l.size() / x;
1262 for (int i = 0; i < gs; i++) {
1263 double o = 0;
1264 for (int j = 0; j < x; j++)
1265 o += l.getQuick(i * x + j);
1266 l.setQuick(i, o);
1267 }
1268 int m = l.size() % x;
1269 if (m > 0) {
1270 double o = 0;
1271 int r = l.size() - x * gs;
1272 for (int j = 0; j < r; j++)
1273 o += l.getQuick(gs * x + j);
1274 l.setQuick(gs, o);
1275 ++gs;
1276 }
1277 l.setSize(gs);
1278 }
1279
1288 public static void regroupElements(DoubleMatrix1D mat, int x) {
1289 if (x < 1)
1290 throw new IllegalArgumentException("x < 1");
1291 int gs = mat.size() / x;
1292 for (int i = 0; i < gs; i++) {
1293 double o = 0;
1294 for (int j = 0; j < x; j++)
1295 o += mat.getQuick(i * x + j);
1296 mat.setQuick(i, o);
1297 }
1298 int m = mat.size() % x;
1299 if (m > 0) {
1300 double o = 0;
1301 int r = mat.size() - x * gs;
1302 for (int j = 0; j < r; j++)
1303 o += mat.getQuick(gs * x + j);
1304 mat.setQuick(gs, o);
1305 ++gs;
1306 }
1307 for (int i = gs; i < mat.size(); i++)
1308 mat.setQuick(i, 0);
1309 }
1310
1320 public static void regroupElements(DoubleMatrix2D mat, int x) {
1321 if (x < 1)
1322 throw new IllegalArgumentException("x < 1");
1323 int gs = mat.columns() / x;
1324 for (int i = 0; i < gs; i++) {
1325 for (int r = 0; r < mat.rows(); r++) {
1326 double o = 0;
1327 for (int j = 0; j < x; j++)
1328 o += mat.getQuick(r, i * x + j);
1329 mat.setQuick(r, i, o);
1330 }
1331 }
1332 int m = mat.columns() % x;
1333 if (m > 0) {
1334 int r = mat.columns() - x * gs;
1335 for (int row = 0; row < mat.rows(); row++) {
1336 double o = 0;
1337 for (int j = 0; j < r; j++)
1338 o += mat.getQuick(row, gs * x + j);
1339 mat.setQuick(row, gs, o);
1340 }
1341 ++gs;
1342 }
1343 for (int row = 0; row < mat.rows(); row++)
1344 for (int i = gs; i < mat.columns(); i++)
1345 mat.setQuick(row, i, 0);
1346 }
1347}
This abstract class provides event scheduling tools.
Definition Event.java:53
abstract void actions()
This is the method that is executed when this event occurs.
final Simulator simulator()
Returns the simulator linked to this event.
Definition Event.java:256
Represents the executive of a discrete-event simulator.
void stop()
Tells the simulation executive to stop as soon as it takes control, and to return control to the prog...
void start()
Starts the simulation executive.
void init()
Reinitializes the simulation executive by clearing up the event list, and resetting the simulation cl...
static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated class.
boolean getBatchAggregation()
Returns true if the aggregation of batches is turned ON.
void setBatchLengthsKeeping(boolean b)
Sets the batch lengths keeping indicator to b.
void warmup()
Performs a warmup by calling warmup(double).
void dropFirstRealBatches(int n)
Drops the n first real batches to save memory.
double getRealBatchEndingTime(int batch)
Returns the ending simulation time of batch batch.
Event getEndSimEvent()
Returns the event used to stop the simulation at the end of the warmup or batches.
static void regroupElements(DoubleMatrix2D mat, int x)
Same as regroupElements(double[],int) for a 2D matrix.
abstract void initRealBatchProbes()
Initializes any statistical collector for real batches.
void setBatchAggregation(boolean a)
Sets the batch aggregation indicator to a.
double getBatchFraction()
Returns the remaining fraction of batch to be simulated.
abstract void initBatchStat()
Resets the counters used for computing observations during the simulation at the beginning of a new b...
void setWarmupTime(double warmupTime)
Sets the warmup time to warmupTime.
void simulateBatch(double batchLength)
Simulates a batch with length batchLength.
BatchMeansSim(int minBatches, double batchSize, double warmupTime)
Constructs a new batch means simulator using at least minBatches batches with size batchSize,...
BatchMeansSim(Simulator sim, int minBatches, double batchSize, double warmupTime)
Equivalent to the first constructor, with a user-defined simulator sim.
abstract void addEffectiveBatchObs(int s, int h, double l)
Adds an observation to each statistical collector corresponding to an effective batch.
double getRealBatchLength(int batch)
Returns the length, in simulation time units, of the real batch batch.
double getBatchSize()
Returns the current batch size as defined for this simulator.
int getMaxBatches()
Returns , the maximal number of batches to be used for estimating the steady-state performance measur...
int getTargetBatches()
Returns the target number of simulated real batches at the next time the stopping condition is checke...
void allocateCapacity(int capacity)
Allocates the necessary memory for storing capacity real batches.
static void regroupElements(DoubleMatrix1D mat, int x)
Same as regroupElements(double[],int) for a 1D matrix.
int getBatch(double time)
Returns the real batch corresponding to simulation time time when batch lengths are kept.
static double getSum(DoubleArrayList l, int start, int length)
Returns the sum of elements start, …, start + length - 1, in the array list l.
static void regroupElements(double[] a, int x)
Regroups the elements in array a by summing each successive x values.
int getMinBatches()
Returns the minimal number of batches required for estimating the steady-state performance measures o...
static double getSum(DoubleMatrix1D m, int start, int length)
Returns the sum of elements start, …, start + length - 1, in the 1D matrix m.
void setMaxBatches(int maxBatches)
Sets the maximal number of batches to maxBatches.
void setMinBatches(int minBatches)
Sets the minimal number of batches to minBatches.
int getCompletedRealBatches()
Returns the number of completed real batches since the beginning of the run.
static double getSum(double[] a, int start, int length)
Returns the sum of elements start, …, start + length - 1, in the array a.
abstract void addRealBatchObs()
Collects values of a vector concerning the last simulated real batch.
void simulateBatch()
Simulate a new batch with default length.
abstract void initEffectiveBatchProbes()
Initializes any statistical collector for effective batches.
boolean getBatchLengthsKeeping()
Indicates that the length, in simulation time units, of each real batch has to be kept.
static double[] getSum(double[][] a, int startColumn, int numColumns)
Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1,...
BatchMeansSim(int minBatches, int maxBatches, double batchSize, double warmupTime)
Constructs a batch means simulator with a maximum of maxBatches batches to avoid excessive memory usa...
void init()
Initializes the simulator for a new experiment.
void simulateBatches()
Simulates batches until the number of completed real batches corresponds to the target number of batc...
double getRealBatchStartingTime(int batch)
Returns the starting simulation time of batch batch.
boolean isWarmupDone()
Determines if the warmup period for the simulation is over.
static void regroupElements(DoubleArrayList l, int x)
Same as regroupElements(double[],int) for an array list.
abstract void initSimulation()
Initializes the simulator for a new run.
void setBatchSize(double batchSize)
Sets the batch size to batchSize.
void setTargetBatches(int targetBatches)
Sets the target number of simulated batches before an error check or the end of the simulation to tar...
static double[] getSum(DoubleMatrix2D m, int startColumn, int numColumns)
Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1,...
void warmup(double warmupTime)
Performs a warmup of fixed duration warmupTime.
double getBatchSizeMultiplier()
Returns the batch size multiplier after the simulation of a new batch.
BatchMeansSim(Simulator sim, int minBatches, int maxBatches, double batchSize, double warmupTime)
Equivalent to the second constructor, with a user-defined simulator sim.
void regroupRealBatches(int x)
Regroups real batches x by x.
int getDroppedRealBatches()
Returns the number of real batches dropped.
int getNumAggregates()
Returns , the number of real batches contained into an effective batch.
void simulate()
Performs a batch means simulation.
void adjustTargetBatches(int numNewBatches)
Adjusts the target number of real batches to simulate numNewBatches additionnal real batches.
int getRequiredNewBatches()
Computes the approximate number of required real batches to be simulated before the simulation can be...
double getWarmupTime()
Returns the duration of the warmup period for the simulation.
boolean simulating
Determines if the simulation is in progress.
Definition SimExp.java:50
SimExp()
Constructs a new object for performing experiments using the default simulator returned by Simulator....
Definition SimExp.java:56
final Simulator simulator()
Returns the simulator linked to this experiment object.
Definition SimExp.java:77
This class provides miscellaneous functions that are hard to classify.
Definition Misc.java:33
static int getTimeInterval(double[] times, int start, int end, double t)
Returns the index of the time interval corresponding to time t.
Definition Misc.java:173
String getName(int series)
Gets the current name of the selected series.