ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.contactcenters.contact
Class PiecewiseConstantPoissonArrivalProcess

java.lang.Object
  extended by umontreal.iro.lecuyer.contactcenters.contact.ContactArrivalProcess
      extended by umontreal.iro.lecuyer.contactcenters.contact.PoissonArrivalProcess
          extended by umontreal.iro.lecuyer.contactcenters.contact.PiecewiseConstantPoissonArrivalProcess
All Implemented Interfaces:
ContactSource, Initializable, Named, PeriodChangeListener, ToggleElement
Direct Known Subclasses:
DirichletCompoundArrivalProcess, PoissonArrivalProcessWithRandomRates, PoissonGammaArrivalProcess, PoissonGammaNortaRatesArrivalProcess

public class PiecewiseConstantPoissonArrivalProcess
extends PoissonArrivalProcess
implements PeriodChangeListener

Represents a non-homogeneous Poisson arrival process with piecewise-constant arrival rates. Each inter-arrival time is an exponential variate with rate λ(t), where λ(t) = p(t) is a piecewise-constant function over simulation time. The function p(t) gives the period corresponding to simulation time t whereas λp is the base arrival rate for the Poisson process, during period p. This class uses the PoissonArrivalProcess base class to generate inter-arrival times and to adjust the arrival time when the rate changes. If a single period p is simulated as if it was infinite in the model, the arrival rate is fixed to λp.


Field Summary
protected  RandomVariateGen busyGen
           
static double s_bgammaParam
          Contains the parameter for the gamma-distributed busyness factor given by methods for parameter estimation.
protected static int s_numMC
           
protected static double varianceEpsilon
           
 
Fields inherited from class umontreal.iro.lecuyer.contactcenters.contact.ContactArrivalProcess
contactEvent
 
Constructor Summary
PiecewiseConstantPoissonArrivalProcess(PeriodChangeEvent pce, ContactFactory factory, double[] lambdas, RandomStream stream)
          Constructs a new Poisson arrival process with piecewise-constant arrival rates instantiating new contacts using factory.
PiecewiseConstantPoissonArrivalProcess(PeriodChangeEvent pce, ContactFactory factory, double[] lambdas, RandomStream stream, RandomVariateGen bgen)
          Similar to (PeriodChangeEvent, ContactFactory, double[], RandomStream), but with busyness generator bgen.
 
Method Summary
 void changePeriod(PeriodChangeEvent pce)
          Switches to the next period defined by pce.
 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.
static PiecewiseConstantPoissonArrivalProcess getInstanceFromMLE(PeriodChangeEvent pce, ContactFactory factory, RandomStream stream, int[][] arrivals, int numObs, int numPeriods, boolean withGammaBusyness)
          Constructs a new arrival process with arrival rates estimated by the maximum likelihood method based on the numObs observations in array arrivals.
 double[] getLambdas()
          Returns the current value of lambdas.
static double[] getMLE(int[][] arrivals, int numObs, int numPeriods)
          Estimates the parameters of a Poisson arrival process with piecewise-constant arrival rate from the number of arrivals in the array arrivals, and returns an array giving the estimated arrival rate for each main period.
static double[] getMLENegMulti(int[][] arrivals, int numObs, int numPeriods)
          Estimates the parameters of a Poisson arrival process with piecewise-constant arrival rate multiplied by a day-specific busyness factor following the gamma (α0, α0) distribution from the number of arrivals in the array arrivals.
static int getNumMC()
          Sets the number of Monte Carlo samples to n.
 PeriodChangeEvent getPeriodChangeEvent()
          Returns the period-change event associated with this object.
static double getVarianceEpsilon()
          Returns the value of varianceEpsilon.
 void init()
          Initializes the new arrival process.
 boolean isNormalizing()
          Determines if the base arrival rates are normalized with period duration.
 void setLambdas(double[] lambdas)
          Sets the base arrival rates to lambdas.
 void setNormalizing(boolean b)
          Sets the arrival rates normalization indicator to b.
static void setNumMC(int n)
          Sets the number of Monte Carlo samples to n.
static void setVarianceEpsilon(double eps)
          Sets the lower limit for the variance of the busyness distribution.
 void startStationary()
          This method checks that the associated period-change event is locked to a fixed period, and calls ContactArrivalProcess.start() if this is the case.
 void stop(PeriodChangeEvent pce)
          This method is called after the period-change event is stopped by PeriodChangeEvent.stop().
 String toString()
           
 
Methods inherited from class umontreal.iro.lecuyer.contactcenters.contact.PoissonArrivalProcess
clearCache, getGenWithCache, getInstanceFromMLE, getLambda, getStream, initCache, isCaching, nextTime, setCaching, setLambda, setStream
 
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
 

Field Detail

busyGen

protected RandomVariateGen busyGen

varianceEpsilon

protected static double varianceEpsilon

s_bgammaParam

public static double s_bgammaParam
Contains the parameter for the gamma-distributed busyness factor given by methods for parameter estimation. This is the alpha parameter of the gamma distribution for busyness. ATTENTION: variable de travail; utiliser tout de suite apres getMLENegMulti


s_numMC

protected static int s_numMC
Constructor Detail

PiecewiseConstantPoissonArrivalProcess

public PiecewiseConstantPoissonArrivalProcess(PeriodChangeEvent pce,
                                              ContactFactory factory,
                                              double[] lambdas,
                                              RandomStream stream)
Constructs a new Poisson arrival process with piecewise-constant arrival rates instantiating new contacts using factory. The parameter λ is initialized with Blambdas[0], and is updated at the beginning of each period with a value from lambdas. The random number stream stream is used to generate the needed uniforms. The newly-constructed arrival process is added to the period-change event pce for the arrival rate to be automatically updated.

Parameters:
pce - the period-change event associated with this object.
factory - the factory instantiating contacts.
lambdas - the base arrival rates.
stream - the random number generator for inter-arrival times.
Throws:
IllegalArgumentException - if there is not one rate per period.
NullPointerException - if any argument is null.

PiecewiseConstantPoissonArrivalProcess

public PiecewiseConstantPoissonArrivalProcess(PeriodChangeEvent pce,
                                              ContactFactory factory,
                                              double[] lambdas,
                                              RandomStream stream,
                                              RandomVariateGen bgen)
Similar to (PeriodChangeEvent, ContactFactory, double[], RandomStream), but with busyness generator bgen. It generates a busyness factor multiplying the base rate.

Parameters:
pce - the period-change event associated with this object.
factory - the factory instantiating contacts.
lambdas - the base arrival rates.
stream - the random number generator for inter-arrival times.
bgen - random number generator for busyness
Throws:
IllegalArgumentException - if there is not one rate per period.
NullPointerException - if any argument is null.
Method Detail

setNumMC

public static void setNumMC(int n)
Sets the number of Monte Carlo samples to n. This is the number of MC samples used in the getMLE method in subclasses.

Parameters:
n -

getNumMC

public static int getNumMC()
Sets the number of Monte Carlo samples to n. This is the number of MC samples used in the getMLE method in subclasses.


isNormalizing

public boolean isNormalizing()
Determines if the base arrival rates are normalized with period duration. When normalization is enabled, for period p, the effective base arrival rate is getLambda (p)/getPeriodChangeEvent().getPeriodDuration (p). No normalization is applied for the wrap-up period, because its duration is unknown when it starts. If normalization is disabled (the default), the base arrival rates are used as specified.

Returns:
if the arrival process normalizes base arrival rates.

setNormalizing

public void setNormalizing(boolean b)
Sets the arrival rates normalization indicator to b.

Parameters:
b - the new arrival rate normalization indicator.
See Also:
isNormalizing()

getPeriodChangeEvent

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

Returns:
the associated period-change event.

startStationary

public void startStationary()
This method checks that the associated period-change event is locked to a fixed period, and calls ContactArrivalProcess.start() if this is the case. Otherwise, it throws an unsupported-operation exception since the arrival rate can change with the current period.

Overrides:
startStationary in class PoissonArrivalProcess

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 PoissonArrivalProcess
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 PoissonArrivalProcess
Parameters:
st - the starting time s.
et - the ending time e.
Returns:
the arrival rate in the given time interval.

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 PoissonArrivalProcess
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 PoissonArrivalProcess
Parameters:
st - the starting time s.
et - the ending time e.
Returns:
the expected arrival rate in the given time interval.

getLambdas

public double[] getLambdas()
Returns the current value of lambdas.

Returns:
the current base rates for the process.

setLambdas

public void setLambdas(double[] lambdas)
Sets the base arrival rates to lambdas.

Parameters:
lambdas - the new base arrival rates.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the length of the array is smaller than the number of periods.

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 PoissonArrivalProcess

changePeriod

public void changePeriod(PeriodChangeEvent pce)
Description copied from interface: PeriodChangeListener
Switches to the next period defined by pce. This can change the parameters and correct scheduled events accordingly. If no parameters are available for the new period, the method should try to use those of the last available period. The listener is called after the period change has occurred, so PeriodChangeEvent.getCurrentPeriod() returns the index of the new period.

Specified by:
changePeriod in interface PeriodChangeListener
Parameters:
pce - the source period-change event.

stop

public void stop(PeriodChangeEvent pce)
Description copied from interface: PeriodChangeListener
This method is called after the period-change event is stopped by PeriodChangeEvent.stop().

Specified by:
stop in interface PeriodChangeListener
Parameters:
pce - the period-change event being stopped.

toString

public String toString()
Overrides:
toString in class PoissonArrivalProcess

getMLE

public static double[] getMLE(int[][] arrivals,
                              int numObs,
                              int numPeriods)
Estimates the parameters of a Poisson arrival process with piecewise-constant arrival rate from the number of arrivals in the array arrivals, and returns an array giving the estimated arrival rate for each main period. Element arrivals[i][p] corresponds to the number of arrivals on day i during main period p, where i = 0,…, n - 1, p = 0,…, P - 1, n = numObs, and P = numPeriods. This method estimates the expected number of arrivals during main period p, noted λp, independently for each main period, assuming that the number of arrivals in that period follows the Poisson distribution. The returned array contains the estimated arrival rate for each of the P periods, noted λ1,…, λP.

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.

setVarianceEpsilon

public static void setVarianceEpsilon(double eps)
Sets the lower limit for the variance of the busyness distribution. When the variance would be smaller than eps, the parameter of the busyness distribution is reset so that variance = eps.


getVarianceEpsilon

public static double getVarianceEpsilon()
Returns the value of varianceEpsilon.

Returns:
the lower bound of the variance for busyness

getMLENegMulti

public static double[] getMLENegMulti(int[][] arrivals,
                                      int numObs,
                                      int numPeriods)
Estimates the parameters of a Poisson arrival process with piecewise-constant arrival rate multiplied by a day-specific busyness factor following the gamma (α0, α0) distribution from the number of arrivals in the array arrivals. Element arrivals[i][p] corresponds to the number of arrivals of this type on day i during main period p, where i = 0,…, n - 1, p = 0,…, P - 1, n = numObs, and P = numPeriods. This returns an array with the estimated arrival rates and stores the gamma busyness parameter in s_bgammaParam. This method assumes that the number of arrivals during main periods, represented by the vector A1,…, AP, follows the negative multinomial distribution with parameters (α0, ρ1,…, ρP) where ρp = λp/(α0 + $ \htsum_{{k=1}}^{P}$λk) for p = 1,…, P. After α0, ρ1,…, ρP are estimated using maximum likelihood, arrival rate for any main period p = 1,…, P can be obtained using λp = α0ρp/ρ0, where ρ0 = 1 - $ \htsum_{{k=1}}^{P}$ρk. This method thus returns the array with λ1,…, λP.

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 PiecewiseConstantPoissonArrivalProcess getInstanceFromMLE(PeriodChangeEvent pce,
                                                                        ContactFactory factory,
                                                                        RandomStream stream,
                                                                        int[][] arrivals,
                                                                        int numObs,
                                                                        int numPeriods,
                                                                        boolean withGammaBusyness)
Constructs a new arrival process with arrival rates 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. If withGammaBusyness is true, the number of arrivals is considered to follow the negative multinomial distribution, and the α0 parameter for the gamma-distributed busyness factor is stored in s_bgammaParam. Otherwise, the periods are considered independent, and the number of arrivals during a period is considered to follow the Poisson distribution. The expected number of arrivals used during the preliminary period is equal to the expectation estimated for the first main period while the arrival rate during the wrap-up period is always 0.

Parameters:
pce - the period-change event marking the end of periods.
factory - the contact factory used to create contacts.
stream - the random stream to generate arrival times.
arrivals - the number of arrivals.
numObs - the number of days.
numPeriods - the number of periods.
withGammaBusyness - determines if the α0 parameter is estimated in addition to the arrival rates.
Returns:
the constructed arrival process.

ContactCenters
V. 0.9.9.

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