ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.contactcenters.contact
Class PoissonArrivalProcess

java.lang.Object
  extended by umontreal.iro.lecuyer.contactcenters.contact.ContactArrivalProcess
      extended by umontreal.iro.lecuyer.contactcenters.contact.PoissonArrivalProcess
All Implemented Interfaces:
ContactSource, Initializable, Named, ToggleElement
Direct Known Subclasses:
PiecewiseConstantPoissonArrivalProcess, PoissonArrivalProcessWithInversion, PoissonArrivalProcessWithThinning, PoissonArrivalProcessWithTimeIntervals

public class PoissonArrivalProcess
extends ContactArrivalProcess

Represents a Poisson-based contact arrival process. This base class implements a Poisson arrival process with (piecewise-)constant arrival rates: when an inter-arrival time is required, it is generated from the exponential distribution with rate . By default, the arrival rate is constant, but it may be changed at any time during the simulation. When the arrival rate changes, the currently scheduled arrival is adjusted automatically to reflect the change. This class can be used as a basis each time the rate function λ(t) of a Poisson process is piecewise-constant over the simulation time t.


Field Summary
 
Fields inherited from class umontreal.iro.lecuyer.contactcenters.contact.ContactArrivalProcess
contactEvent
 
Constructor Summary
PoissonArrivalProcess(ContactFactory factory, double lambda, RandomStream stream)
          Constructs a new Poisson arrival process instantiating new contacts using factory.
PoissonArrivalProcess(Simulator sim, ContactFactory factory, double lambda, RandomStream stream)
          Equivalent to PoissonArrivalProcess(ContactFactory,double,RandomStream), with the given simulator sim.
 
Method Summary
 void clearCache()
          Clears the cached inter-arrival times for this Poisson arrival process.
 double getArrivalRate(double st, double et)
          Determines the mean arrival rate in time interval [s, e].
 double getArrivalRate(int p)
          Determines the arrival rate in period p for this arrival process.
 double getExpectedArrivalRate(double st, double et)
          Determines the expected mean arrival rate in time interval [s, e] for this arrival process assuming that the expected value of the busyness factor is 1.
 double getExpectedArrivalRate(int p)
          Determines the expected arrival rate in period p for this arrival process assuming that the expected value of the busyness factor is 1.
 RandomVariateGenWithCache getGenWithCache()
          Returns the random variate generator for the exponential arrival times used when caching is enabled.
static PoissonArrivalProcess getInstanceFromMLE(ContactFactory factory, RandomStream stream, double dayLength, int[][] arrivals, int numObs, int numPeriods)
          Constructs a new arrival process with arrival rate estimated by the maximum likelihood method based on the numObs observations in array arrivals.
 double getLambda()
          Returns the current value of the arrival rate λ.
static double[] getMLE(int[][] arrivals, int numObs, int numPeriods)
          Estimates the parameters of a Poisson arrival process with arrival rate λ from the number of arrivals in the array arrivals.
 RandomStream getStream()
          Returns the random number stream used to generate the uniforms for inter-arrival times.
 void init()
          Initializes the new arrival process.
 void initCache()
          Resets the random variate generator cache to get the generated inter-arrival times.
 boolean isCaching()
          Determines if the generated inter-arrival times are cached for more efficiency.
 double nextTime()
          Computes and returns the time before the next contact arrival is simulated by this object.
 void setCaching(boolean caching)
          Sets the caching indicator to caching for this Poisson process.
 void setLambda(double newLambda)
          Changes the value of λ to newLambda.
 void setStream(RandomStream stream)
          Sets the random number stream used to generate the uniforms for the inter-arrival times to stream.
 void startStationary()
          This method calls ContactArrivalProcess.start() assuming that the λ arrival rate will not change during simulation.
 String toString()
           
 
Methods inherited from class umontreal.iro.lecuyer.contactcenters.contact.ContactArrivalProcess
addNewContactListener, clearNewContactListeners, getArrivalRates, getBusynessFactor, getContactFactory, getExpectedArrivalRateB, getExpectedArrivalRateB, getExpectedArrivalRates, getExpectedArrivalRatesB, getExpectedBusynessFactor, getName, getNewContactListeners, getNextArrivalTime, init, isStarted, notifyNewContact, removeNewContactListener, setBusynessFactor, setContactFactory, setExpectedBusynessFactor, setName, setSimulator, simulator, start, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PoissonArrivalProcess

public PoissonArrivalProcess(ContactFactory factory,
                             double lambda,
                             RandomStream stream)
Constructs a new Poisson arrival process instantiating new contacts using factory. The parameter λ is initialized with lambda and the random number stream stream is used to generate the needed uniforms.

Parameters:
factory - the factory instantiating contacts.
lambda - the initial value of λ(t).
stream - random number stream.
Throws:
IllegalArgumentException - if lambda < 0.
NullPointerException - if factory or stream are null.

PoissonArrivalProcess

public PoissonArrivalProcess(Simulator sim,
                             ContactFactory factory,
                             double lambda,
                             RandomStream stream)
Equivalent to PoissonArrivalProcess(ContactFactory,double,RandomStream), with the given simulator sim.

Method Detail

getExpectedArrivalRate

public double getExpectedArrivalRate(int p)
Description copied from class: ContactArrivalProcess
Determines the expected arrival rate in period p for this arrival process assuming that the expected value of the busyness factor is 1. The arrival rate corresponds to the expected number of arrivals per simulation time unit during the specified period; one must multiply the rate by the period duration to get the expected number of arrivals during the period. If arrival rates are deterministic, this returns the same value as ContactArrivalProcess.getArrivalRate(int).

If $ \E$[B]≠1, one should use ContactArrivalProcess.getExpectedArrivalRateB(int) which takes the expectation of the busyness factor into account.

If the expected arrival rate is not available, throws an UnsupportedOperationException. This is the default behavior of this method if not overridden by a subclass.

Overrides:
getExpectedArrivalRate in class ContactArrivalProcess
Parameters:
p - the queried period index.
Returns:
the expected arrival rate in that period.

getExpectedArrivalRate

public double getExpectedArrivalRate(double st,
                                     double et)
Description copied from class: ContactArrivalProcess
Determines the expected mean arrival rate in time interval [s, e] for this arrival process assuming that the expected value of the busyness factor is 1. The arrival rate corresponds to the expected number of arrivals per simulation time unit during the specified interval; one must multiply the rate by the interval length to get the expected number of arrivals during the interval. If arrival rates are deterministic, this returns the same value as ContactArrivalProcess.getArrivalRate(double,double). If λ(t) is the arrival rate at time t, this method returns

$\displaystyle \htint_{s}^{e}$$\displaystyle \E$[λ(t)]dt/(e - s).

If $ \E$[B]≠1, one should use ContactArrivalProcess.getExpectedArrivalRateB(double,double) which takes the expectation of the busyness factor into account.

This method returns 0 if es.

If the expected arrival rate is not available, throws an UnsupportedOperationException. This is the default behavior of this method if not overridden by a subclass.

Overrides:
getExpectedArrivalRate in class ContactArrivalProcess
Parameters:
st - the starting time s.
et - the ending time e.
Returns:
the expected arrival rate in the given time interval.

getLambda

public double getLambda()
Returns the current value of the arrival rate λ.

Returns:
the current value of λ.

getArrivalRate

public double getArrivalRate(int p)
Description copied from class: ContactArrivalProcess
Determines the arrival rate in period p for this arrival process. The arrival rate corresponds to the expected number of arrivals per simulation time unit during the specified period; one must multiply the rate by the period duration to get the expected number of arrivals during the period.

If arrival rate is random, this returns the arrival rate for the current replication. One should use ContactArrivalProcess.getExpectedArrivalRate(int) or ContactArrivalProcess.getExpectedArrivalRateB(int) to get the expected arrival rate.

If the arrival rate is not available, throws an UnsupportedOperationException.

Overrides:
getArrivalRate in class ContactArrivalProcess
Parameters:
p - the queried period index.
Returns:
the arrival rate in that period.

getArrivalRate

public double getArrivalRate(double st,
                             double et)
Description copied from class: ContactArrivalProcess
Determines the mean arrival rate in time interval [s, e]. The arrival rate corresponds to the expected number of arrivals per simulation time unit during the specified interval; one must multiply the rate by the interval length to get the expected number of arrivals during the interval. If λ(t) is the arrival rate at time t, this method returns the result of

$\displaystyle \htint_{s}^{e}$λ(t)dt/(e - s).

If arrival rate is random, this returns the arrival rate for the current replication. One should use ContactArrivalProcess.getExpectedArrivalRate(double,double) or ContactArrivalProcess.getExpectedArrivalRateB(double,double) to get the expected arrival rate.

This method returns 0 if es.

If the arrival rate is not available, throws an UnsupportedOperationException. This is the default behavior of this method if not overridden by a subclass.

Overrides:
getArrivalRate in class ContactArrivalProcess
Parameters:
st - the starting time s.
et - the ending time e.
Returns:
the arrival rate in the given time interval.

setLambda

public void setLambda(double newLambda)
Changes the value of λ to newLambda. This adjusts the time of the next arrival if necessary. If newLambda is set to 0, the currently scheduled arrival, if any, is cancelled and the Poisson process is stopped. The Poisson process can be restarted by setting a new non-zero λ value.

Parameters:
newLambda - the new value of λ.
Throws:
IllegalArgumentException - if newLambda < 0.

getStream

public RandomStream getStream()
Returns the random number stream used to generate the uniforms for inter-arrival times.

Returns:
the random number stream for the uniforms.

setStream

public void setStream(RandomStream stream)
Sets the random number stream used to generate the uniforms for the inter-arrival times to stream.

Parameters:
stream - the new random number stream.
Throws:
NullPointerException - if stream is null.

isCaching

public boolean isCaching()
Determines if the generated inter-arrival times are cached for more efficiency. When caching is enabled, the arrival process records every standardized inter-arrival time generated. These random times follow the exponential distribution with λ = 1, and are divided by the arrival rate in use. Therefore, the cache can be used even if the arrival rate changes. The initCache() method must be called to start reusing cached values. This avoids some computations and increases the performance, at the expense of memory. This is useful when comparing several contact centers with common random numbers. By default, this caching is disabled for more efficient memory usage.

Returns:
the caching indicator for this arrival process.

setCaching

public void setCaching(boolean caching)
Sets the caching indicator to caching for this Poisson process.

Parameters:
caching - the new value of the caching indicator.
See Also:
isCaching()

initCache

public void initCache()
Resets the random variate generator cache to get the generated inter-arrival times. This method has no effect if caching is disabled.

See Also:
isCaching()

clearCache

public void clearCache()
Clears the cached inter-arrival times for this Poisson arrival process. This has some effect only if caching is enabled.

See Also:
isCaching()

getGenWithCache

public RandomVariateGenWithCache getGenWithCache()
Returns the random variate generator for the exponential arrival times used when caching is enabled. If caching is disabled, the method throws an IllegalStateException.

Returns:
the random variate generator.
Throws:
IllegalStateException - if caching is disabled.

init

public void init()
Description copied from class: ContactArrivalProcess
Initializes the new arrival process. If this method is overridden by a subclass, it is important to call super.init() in order to ensure that everything is initialized correctly.

Specified by:
init in interface ContactSource
Specified by:
init in interface Initializable
Overrides:
init in class ContactArrivalProcess

nextTime

public double nextTime()
Description copied from class: ContactArrivalProcess
Computes and returns the time before the next contact arrival is simulated by this object. If this method returns Double.POSITIVE_INFINITY, no more arrival events will be scheduled until the arrival process is reinitialized.

Specified by:
nextTime in class ContactArrivalProcess
Returns:
the time before the next arrival.

startStationary

public void startStationary()
This method calls ContactArrivalProcess.start() assuming that the λ arrival rate will not change during simulation. Subclasses violating this assumption should override this method.

Overrides:
startStationary in class ContactArrivalProcess

toString

public String toString()
Overrides:
toString in class ContactArrivalProcess

getMLE

public static double[] getMLE(int[][] arrivals,
                              int numObs,
                              int numPeriods)
Estimates the parameters of a Poisson arrival process with arrival rate λ from the number of arrivals in the array arrivals. Element arrivals[i][p] corresponds to the number of arrivals on day i during period p, where i = 0,…, n - 1, p = 0,…, P - 1, n = numObs, and P = numPeriods. This method sums the number of arrivals on every period for each day and uses the resulting array of numObs observations to estimate a Poisson arrival rate. This returns an array containing the estimated $ \hat{{\lambda}}$, which estimates the expected number of arrivals during one day.

Parameters:
arrivals - the number of arrivals during each day and period.
numObs - the number of days.
numPeriods - the number of periods.
Returns:
the estimated arrival rates.

getInstanceFromMLE

public static PoissonArrivalProcess getInstanceFromMLE(ContactFactory factory,
                                                       RandomStream stream,
                                                       double dayLength,
                                                       int[][] arrivals,
                                                       int numObs,
                                                       int numPeriods)
Constructs a new arrival process with arrival rate estimated by the maximum likelihood method based on the numObs observations in array arrivals. Element arrivals[i][p] corresponds to the number of arrivals on day i during period p, where i = 0,…, n - 1, p = 0,…, P - 1, n = numObs, and P = numPeriods. The estimated arrival rate, which approximates the expected number of arrivals during a day, is divided by dayLength to be relative to one time unit.

Parameters:
factory - the contact factory used to create contacts.
stream - the random stream to generate arrival times.
dayLength - the duration of the day, in simulation time units.
arrivals - the number of arrivals.
numObs - the number of days.
numPeriods - the number of periods.
Returns:
the constructed arrival process.

ContactCenters
V. 0.9.9.

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