SSJ
V. labo.

umontreal.iro.lecuyer.simexp
Class BatchMeansSim

java.lang.Object
  extended by umontreal.iro.lecuyer.simexp.SimExp
      extended by umontreal.iro.lecuyer.simexp.BatchMeansSim

public abstract class BatchMeansSim
extends SimExp

Performs a simulation experiment on an infinite horizon, for estimating steady-state performance measures, using batch means. Batches are delimited using a user-specified condition such as a fixed duration in simulation time units (the default), the number of occurrences of an event such as the arrival of a customer, a regenerative cycle, etc. After the condition for batch termination is defined, the batch size can be set. This size can be, depending on how batches are delimited, a time duration, a number of events, or 1 for regenerative cycles. The batch length is defined to be the duration of a batch, in simulation time units, independently of how batches are defined. By default, the batch size and the batch length are equivalent (and constant), but they may differ if the condition for batch termination is changed.

A warmup period is usually simulated to reduce the bias induced by the initial state of the system. During the warmup, the system runs without any observation being collected. By default, this period has a duration fixed in simulation time units, but this can also be changed.

After the warmup is over, events are counted as follows. The simulation model defines some counters being updated when events occur and reset at the beginning of each batch. At the end of a batch, the value of these counters are used to generate a random vector Vj before the counters are reset. Alternatively, a simulation may compute and update the Vj's directly, without using intermediate counters. A set of data structures is needed to collect and store these Vj's, the simplest option being a set of TallyStore instances. This generates values for m real batches. The sample (X0,…, Xn-1) is then obtained from (V0,…,Vm-1), so a second set of data structures is needed to collect the Xr's, the simplest being a set of Tally instances. The most straightforward way to estimate covariances on components of Xr is by considering the vectors Xr i.i.d., which is not true in general. However, by choosing a sufficiently large simulation time and batch lengths, the correlation between batches can be reduced, and the Xr's are approximately i.i.d. and normally distributed. If batches correspond to regenerative cycles, the Xr are then truly i.i.d., but only approximately normally distributed. Confidence intervals on functions of μ can be approximated using the central limit theorem, as with independent replications, or using the delta theorem for functions of multiple means or when batches have different lengths.

The sample size corresponding to the number of simulated batches is always fixed when sequential sampling is not used; we have n = m and Xr = Vr for r = 0,…, n - 1. However, when sequential sampling is used, the sample size can be random or fixed. If the sample size is random, we still have Xr = Vr. When using this mode, the batch size must be chosen carefully to reduce correlation between batches.

On the other hand, if the sample size n is required to be fixed while sequential sampling is used, batch aggregation must be activated to have effective batches with random lengths. When aggregation is enabled, real batches are simulated as usual, but the obtained values Vj are regrouped (or aggregated) to form effective batches. The number of real batches must be m = h*n to get a sample of size n, and h can be any integer greater than or equal to 1. In this case,

Xr = ∑k=0h-1Vhr+k.

The size of the effective batches increases while the sample size remains fixed because the group size h increases with simulation length. When aggregation is used, the effective batches become longer while simulation time increases, and the correlation between effective batches should decrease with simulation time. However, the increment to the target number of batches must always be a multiple of the sample size, which can lead to useless simulation if the sample size is large.

This class must be extended to implement a batch means simulator, and the appropriate methods must be defined or overridden. This class uses a simulation event to stop the simulation at the end of the warmup period and batches. One can use this event for fixed-duration warmup and batches, or schedule their own events which call Sim.stop to end warmup or batches. To change how the warmup period is terminated, one must override the method warmup. For the batch termination condition to be redefined, simulateBatch must be overridden.

One must implement initSimulation to initialize the simulated model before the warmup, initBatchStat to reset the model-specific counters used to compute the Vj's, initRealBatchProbes and addRealBatchObs to initialize statistical probes and add observations for real batches, initEffectiveBatchProbes and addEffectiveBatchObs to initialize statistical probes and add observations for effective batches.

The moment the latter methods are called depends on the status of batch aggregation: when aggregation is turned ON, before any error check or the end of the simulation, initEffectiveBatchProbes is called once before addEffectiveBatchObs is called n successive times, with different parameters. When aggregation is turned OFF, then method initEffectiveBatchProbes is called after the warmup is over, and addEffectiveBatchObs is called each time a batch ends, after addRealBatchObs is called.

If sequential sampling is used, getRequiredNewBatches must be overridden to implement error checking. In some particular situations, the user may also need to override allocateCapacity and regroupRealBatches.


Constructor Summary
BatchMeansSim(int minBatches, double batchSize, double warmupTime)
          Constructs a new batch means simulator using at least minBatches batches with size batchSize, with a warmup period of duration warmupTime.
BatchMeansSim(int minBatches, int maxBatches, double batchSize, double warmupTime)
          Constructs a batch means simulator with a maximum of maxBatches batches to avoid excessive memory usage and too long simulations when using sequential sampling.
BatchMeansSim(Simulator sim, int minBatches, double batchSize, double warmupTime)
          Equivalent to the first constructor, with a user-defined simulator sim.
BatchMeansSim(Simulator sim, int minBatches, int maxBatches, double batchSize, double warmupTime)
          Equivalent to the second constructor, with a user-defined simulator sim.
 
Method Summary
abstract  void addEffectiveBatchObs(int s, int h, double l)
          Adds an observation to each statistical collector corresponding to an effective batch.
abstract  void addRealBatchObs()
          Collects values of a Vj vector concerning the last simulated real batch.
 void adjustTargetBatches(int numNewBatches)
          Adjusts the target number of real batches to simulate numNewBatches additionnal real batches.
 void allocateCapacity(int capacity)
          Allocates the necessary memory for storing capacity real batches.
 void dropFirstRealBatches(int n)
          Drops the n first real batches to save memory.
 int getBatch(double time)
          Returns the real batch corresponding to simulation time time when batch lengths are kept.
 boolean getBatchAggregation()
          Returns true if the aggregation of batches is turned ON.
 double getBatchFraction()
          Returns the remaining fraction of batch to be simulated.
 boolean getBatchLengthsKeeping()
          Indicates that the length, in simulation time units, of each real batch has to be kept.
 double getBatchSize()
          Returns the current batch size as defined for this simulator.
 double getBatchSizeMultiplier()
          Returns the batch size multiplier after the simulation of a new batch.
 int getCompletedRealBatches()
          Returns the number of completed real batches since the beginning of the run.
 int getDroppedRealBatches()
          Returns the number of real batches dropped.
 Event getEndSimEvent()
          Returns the event used to stop the simulation at the end of the warmup or batches.
 int getMaxBatches()
          Returns M, the maximal number of batches to be used for estimating the steady-state performance measures of interest.
 int getMinBatches()
          Returns the minimal number of batches required for estimating the steady-state performance measures of interest.
 int getNumAggregates()
          Returns h, the number of real batches contained into an effective batch.
 double getRealBatchEndingTime(int batch)
          Returns the ending simulation time of batch batch.
 double getRealBatchLength(int batch)
          Returns the length, in simulation time units, of the real batch batch.
 double getRealBatchStartingTime(int batch)
          Returns the starting simulation time of batch batch.
 int getRequiredNewBatches()
          Computes the approximate number of required real batches to be simulated before the simulation can be stopped.
static double[] getSum(double[][] a, int startColumn, int numColumns)
          Returns an array containing the sum of columns startColumn, ..., startColumn + numColumns - 1, in the 2D matrix represented by the 2D array a.
static double getSum(double[] a, int start, int length)
          Returns the sum of elements start, ..., start + length - 1, in the array a.
static double getSum(cern.colt.list.DoubleArrayList l, int start, int length)
          Returns the sum of elements start, ..., start + length - 1, in the array list l.
static double getSum(cern.colt.matrix.DoubleMatrix1D m, int start, int length)
          Returns the sum of elements start, ..., start + length - 1, in the 1D matrix m.
static double[] getSum(cern.colt.matrix.DoubleMatrix2D m, int startColumn, int numColumns)
          Returns an array containing the sum of columns startColumn, ..., startColumn + numColumns - 1, in the 2D matrix m.
 int getTargetBatches()
          Returns the target number of simulated real batches at the next time the stopping condition is checked.
 double getWarmupTime()
          Returns the duration of the warmup period for the simulation.
 void init()
          Initializes the simulator for a new experiment.
abstract  void initBatchStat()
          Resets the counters used for computing observations during the simulation at the beginning of a new batch.
abstract  void initEffectiveBatchProbes()
          Initializes any statistical collector for effective batches.
abstract  void initRealBatchProbes()
          Initializes any statistical collector for real batches.
abstract  void initSimulation()
          Initializes the simulator for a new run.
 boolean isWarmupDone()
          Determines if the warmup period for the simulation is over.
static void regroupElements(double[] a, int x)
          Regroups the elements in array a by summing each successive x values.
static void regroupElements(cern.colt.list.DoubleArrayList l, int x)
          Same as regroupElements for an array list.
static void regroupElements(cern.colt.matrix.DoubleMatrix1D mat, int x)
          Same as regroupElements for a 1D matrix.
static void regroupElements(cern.colt.matrix.DoubleMatrix2D mat, int x)
          Same as regroupElements for a 2D matrix.
 void regroupRealBatches(int x)
          Regroups real batches x by x.
 void setBatchAggregation(boolean a)
          Sets the batch aggregation indicator to a.
 void setBatchLengthsKeeping(boolean b)
          Sets the batch lengths keeping indicator to b.
 void setBatchSize(double batchSize)
          Sets the batch size to batchSize.
 void setMaxBatches(int maxBatches)
          Sets the maximal number of batches to maxBatches.
 void setMinBatches(int minBatches)
          Sets the minimal number of batches to minBatches.
 void setTargetBatches(int targetBatches)
          Sets the target number of simulated batches before an error check or the end of the simulation to targetBatches.
 void setWarmupTime(double warmupTime)
          Sets the warmup time to warmupTime.
 void simulate()
          Performs a batch means simulation.
 void simulateBatch()
          Simulate a new batch with default length.
 void simulateBatch(double batchLength)
          Simulates a batch with length batchLength.
 void simulateBatches()
          Simulates batches until the number of completed real batches corresponds to the target number of batches.
 String toString()
           
 void warmup()
          Performs a warmup by calling warmup.
 void warmup(double warmupTime)
          Performs a warmup of fixed duration warmupTime.
 
Methods inherited from class umontreal.iro.lecuyer.simexp.SimExp
getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservationsTally, getRequiredNewObservationsTally, isSimulating, setSimulator, simulator
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BatchMeansSim

public BatchMeansSim(int minBatches,
                     double batchSize,
                     double warmupTime)
Constructs a new batch means simulator using at least minBatches batches with size batchSize, with a warmup period of duration warmupTime. By default, batch aggregation and batch lengths keeping are turned off, and the maximal number of batches is infinite.

Parameters:
minBatches - the minimal number of batches to simulate.
batchSize - the size of the batches.
warmupTime - the duration of the warmup period.
Throws:
IllegalArgumentException - if the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

BatchMeansSim

public BatchMeansSim(int minBatches,
                     int maxBatches,
                     double batchSize,
                     double warmupTime)
Constructs a batch means simulator with a maximum of maxBatches batches to avoid excessive memory usage and too long simulations when using sequential sampling. See BatchMeansSim for more information about the other parameters.

Parameters:
minBatches - the minimal number of batches to simulate.
maxBatches - the maximal number of batches to simulate.
batchSize - the size of the batches.
warmupTime - the duration of the warmup period.
Throws:
IllegalArgumentException - if the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

BatchMeansSim

public BatchMeansSim(Simulator sim,
                     int minBatches,
                     double batchSize,
                     double warmupTime)
Equivalent to the first constructor, with a user-defined simulator sim.

Parameters:
sim - the simulator attached to this object.
minBatches - the minimal number of batches to simulate.
batchSize - the size of the batches.
warmupTime - the duration of the warmup period.
Throws:
IllegalArgumentException - if the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

BatchMeansSim

public BatchMeansSim(Simulator sim,
                     int minBatches,
                     int maxBatches,
                     double batchSize,
                     double warmupTime)
Equivalent to the second constructor, with a user-defined simulator sim.

Parameters:
sim - the simulator attached to this object.
minBatches - the minimal number of batches to simulate.
maxBatches - the maximal number of batches to simulate.
batchSize - the size of the batches.
warmupTime - the duration of the warmup period.
Throws:
IllegalArgumentException - if the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.
Method Detail

getBatchAggregation

public boolean getBatchAggregation()
Returns true if the aggregation of batches is turned ON. If getRequiredNewBatches always returns 0 (the default), the aggregation has no effect since the number of batches is not random. By default, batch aggregation is turned OFF.

Returns:
the batch aggregation indicator.

setBatchAggregation

public void setBatchAggregation(boolean a)
Sets the batch aggregation indicator to a. This should not be called during an experiment.

Parameters:
a - the new batch aggregation indicator.
Throws:
IllegalStateException - if the warmup period is over, and simulation is not terminated.

getBatchLengthsKeeping

public boolean getBatchLengthsKeeping()
Indicates that the length, in simulation time units, of each real batch has to be kept. By default, this is set to false. When batch aggregation is turned ON, the batch lengths are always kept.

Returns:
the batch lengths keeping indicator.

setBatchLengthsKeeping

public void setBatchLengthsKeeping(boolean b)
Sets the batch lengths keeping indicator to b. This has no impact if batch aggregation is turned ON.

Parameters:
b - the new value of the indicator.
Throws:
IllegalStateException - if the warmup period is over and simulation is not terminated.

getMinBatches

public int getMinBatches()
Returns the minimal number of batches required for estimating the steady-state performance measures of interest. If aggregation is turned ON, this is also the final number of effective batches, i.e., the sample size.

Returns:
the minimal number of batches.

setMinBatches

public void setMinBatches(int minBatches)
Sets the minimal number of batches to minBatches.

Parameters:
minBatches - the new minimal number of batches.
Throws:
IllegalArgumentException - if the specified minimal number of batches is smaller than 0.

getMaxBatches

public int getMaxBatches()
Returns M, the maximal number of batches to be used for estimating the steady-state performance measures of interest. This is used to prevent the number of batches from growing indefinitely when using sequential sampling. By default, this is set to MAX_VALUE, which is equivalent to infinity in practice.

Returns:
the maximal number of batches.

setMaxBatches

public void setMaxBatches(int maxBatches)
Sets the maximal number of batches to maxBatches.

Parameters:
maxBatches - the new maximal number of batches.
Throws:
IllegalArgumentException - if the maximal number of batches is smaller than the actual minimal number of batches.

getBatchSize

public double getBatchSize()
Returns the current batch size as defined for this simulator. By default, this is a duration in simulation time units. Depending on the batch termination condition, which can be changed by overriding simulateBatch, it can be the number of occurrences of an event, or 1 for regenerative cycles.

Returns:
the current batch size.

setBatchSize

public void setBatchSize(double batchSize)
Sets the batch size to batchSize.

Parameters:
batchSize - the new batch size.
Throws:
IllegalArgumentException - if the given batch size is negative or 0.

getWarmupTime

public double getWarmupTime()
Returns the duration of the warmup period for the simulation. By default, this duration is expressed in simulation time units, but this can be changed by overriding warmup.

Returns:
the warmup time for the simulation.

setWarmupTime

public void setWarmupTime(double warmupTime)
Sets the warmup time to warmupTime. If this method is called while a simulation is in progress, the new time will affect the next simulation only.

Parameters:
warmupTime - the new warmup time.
Throws:
IllegalArgumentException - if the warmup time is smaller than 0.

getBatchFraction

public double getBatchFraction()
Returns the remaining fraction of batch to be simulated. This method is called when scheduling the end of the next batch during a simulation. Sometimes, it can be necessary to increase the batch size to avoid excessive memory usage. In this case, stored real batches (the Vj's) have to be regrouped to use less memory, and the last stored Vj may represent an incomplete batch with respect to the new batch size. This method returns the fraction of batch, with respect to the new batch size, remaining to be simulated before a new batch starts. If regrouping is not used, this always returns 1. The returned value is always greater than 0 and smaller than or equal to 1. For example, with a fixed time batch size s, the next end of batch will be scheduled in s*getBatchFraction() simulation time units. This method returns values different from 1 only if one overrides allocateCapacity, and regroupRealBatches.

Returns:
the remaining fraction of batch to simulate. #regroupRealBatches(int)

getBatchSizeMultiplier

public double getBatchSizeMultiplier()
Returns the batch size multiplier after the simulation of a new batch. This is called when scheduling the end of a new batch, to multiply the batch size after regroupRealBatches has regrouped real batches. This can return any value greater than 0, or 1 if the size is unchanged (the most common case) or if aggregation is not used. This method returns values different from 1 only if one overrides allocateCapacity, and regroupRealBatches.

Returns:
the batch size multiplier. #regroupRealBatches(int)

getTargetBatches

public int getTargetBatches()
Returns the target number of simulated real batches at the next time the stopping condition is checked. By default, this number is set to the minimal number of batches and is increased if the stopping condition check requires new simulated batches. This target number of batches is not decreased automatically, even upon a new call to simulate.

Returns:
the target number of batches.

setTargetBatches

public void setTargetBatches(int targetBatches)
Sets the target number of simulated batches before an error check or the end of the simulation to targetBatches.

Parameters:
targetBatches - the target number of batches.
Throws:
IllegalArgumentException - if the new target number of batches is smaller than the minimal number of batches, or greater than the maximal number of batches.

getCompletedRealBatches

public int getCompletedRealBatches()
Returns the number of completed real batches since the beginning of the run.

Returns:
the number of completed real batches.

getDroppedRealBatches

public int getDroppedRealBatches()
Returns the number of real batches dropped. When using sequential sampling, the target number of batches can become very high, resulting in not enough memory available to store the real batches. One simple heuristic to address this issue is to drop the first real batches, and increase the batch length. This method gives the number of real batches which have been dropped to save memory.

Returns:
the number of dropped real batches.

dropFirstRealBatches

public void dropFirstRealBatches(int n)
Drops the n first real batches to save memory.

Parameters:
n - the number of real batches to drop.
Throws:
IllegalArgumentException - if n is negative or greater than the number of stored real batches. #getDroppedRealBatches()

getBatch

public int getBatch(double time)
Returns the real batch corresponding to simulation time time when batch lengths are kept. If batch lengths are not kept, or if the given time corresponds to the warmup period, this method returns a negative value.

Parameters:
time - the simulation time.
Returns:
the batch corresponding to the time, or a negative value.

isWarmupDone

public boolean isWarmupDone()
Determines if the warmup period for the simulation is over.

Returns:
true if the warmup period is finished, false otherwise.

getNumAggregates

public int getNumAggregates()
Returns h, the number of real batches contained into an effective batch. If aggregation is turned OFF, this always returns 1 as soon as at least one batch is simulated. Otherwise, this returns a number greater than or equal to 1 as soon as addEffectiveBatchObs is called.

Returns:
the number of real batches in one effective batch.
Throws:
IllegalStateException - if h is not available.

getRealBatchLength

public double getRealBatchLength(int batch)
Returns the length, in simulation time units, of the real batch batch. If batch lengths are not kept, this method can return the length of the last batch only.

Parameters:
batch - the batch index.
Returns:
the length of the batch.
Throws:
IndexOutOfBoundsException - if the batch index is out of bounds.
IllegalArgumentException - if the batch length is not available for batch.

getRealBatchStartingTime

public double getRealBatchStartingTime(int batch)
Returns the starting simulation time of batch batch.

Parameters:
batch - the queried batch index.
Returns:
the starting time.

getRealBatchEndingTime

public double getRealBatchEndingTime(int batch)
Returns the ending simulation time of batch batch.

Parameters:
batch - the queried batch index.
Returns:
the ending time.

allocateCapacity

public void allocateCapacity(int capacity)
Allocates the necessary memory for storing capacity real batches. When using sequential sampling, if the variance of estimators is high, many additional batches may be needed to reach the target precision. To avoid memory problems after a long simulation time, this method can preallocate the necessary memory. The method must ensure that the data structures used to store the Vj's can contain capacity real batches. This is done by recreating arrays or resizing data structures. By default, this method throws an UnsupportedOperationException. regroupRealBatches must be implemented if this method does not throw this exception.

Parameters:
capacity - the number of real batches to store.
Throws:
UnsupportedOperationException - to indicate that capacity allocation is not supported

regroupRealBatches

public void regroupRealBatches(int x)
Regroups real batches x by x. When memory is low, the simulator can try to regroup real batches and increase the batch size consequently. This is partly done by this method. The user must override it and modify the internal data structures storing the Vj's in order to regroup elements. The number of real batches m becomes m' = floor(m/x). After this method returns, each new Vj should contain Vj = ∑l=0x-1Vjx+l for j = 0,…, m' - 1, Vm' = ∑l=0(m mod x)-1Vm'x+l, and Vj = 0 for j = m' + 1,…, m - 1. Some static methods called regroupElements are provided by this class to help the user with this. By default, this method throws an UnsupportedOperationException, disabling this functionality which is not always needed.

Parameters:
x - the regrouping factor.
Throws:
UnsupportedOperationException - if regrouping is not supported.

initSimulation

public abstract void initSimulation()
Initializes the simulator for a new run. This is called by the init method after init is called.


initBatchStat

public abstract void initBatchStat()
Resets the counters used for computing observations during the simulation at the beginning of a new batch.


initRealBatchProbes

public abstract void initRealBatchProbes()
Initializes any statistical collector for real batches. This is called at the end of the warmup period.


initEffectiveBatchProbes

public abstract void initEffectiveBatchProbes()
Initializes any statistical collector for effective batches. This is called at every stopping condition check when aggregation is ON, or at the end of the warmup period when it is OFF.


addRealBatchObs

public abstract void addRealBatchObs()
Collects values of a Vj vector concerning the last simulated real batch. This method is called at the end of each real batch.


addEffectiveBatchObs

public abstract void addEffectiveBatchObs(int s,
                                          int h,
                                          double l)
Adds an observation to each statistical collector corresponding to an effective batch. The effective batch for which this method is called has length l, and regroups real batches s, ..., s + h - 1. This method is called after each error check if aggregation is turned ON, or after each real batch if it is turned OFF.


getRequiredNewBatches

public int getRequiredNewBatches()
Computes the approximate number of required real batches to be simulated before the simulation can be stopped. The default implementation always returns 0, which stops the simulation after getTargetBatches real batches are obtained; sequential sampling is not used by default.

Note: if the method uses getRequiredNewObservations with a statistical probe containing one observation per effective batch, this gives the number of additional effective batches to simulate. This value should be multiplied with getNumAggregates to get the number of additional real batches.

Returns:
the approximate required number of additionnal real batches.

init

public void init()
Initializes the simulator for a new experiment. This method, called by simulate, resets the counter for the number of batches, calls simulator().init, followed by initSimulation.


getEndSimEvent

public Event getEndSimEvent()
Returns the event used to stop the simulation at the end of the warmup or batches.


warmup

public void warmup()
Performs a warmup by calling warmup. By default, this method calls warmup with the value returned by getWarmupTime, but one can override this method to simulate the warmup differently. If the duration of the warmup period is not fixed, one can call warmup with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.


warmup

public void warmup(double warmupTime)
Performs a warmup of fixed duration warmupTime. This method simulates for warmupTime simulation time units, and initializes statistical probes for real batches through initRealBatchProbes. If the duration of the warmup period is not fixed, one can call warmup with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.


simulateBatch

public void simulateBatch()
Simulate a new batch with default length. By default, this method multiplies the current batch size with getBatchSizeMultiplier, and schedules the next end-batch event to happen in getBatchSize*getBatchFraction simulation time units, by using simulateBatch. After the batch is simulated, the batch-size multiplier and fraction are reset to 1. If the batch lengths are not fixed, one can override this method to call simulateBatch with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.


simulateBatch

public void simulateBatch(double batchLength)
Simulates a batch with length batchLength. This method initializes the model-specific counters by using initBatchStat, simulates the batch, and adds observations using addRealBatchObs. It also calls addEffectiveBatchObs if aggregation is turned OFF. If the batch lengths are not fixed, one can call this method to call simulateBatch with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.


adjustTargetBatches

public void adjustTargetBatches(int numNewBatches)
Adjusts the target number of real batches to simulate numNewBatches additionnal real batches. This method clamps the target number of real batches to the maximal number of batches, and ensures that the target number of batches is a multiple of the minimal number of batches when aggregation is turned ON.


simulateBatches

public void simulateBatches()
Simulates batches until the number of completed real batches corresponds to the target number of batches. This method first allocates the capacity for simulating getTargetBatches. It then simulate each batch using simulateBatch. If aggregation is turned ON, this method also calls initEffectiveBatchProbes, and addEffectiveBatchObs to manage effective batches.


simulate

public void simulate()
Performs a batch means simulation. This method resets the state of the system by calling init, and calls warmup to perform the warmup. Then, the method calls simulateBatches and getRequiredNewBatches until the number of completed real batches equals or exceeds the target number of batches.

Specified by:
simulate in class SimExp

toString

public String toString()
Overrides:
toString in class Object

getSum

public static double getSum(double[] a,
                            int start,
                            int length)
Returns the sum of elements start, ..., start + length - 1, in the array a.

Parameters:
a - the source array.
start - the index of the first element to sum.
length - the number of elements in the sum.
Returns:
the sum of the elements.
Throws:
NullPointerException - if a is null.
IllegalArgumentException - length is negative.
IndexOutOfBoundsException - if start is negative, or start + length is greater than the length of a.

getSum

public static double getSum(cern.colt.list.DoubleArrayList l,
                            int start,
                            int length)
Returns the sum of elements start, ..., start + length - 1, in the array list l.

Parameters:
l - the source array list.
start - the index of the first element to sum.
length - the number of elements in the sum.
Returns:
the sum of the elements.
Throws:
NullPointerException - if l is null.
IllegalArgumentException - length is negative.
IndexOutOfBoundsException - if start is negative, or start + length is greater than the size of l.

getSum

public static double getSum(cern.colt.matrix.DoubleMatrix1D m,
                            int start,
                            int length)
Returns the sum of elements start, ..., start + length - 1, in the 1D matrix m.

Parameters:
m - the source 1D matrix.
start - the index of the first element to sum.
length - the number of elements in the sum.
Returns:
the sum of the elements.
Throws:
NullPointerException - if m is null.
IllegalArgumentException - length is negative.
IndexOutOfBoundsException - if start is negative, or start + length is greater than the size of m.

getSum

public static double[] getSum(double[][] a,
                              int startColumn,
                              int numColumns)
Returns an array containing the sum of columns startColumn, ..., startColumn + numColumns - 1, in the 2D matrix represented by the 2D array a. The given array is assumed to be rectangular, i.e., each of its array elements has the same length.

Parameters:
a - the source 2D array.
startColumn - the index of the first column to sum.
numColumns - the number of columns in the sum.
Returns:
an array of a.length elements containing the sums of the columns.
Throws:
NullPointerException - if a is null.
IllegalArgumentException - numColumns is negative.
IndexOutOfBoundsException - if startColumn is negative, or startColumn + numColumns is greater than the number of columns in the matrix represented by a.

getSum

public static double[] getSum(cern.colt.matrix.DoubleMatrix2D m,
                              int startColumn,
                              int numColumns)
Returns an array containing the sum of columns startColumn, ..., startColumn + numColumns - 1, in the 2D matrix m.

Parameters:
m - the source 2D matrix.
startColumn - the index of the first column to sum.
numColumns - the number of columns in the sum.
Returns:
an array of m.rows() elements containing the sum of the columns.
Throws:
NullPointerException - if m is null.
IllegalArgumentException - numColumns is negative.
IndexOutOfBoundsException - if startColumn is negative, or startColumn + numColumns is greater than the number of columns in m.

regroupElements

public static void regroupElements(double[] a,
                                   int x)
Regroups the elements in array a by summing each successive x values. When this method returns, element i of the given array corresponds to the sum of elements ix, ..., ix + x - 1 in the original array. If the size of the array is not a multiple of x, the remaining elements are summed up and added into an extra element of the transformed array. Remaining elements of the transformed array are set to 0.

Parameters:
a - the array being processed.
x - the regrouping factor.
Throws:
NullPointerException - if a is null.
IllegalArgumentException - if x is smaller than 1.

regroupElements

public static void regroupElements(cern.colt.list.DoubleArrayList l,
                                   int x)
Same as regroupElements for an array list. The size of the list is also divided by x.

Parameters:
l - the array list being processed.
x - the regrouping factor.
Throws:
NullPointerException - if l is null.
IllegalArgumentException - if x is smaller than 1.

regroupElements

public static void regroupElements(cern.colt.matrix.DoubleMatrix1D mat,
                                   int x)
Same as regroupElements for a 1D matrix.

Parameters:
mat - the 1D matrix being processed.
x - the regrouping factor.
Throws:
NullPointerException - if mat is null.
IllegalArgumentException - if x is smaller than 1.

regroupElements

public static void regroupElements(cern.colt.matrix.DoubleMatrix2D mat,
                                   int x)
Same as regroupElements for a 2D matrix. This method regroups columns and considers each row as an independent array.

Parameters:
mat - the 2D matrix being processed.
x - the regrouping factor.
Throws:
NullPointerException - if mat is null.
IllegalArgumentException - if x is smaller than 1.

SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.