ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.contactcenters
Class MultiPeriodGen

java.lang.Object
  extended by umontreal.iro.lecuyer.randvar.RandomVariateGen
      extended by umontreal.iro.lecuyer.contactcenters.MultiPeriodGen
All Implemented Interfaces:
Initializable, ValueGenerator

public class MultiPeriodGen
extends RandomVariateGen
implements ValueGenerator

Represents a random variate generator for non-stationary distributions with constant parameters during each period. When a new random variate is required, a random variate generator corresponding to the appropriate period is selected and a value is drawn from this generator.

This generator supports caching by using internal RandomVariateGenWithCache instances for each period. If a single cache was used, the generator could recover a value whose distribution does not correspond with the current period. Caching is disabled by default, and can be enabled by using the setCaching(boolean) method.


Field Summary
 
Fields inherited from class umontreal.iro.lecuyer.randvar.RandomVariateGen
dist, stream
 
Constructor Summary
MultiPeriodGen(PeriodChangeEvent pce, RandomVariateGen gen)
          Constructs a new multi-period random variate generator with period-change event pce, and random variate generator gen for every period.
MultiPeriodGen(PeriodChangeEvent pce, RandomVariateGen[] gens)
          Constructs a new multi-period random variate generator with period-change event pce, and the per-period random variate generators gens.
 
Method Summary
 void clearCache()
          Clears the values cached by this generator.
static MultiPeriodGen createConstant(PeriodChangeEvent pce, double[] values)
          Constructs and returns a multiple-periods random variate generator using the constant distribution with value values[p] for period p as defined by pce.
static MultiPeriodGen createExponential(PeriodChangeEvent pce, RandomStream stream, double[] lambdas)
          Constructs and returns a multiple-periods random variate generator using the exponential distribution with rate lambdas[p] for period p as defined by pce.
static MultiPeriodGen createGamma(PeriodChangeEvent pce, RandomStream stream, double[] alphas, double[] lambdas)
          Constructs and returns a multiple-periods random variate generator using the gamma distribution with parameters alphas[p] and lambdas[p] for period p as defined by pce.
 DoubleArrayList[] getCachedValues()
          Returns an array of array lists containing the values cached by each period-specific generator.
 int[] getCacheIndices()
          Returns an array containing the cache indices of each per-period generator.
 Distribution getDistribution()
          Returns the distribution used during the current period.
 RandomVariateGen getGenerator(int p)
          Returns the random variate generator corresponding to the period p.
 RandomVariateGen[] getGenerators()
          Returns the random variate generators associated with this object.
 RandomVariateGenWithCache[] getGeneratorsWithCache()
          Returns the random variate generators with cache used by this object.
 RandomVariateGenWithCache getGeneratorWithCache(int p)
          Returns the random variate generator with cache corresponding to the period p.
 double getMean(int p)
          Returns the mean for period p.
static double getMean(RandomVariateGen rvg)
          Returns the mean of the distribution for a random variate generator, taking the shift into account.
 double getMult()
          Returns the multiplier applied to each generated random variate.
 PeriodChangeEvent getPeriodChangeEvent()
          Returns the period-change event associated with this object.
 TimeUnit getSourceTimeUnit()
          Returns the time unit in which the values coming from the probability distribution are expressed.
 RandomStream getStream()
          Returns the random stream used during the current period.
 TimeUnit getTargetTimeUnit()
          Returns the time unit in which the values returned by nextDouble() must be expressed.
 double getVariance(int p)
          Returns the variance for the period p.
 void init()
          Initializes the generator at the beginning of the simulation.
 void initCache()
          Resets the cache of this generator, if caching is enabled.
 boolean isCaching()
          Determines if this multiple-periods generator is caching the generated values, using internal RandomVariateGenWithCache objects.
 void nextArrayOfDouble(double[] v, int start, int n)
           
 double nextDouble()
           
 double nextDouble(Contact contact)
          Ignores the given contact and calls nextDouble().
 void setCachedValues(DoubleArrayList[] values)
          Sets the array list containing the cached values to values[g] for each period-specific generator g.
 void setCacheIndices(int[] ind)
          Sets the array of cache indices to ind.
 void setCaching(boolean caching)
          Sets the status of the caching for this generator.
 void setGenerator(int p, RandomVariateGen gen)
          Sets the random variate generator for period p to gen.
 void setGenerators(RandomVariateGen[] gens)
          Sets the per-period random variate generators to gens.
 void setMult(double mult)
          Sets the multiplier applied to each generated random variate to mult.
 void setSourceTimeUnit(TimeUnit unit)
          Sets the source time unit to unit.
 void setTargetTimeUnit(TimeUnit unit)
          Sets the target time unit to unit.
 
Methods inherited from class umontreal.iro.lecuyer.randvar.RandomVariateGen
setStream, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiPeriodGen

public MultiPeriodGen(PeriodChangeEvent pce,
                      RandomVariateGen gen)
Constructs a new multi-period random variate generator with period-change event pce, and random variate generator gen for every period.

Parameters:
pce - the period-change event.
gen - one random variate generator for every period.
Throws:
NullPointerException - if any argument is null.

MultiPeriodGen

public MultiPeriodGen(PeriodChangeEvent pce,
                      RandomVariateGen[] gens)
Constructs a new multi-period random variate generator with period-change event pce, and the per-period random variate generators gens.

Parameters:
pce - the period change event.
gens - one random variate generator for each period.
Throws:
NullPointerException - if any argument is null.
IllegalArgumentException - if the length of gens does not correspond to the number of periods.
Method Detail

isCaching

public boolean isCaching()
Determines if this multiple-periods generator is caching the generated values, using internal RandomVariateGenWithCache objects. By default, caching is disabled for better memory utilization.

Returns:
the status of the caching.

setCaching

public void setCaching(boolean caching)
Sets the status of the caching for this generator.

Parameters:
caching - the new status of the caching.

getPeriodChangeEvent

public PeriodChangeEvent getPeriodChangeEvent()
Returns the period-change event associated with this object.

Returns:
the associated period-change event.

getGenerators

public RandomVariateGen[] getGenerators()
Returns the random variate generators associated with this object.

Returns:
the associated random variate generators.

getGeneratorsWithCache

public RandomVariateGenWithCache[] getGeneratorsWithCache()
Returns the random variate generators with cache used by this object. If caching is disabled (the default), this method throws an IllegalStateException.

Returns:
the random variate generators with cache.
Throws:
IllegalStateException - if caching is disabled.

setGenerators

public void setGenerators(RandomVariateGen[] gens)
Sets the per-period random variate generators to gens. Note that if caching is enabled, the cache is reset when using this method.

Parameters:
gens - the array containing the new random variate generators.
Throws:
IllegalArgumentException - if the length of gens is invalid.
NullPointerException - if any argument is null.

getGenerator

public RandomVariateGen getGenerator(int p)
Returns the random variate generator corresponding to the period p.

Parameters:
p - index of the period.
Returns:
the corresponding random variate generator.
Throws:
ArrayIndexOutOfBoundsException - if p is out of bounds.

getGeneratorWithCache

public RandomVariateGenWithCache getGeneratorWithCache(int p)
Returns the random variate generator with cache corresponding to the period p. If caching is disabled (the default), this method throws an IllegalStateException.

Parameters:
p - index of the period.
Returns:
the corresponding random variate generator with cache.
Throws:
ArrayIndexOutOfBoundsException - if p is out of bounds.
IllegalStateException - if caching is disabled.

setGenerator

public void setGenerator(int p,
                         RandomVariateGen gen)
Sets the random variate generator for period p to gen.

Parameters:
p - the period index.
gen - the new random variate generator.
Throws:
ArrayIndexOutOfBoundsException - if p is out of bounds.

initCache

public void initCache()
Resets the cache of this generator, if caching is enabled. If caching is disabled, this method does nothing. When the cache is reset, cached values are returned upon calls to nextDouble(), until the cache is exhausted. When there is no more cached value, random variates are computed as usual.


clearCache

public void clearCache()
Clears the values cached by this generator. If caching is disabled, this method does nothing.


getCacheIndices

public int[] getCacheIndices()
Returns an array containing the cache indices of each per-period generator.

Returns:
the array of cache indices.
Throws:
IllegalStateException - if caching is disabled.

setCacheIndices

public void setCacheIndices(int[] ind)
Sets the array of cache indices to ind.

Parameters:
ind - the new array of cache indices.
Throws:
NullPointerException - if ind is null.
IllegalArgumentException - if ind has incorrect size.
IllegalStateException - if caching is disabled.

getCachedValues

public DoubleArrayList[] getCachedValues()
Returns an array of array lists containing the values cached by each period-specific generator.

Returns:
the array of cached values.

setCachedValues

public void setCachedValues(DoubleArrayList[] values)
Sets the array list containing the cached values to values[g] for each period-specific generator g. This resets the cache index to the size of the given array for each generator.

Parameters:
values - the array list of cached values.
Throws:
NullPointerException - if values is null.

getSourceTimeUnit

public TimeUnit getSourceTimeUnit()
Returns the time unit in which the values coming from the probability distribution are expressed. If the source unit is null, no conversion of the generated values is performed. By default, this returns null.

Returns:
the source time unit.

setSourceTimeUnit

public void setSourceTimeUnit(TimeUnit unit)
Sets the source time unit to unit.

Parameters:
unit - the source time unit.
See Also:
getSourceTimeUnit()

getTargetTimeUnit

public TimeUnit getTargetTimeUnit()
Returns the time unit in which the values returned by nextDouble() must be expressed. If the target unit is null, no conversion of the generated values is performed. By default, this returns null.

Returns:
the target time unit.

setTargetTimeUnit

public void setTargetTimeUnit(TimeUnit unit)
Sets the target time unit to unit.

Parameters:
unit - the target time unit.
See Also:
getTargetTimeUnit()

getMean

public static double getMean(RandomVariateGen rvg)
Returns the mean of the distribution for a random variate generator, taking the shift into account. This method first calls Distribution.getMean() on the distribution associated with the generator. If rvg is an instance of RandomVariateGenWithShift or RandomVariateGenIntWithShift, it then subtracts the associated shift.

Parameters:
rvg - the random variate generator.
Returns:
the possibly shifted mean.

getMean

public double getMean(int p)
Returns the mean for period p.

Parameters:
p - the index of the period.
Returns:
the mean.

getVariance

public double getVariance(int p)
Returns the variance for the period p.

Parameters:
p - the index of the period.
Returns:
the variance.

getMult

public double getMult()
Returns the multiplier applied to each generated random variate. The default multiplier is 1.

Returns:
the applied multiplier.

setMult

public void setMult(double mult)
Sets the multiplier applied to each generated random variate to mult.

Parameters:
mult - the new multiplier.

nextDouble

public double nextDouble()
Overrides:
nextDouble in class RandomVariateGen

nextArrayOfDouble

public void nextArrayOfDouble(double[] v,
                              int start,
                              int n)
Overrides:
nextArrayOfDouble in class RandomVariateGen

getStream

public RandomStream getStream()
Returns the random stream used during the current period.

Overrides:
getStream in class RandomVariateGen

getDistribution

public Distribution getDistribution()
Returns the distribution used during the current period.

Overrides:
getDistribution in class RandomVariateGen

nextDouble

public double nextDouble(Contact contact)
Ignores the given contact and calls nextDouble().

Specified by:
nextDouble in interface ValueGenerator
Parameters:
contact - the contact being concerned.
Returns:
the generated value.

init

public void init()
Description copied from interface: ValueGenerator
Initializes the generator at the beginning of the simulation.

Specified by:
init in interface Initializable
Specified by:
init in interface ValueGenerator

createConstant

public static MultiPeriodGen createConstant(PeriodChangeEvent pce,
                                            double[] values)
Constructs and returns a multiple-periods random variate generator using the constant distribution with value values[p] for period p as defined by pce.

Parameters:
pce - the period-change event.
values - the values of the constant.
Returns:
the constructed multiple-periods generator.
Throws:
IllegalArgumentException - if the length of array is less than the number of periods.

createExponential

public static MultiPeriodGen createExponential(PeriodChangeEvent pce,
                                               RandomStream stream,
                                               double[] lambdas)
Constructs and returns a multiple-periods random variate generator using the exponential distribution with rate lambdas[p] for period p as defined by pce. The random stream stream is used for all the periods.

Parameters:
pce - the period-change event.
stream - the random stream.
lambdas - the rates for the exponential variates.
Returns:
the constructed multiple-periods generator.
Throws:
IllegalArgumentException - if the length of array is less than the number of periods.

createGamma

public static MultiPeriodGen createGamma(PeriodChangeEvent pce,
                                         RandomStream stream,
                                         double[] alphas,
                                         double[] lambdas)
Constructs and returns a multiple-periods random variate generator using the gamma distribution with parameters alphas[p] and lambdas[p] for period p as defined by pce. The random stream stream is used for all the periods. The underlying gamma generators use acceptance-rejection rather than inversion for efficiency.

Parameters:
pce - the period-change event.
stream - the random stream.
alphas - the alpha parameters for the gamma variates.
lambdas - the lambda parameters for the gamma variates.
Returns:
the constructed multiple-periods generator.
Throws:
IllegalArgumentException - if the length of the arrays is less than the number of periods, or the two arrays have different lengths.

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.