|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectumontreal.iro.lecuyer.simevents.Event
umontreal.iro.lecuyer.contactcenters.PeriodChangeEvent
public class PeriodChangeEvent
Defines a simulation event that occurs upon period changes and supporting fixed-sized or variable-sized periods. Because this event must cover the complete simulation horizon (day, week, etc.), not only the times at which the contact center is opened, three types of periods need to be defined.
The P periods during which the contact center is opened are denoted main periods, or simply periods. Main period p, where p = 1,…, P, corresponds to simulation time interval [tp-1, tp[, where t0 < ... < tP. During the preliminary period [0, t0), the contact center is closed. Sometimes, arrivals start at time t0 - τ for a queue to build up before agents enter into service. During the wrap-up period [tP, T], no more arrival occurs, but ongoing services are terminated. Note that preliminary and wrap-up periods are more useful when a simulation replication corresponds to a day.
Before starting the simulation, the period-change event
should be initialized by calling init()
, which
resets the current period index.
The event needs to be started by using start()
;
this schedules it at the beginning of the first main period.
This also schedules auxiliary event managing
period changes at the other periods.
It is recommended to start the period-change
event before scheduling any other event to
ensure that period changes have priority
over other events.
When the period change occurs, it is
notified to any registered PeriodChangeListener
implementation.
When returning from Sim.start or just before
calling Sim.stop, it is recommended to call
the stop()
method of this object, since the end
of the wrap-up period is not scheduled as an event.
This notifies all registered listeners about the
end of the simulation, and disables
any remaining auxiliary event. This can be useful for
some statistical collectors.
Note: the PeriodChangeListener
implementations
are notified in the order of the list returned by
getPeriodChangeListeners()
, and a period-change listener
modifying the list of listeners by using
addPeriodChangeListener(PeriodChangeListener)
or
removePeriodChangeListener(PeriodChangeListener)
could result in unpredictable behavior.
Field Summary | |
---|---|
static double |
PRIORITY
Default priority of period-change events. |
Fields inherited from class umontreal.iro.lecuyer.simevents.Event |
---|
eventTime, priority, sim |
Constructor Summary | |
---|---|
PeriodChangeEvent(double... endingTimes)
Constructs a new period-change event with variable-sized periods, using the default simulator. |
|
PeriodChangeEvent(double periodDuration,
int numPeriods,
double startingTime)
Constructs a new period-change event with fixed-sized main periods of duration periodDuration, a total of P + 2 = numPeriods periods, with the first main period beginning at time t0 = startingTime, and using the default simulator. |
|
PeriodChangeEvent(Simulator sim,
double... endingTimes)
Equivalent to PeriodChangeEvent(double[]) ,
with a user-defined simulator sim. |
|
PeriodChangeEvent(Simulator sim,
double periodDuration,
int numPeriods,
double startingTime)
Equivalent to PeriodChangeEvent(double,int,double) ,
with a user-defined simulator sim. |
Method Summary | |
---|---|
void |
actions()
|
void |
addPeriodChangeListener(PeriodChangeListener l)
Registers the period-change listener l to be notified when a period change occurs. |
boolean |
cancel()
|
void |
clearPeriodChangeListeners()
Removes all the period change listeners from this event. |
int |
getCurrentMainPeriod()
Returns the current main period for this period-change event. |
int |
getCurrentPeriod()
Returns the index of the current simulation period. |
int |
getMainPeriod(int period)
Returns the main period index corresponding to period period. |
String |
getName()
Returns the name associated with this object. |
int |
getNumMainPeriods()
Returns P, the number of main periods used by this period change event, i.e., getNumPeriods() - 2. |
int |
getNumPeriods()
Returns P + 2, the number of periods supported by this period change event. |
int |
getPeriod(double simTime)
Computes the period index corresponding to the simulation time simTime. |
List<PeriodChangeListener> |
getPeriodChangeListeners()
Returns an unmodifiable list containing the period-change listeners currently registered with this event. |
double |
getPeriodDuration(int period)
Returns the duration of the period period. |
double |
getPeriodEndingTime(int period)
Returns the simulation time at which the period period ends. |
double |
getPeriodStartingTime(int period)
Returns the simulation time at which the period period starts. |
void |
init()
Equivalent to init (simulator().time()) . |
void |
init(double initTime)
Inits this period-change event at initial time initTime. |
void |
initAndNotify()
Equivalent to initAndNotify (simulator().time()) . |
void |
initAndNotify(double initTime)
Calls init() and notifies the
period-change listeners if the period changed
due to the initialization. |
boolean |
isLockedPeriod()
Returns true if the current period was changed using setCurrentPeriod(int)
from the last call to init() . |
boolean |
isMainPeriod(int period)
Determines if the period index period corresponds to a main period. |
boolean |
isPeriodStartingTime(double time)
Determines if the time time corresponds to the beginning of a period. |
boolean |
isPreliminaryPeriod(int period)
Determines if the period index period corresponds to the preliminary period. |
boolean |
isStarted()
Determines if the element is enabled or disabled. |
boolean |
isWrapupPeriod(int period)
Determines if the period index period corresponds to the wrap-up period. |
void |
removePeriodChangeListener(PeriodChangeListener l)
Removes the period-change listener l from this period-change event. |
void |
setCurrentPeriod(int p)
Sets the current period to p and disables all period changes initiated by this event. |
void |
setEndingTimes(double... endingTimes)
Changes the ending times of periods to endingTimes. |
void |
setFixedPeriods(double periodDuration,
double startingTime)
Sets this period-change event to fixed-length periods of duration periodDuration, and with main period starting at t0 = startingTime. |
void |
setName(String name)
Sets the name of this object to name. |
void |
start()
Starts the period-change event by scheduling it. |
void |
stop()
This method should be called when the simulation ends. |
String |
toString()
|
boolean |
wasStopped()
Determines if this period-change event was stopped since the last call to init() . |
Methods inherited from class umontreal.iro.lecuyer.simevents.Event |
---|
cancel, compareTo, getRa, priority, reschedule, schedule, scheduleAfter, scheduleBefore, scheduleNext, setPriority, setRa, setSimulator, setTime, simulator, time |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final double PRIORITY
Constructor Detail |
---|
public PeriodChangeEvent(double periodDuration, int numPeriods, double startingTime)
Note that this constructor calls the
setFixedPeriods(double,double)
method.
periodDuration
- the length of each period, in simulation time units.numPeriods
- the total number of periods P + 2.startingTime
- the beginning of the first period.
IllegalArgumentException
- if the number of periods
is smaller than 2 or the period duration or starting time is
smaller than 0.public PeriodChangeEvent(Simulator sim, double periodDuration, int numPeriods, double startingTime)
PeriodChangeEvent(double,int,double)
,
with a user-defined simulator sim.
sim
- the simulator attached to the new event.periodDuration
- the length of each period, in simulation time units.numPeriods
- the total number of periods P + 2.startingTime
- the beginning of the first period.
IllegalArgumentException
- if
sim is null, if the number of periods
is smaller than 2, or the period duration or starting time is
smaller than 0.public PeriodChangeEvent(double... endingTimes)
IllegalArgumentException
is thrown.
This constructor accepts a variable number of arguments, i.e., one can use new PeriodChangeEvent (t1, t2, t3, t4, t5), where tN are ending times. One can also pass a regular array.
Note that this constructor calls the
setEndingTimes(double[])
method.
endingTimes
- the ending times of periods.
IllegalArgumentException
- if one ending time is negative
or the ending times are not non-decreasing.public PeriodChangeEvent(Simulator sim, double... endingTimes)
PeriodChangeEvent(double[])
,
with a user-defined simulator sim.
sim
- the simulator attached to this event.endingTimes
- the ending times of periods.
IllegalArgumentException
- if sim
is null, or if one ending time is negative
or the ending times are not non-decreasing.Method Detail |
---|
public String getName()
Named
getName
in interface Named
public void setName(String name)
Named
UnsupportedOperationException
if the name is read-only.
setName
in interface Named
name
- the new name of the object.public final void setFixedPeriods(double periodDuration, double startingTime)
periodDuration
- the length of each main period.startingTime
- the starting time of the first main period.
IllegalArgumentException
- if one argument
is negative.public final void setEndingTimes(double... endingTimes)
endingTimes
- the new period ending times.
IllegalArgumentException
- if one ending time is negative,
the ending times are not non-decreasing, or one tries to change
the number of periods.public void addPeriodChangeListener(PeriodChangeListener l)
l
- the listener to be registered.
NullPointerException
- if l is null.public void removePeriodChangeListener(PeriodChangeListener l)
l
- the period change listener being removed.public void clearPeriodChangeListeners()
public List<PeriodChangeListener> getPeriodChangeListeners()
public void init()
init (simulator().time())
.
init
in interface Initializable
public void init(double initTime)
start()
is called,
no period changes will be scheduled
before initTime.
initTime
- the initialization time.public void initAndNotify()
initAndNotify (simulator().time())
.
public void initAndNotify(double initTime)
init()
and notifies the
period-change listeners if the period changed
due to the initialization.
This can be useful to force period-change listeners
to restore parameters.
public void start()
start
in interface ToggleElement
public void stop()
PeriodChangeListener.stop(PeriodChangeEvent)
method of
all registered PeriodChangeListener
implementations.
stop
in interface ToggleElement
public boolean wasStopped()
init()
.
public boolean isStarted()
ToggleElement
isStarted
in interface ToggleElement
public boolean cancel()
cancel
in class Event
public int getCurrentPeriod()
public void setCurrentPeriod(int p)
init()
, or initAndNotify()
.
However,
this method can be used multiple
times without calling init()
.
Each time this method changes the current period,
registered period-change listeners are notified.
p
- the new period index.
IllegalArgumentException
- if the period index is
negative or greater than or equal to getNumPeriods()
.public boolean isLockedPeriod()
setCurrentPeriod(int)
from the last call to init()
.
When the period is locked, only calls to setCurrentPeriod(int)
can change the period index.
If the period is not locked, this returns false.
public int getCurrentMainPeriod()
getMainPeriod
(getCurrentPeriod()
).
public boolean isPreliminaryPeriod(int period)
period
- the tested period index.
public boolean isMainPeriod(int period)
getNumPeriods()
- 2.
period
- the tested period index.
public boolean isWrapupPeriod(int period)
getNumPeriods()
- 1.
period
- the tested period index.
public int getMainPeriod(int period)
period
- the period index to be processed.
public int getPeriod(double simTime)
simTime
- the simulation time.
public boolean isPeriodStartingTime(double time)
start()
is called.
One can use getPeriod(double)
to obtain
the period corresponding to the given
simulation time if needed.
time
- the simulation time to test.
public double getPeriodStartingTime(int period)
period
- the index of the queried period.
IllegalArgumentException
- if the period index is invalid.public double getPeriodEndingTime(int period)
stop()
was called. If it was not called yet,
this returns the current simulation time
if the current period is the last one or
Double.NaN otherwise.
period
- the queried period.
IllegalArgumentException
- if the period index is invalid.public double getPeriodDuration(int period)
getPeriodEndingTime(int)
minus
getPeriodStartingTime(int)
.
period
- the period of interest.
IllegalArgumentException
- if the period index is invalid.public int getNumPeriods()
public int getNumMainPeriods()
getNumPeriods()
- 2.
public void actions()
actions
in class Event
public String toString()
toString
in class Object
|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |