Package jsl.modeling.elements
Class Schedule
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.Schedule
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class Schedule extends SchedulingElement
A Schedule represents a known set of events that can occur according to a pattern. A schedule contains one or more instances of ScheduleItem. A ScheduleItem represents an item on a Schedule. It has a start time, relative to the start of the Schedule and a duration. If more than one schedule item needs to start at the same time, then a priority can be provided to determine the ordering (smallest priority goes first). ScheduleItems are not scheduled to occur until the Schedule actually starts. A Schedule has an auto start flag, which controls whether or not the schedule should start automatically upon initialization (at the start of the simulation). The default is to start automatically. A Schedule has an initial start time, which represents the amount of time after the beginning of the simulation that the schedule is to start. The default start time is zero (at the beginning of the simulation). A Schedule as a length (or duration) that represents the total time associated with the schedule. After this time has elapsed the entire schedule can repeat if the repeat option is on. The default length of a schedule is infinite. The total or maximum duration of scheduled items cannot exceed the schedule duration if it is finite. A Schedule has a repeat flag that controls whether or not it will repeat after its duration has elapsed. The default is to repeat the schedule and is only relevant if the schedule duration (length) is finite. A Schedule has a cycle start time that represents when the schedule started its current cycle. Again, this is only relevant if the repeat flag is true and the schedule duration is finite. If there is only one cycle, it is the time that the schedule started. A builder is used to configure the schedule and then items are added to the schedule. If no items are added to the schedule, then there will still be an event to start the schedule. To make a Schedule useful, instances of the ScheduleChangeListenerIfc interface should be added to listen for changes in the schedule. Instances of ScheduleChangeListenerIfc are notified in the order in which they are added to the schedule. Instances of ScheduleChangeListenerIfc are notified when the schedule starts, when it ends, and when any ScheduleItem starts and ends. It is up to the instance of ScheduleChangeListenerIfc to react to the schedule changes that it needs to react to and ignore those that it does not care about.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Schedule.Builder
A builder for configuring the set up of a Scheduleclass
Schedule.ScheduleItem<T>
A ScheduleItem represents an item on a Schedule.-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<ScheduleChangeListenerIfc>
myChangeListeners
protected java.util.List<Schedule.ScheduleItem<?>>
myItems
protected JSLEvent
myStartScheduleEvent
-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Schedule.ScheduleItem
addItem(double duration)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY and default start time of 0.0 (i.e.Schedule.ScheduleItem
addItem(double startTime, double duration)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITYSchedule.ScheduleItem
addItem(double startTime, double duration, int priority)
Adds an item to the schedule<T> Schedule.ScheduleItem<T>
addItem(double startTime, double duration, int priority, T message)
Adds an item to the schedule<T> Schedule.ScheduleItem<T>
addItem(double startTime, double duration, T message)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITYvoid
addScheduleChangeListener(ScheduleChangeListenerIfc listener)
The same listener cannot be added more than once.protected void
afterReplication()
This method should be overridden by subclasses that need actions performed after each replication.java.lang.String
asString()
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a Stringvoid
cancelScheduleStart()
If scheduled to start, this cancels the start of the schedule.void
clearSchedule()
Removes all schedule items from the scheduleboolean
contains(ScheduleChangeListenerIfc listener)
int
countScheduleChangeListeners()
void
deleteScheduleChangeListener(ScheduleChangeListenerIfc listener)
void
deleteScheduleChangeListeners()
Deletes all listenersprotected void
endItem(JSLEvent evt)
protected void
endSchedule(JSLEvent evt)
double
getCycleStartTime()
double
getInitialStartTime()
int
getItemStartEventPriority()
double
getScheduleLength()
int
getStartEventPriority()
protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.boolean
isAutoStartFlag()
boolean
isScheduleRepeatable()
protected void
notifyScheduleChangeListenersScheduleEnded()
protected void
notifyScheduleChangeListenersScheduleItemEnded(Schedule.ScheduleItem<?> item)
protected void
notifyScheduleChangeListenersScheduleItemStarted(Schedule.ScheduleItem<?> item)
protected void
notifyScheduleChangeListenersScheduleStarted()
void
removeItem(Schedule.ScheduleItem item)
Removes the item from the schedule.protected void
scheduleEndOfSchedule()
protected void
scheduleItemEnd(Schedule.ScheduleItem item)
protected void
scheduleItemStart(Schedule.ScheduleItem item)
void
scheduleStart()
Schedules the start of the schedule for the start time of the schedule if it has not already be startedprotected void
startItem(JSLEvent evt)
protected void
startSchedule(JSLEvent evt)
-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication_, beforeExperiment, beforeExperiment_, beforeReplication, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, initialize_, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removedFromModel, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate, timedUpdate_, toString, update, useControls, warmUp, warmUp_, week
-
-
-
-
Field Detail
-
myItems
protected final java.util.List<Schedule.ScheduleItem<?>> myItems
-
myChangeListeners
protected final java.util.List<ScheduleChangeListenerIfc> myChangeListeners
-
myStartScheduleEvent
protected JSLEvent myStartScheduleEvent
-
-
Method Detail
-
isAutoStartFlag
public final boolean isAutoStartFlag()
- Returns:
- true if the schedule starts automatically
-
getStartEventPriority
public final int getStartEventPriority()
- Returns:
- the priority associated with the schedule's start event
-
getItemStartEventPriority
public final int getItemStartEventPriority()
- Returns:
- the priority associated with the item's start event
-
getInitialStartTime
public final double getInitialStartTime()
- Returns:
- the time relative to the start of the simulation that indicates when the schedule should start
-
isScheduleRepeatable
public final boolean isScheduleRepeatable()
- Returns:
- true if the schedule repeats after completing
-
getScheduleLength
public final double getScheduleLength()
- Returns:
- the length or duration of the schedule
-
getCycleStartTime
public final double getCycleStartTime()
- Returns:
- when the schedule actually starts, if repeated the time it last started
-
cancelScheduleStart
public final void cancelScheduleStart()
If scheduled to start, this cancels the start of the schedule.
-
addScheduleChangeListener
public void addScheduleChangeListener(ScheduleChangeListenerIfc listener)
The same listener cannot be added more than once. Listeners are notified of schedule changes in the sequence by which they were added.- Parameters:
listener
- the listener to add to the schedule
-
deleteScheduleChangeListener
public void deleteScheduleChangeListener(ScheduleChangeListenerIfc listener)
- Parameters:
listener
- the listener to delete from the schedule
-
deleteScheduleChangeListeners
public void deleteScheduleChangeListeners()
Deletes all listeners
-
contains
public boolean contains(ScheduleChangeListenerIfc listener)
- Parameters:
listener
- the listener to check- Returns:
- true if the listener is already added
-
countScheduleChangeListeners
public int countScheduleChangeListeners()
- Returns:
- the number of listeners
-
addItem
public Schedule.ScheduleItem addItem(double duration)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY and default start time of 0.0 (i.e. when the schedule starts)- Parameters:
duration
- the duration of the item- Returns:
- the created ScheduleItem
-
addItem
public Schedule.ScheduleItem addItem(double startTime, double duration)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY- Parameters:
startTime
- the time past the start of the schedule to start the itemduration
- the duration of the item- Returns:
- the created ScheduleItem
-
addItem
public Schedule.ScheduleItem addItem(double startTime, double duration, int priority)
Adds an item to the schedule- Parameters:
startTime
- the time past the start of the schedule to start the itemduration
- the duration of the itempriority
- the priority, among items, if items start at the same time- Returns:
- the created ScheduleItem
-
addItem
public <T> Schedule.ScheduleItem<T> addItem(double startTime, double duration, T message)
Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY- Type Parameters:
T
- the type of the message- Parameters:
startTime
- the time past the start of the schedule to start the itemduration
- the duration of the itemmessage
- a message or datum to attach to the item- Returns:
- the created ScheduleItem
-
addItem
public <T> Schedule.ScheduleItem<T> addItem(double startTime, double duration, int priority, T message)
Adds an item to the schedule- Type Parameters:
T
- the type of the message- Parameters:
startTime
- the time past the start of the schedule to start the itemduration
- the duration of the itempriority
- the priority, (among items) if items start at the same timemessage
- a message or datum to attach to the item- Returns:
- the created ScheduleItem
-
removeItem
public void removeItem(Schedule.ScheduleItem item)
Removes the item from the schedule. If the item is null or not on this schedule nothing happens.- Parameters:
item
- the item to remove
-
clearSchedule
public void clearSchedule()
Removes all schedule items from the schedule
-
asString
public java.lang.String asString()
Description copied from class:ModelElement
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String- Overrides:
asString
in classModelElement
- Returns:
- a detailed String representation
-
notifyScheduleChangeListenersScheduleStarted
protected void notifyScheduleChangeListenersScheduleStarted()
-
notifyScheduleChangeListenersScheduleEnded
protected void notifyScheduleChangeListenersScheduleEnded()
-
notifyScheduleChangeListenersScheduleItemEnded
protected void notifyScheduleChangeListenersScheduleItemEnded(Schedule.ScheduleItem<?> item)
-
notifyScheduleChangeListenersScheduleItemStarted
protected void notifyScheduleChangeListenersScheduleItemStarted(Schedule.ScheduleItem<?> item)
-
initialize
protected void initialize()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called- Overrides:
initialize
in classModelElement
-
afterReplication
protected void afterReplication()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.- Overrides:
afterReplication
in classModelElement
-
scheduleStart
public final void scheduleStart()
Schedules the start of the schedule for the start time of the schedule if it has not already be started
-
startSchedule
protected void startSchedule(JSLEvent evt)
-
endSchedule
protected void endSchedule(JSLEvent evt)
-
startItem
protected void startItem(JSLEvent evt)
-
endItem
protected void endItem(JSLEvent evt)
-
scheduleEndOfSchedule
protected final void scheduleEndOfSchedule()
-
scheduleItemStart
protected final void scheduleItemStart(Schedule.ScheduleItem item)
-
scheduleItemEnd
protected final void scheduleItemEnd(Schedule.ScheduleItem item)
-
-