Class ResponseSchedule
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.variable.ResponseSchedule
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class ResponseSchedule extends SchedulingElement
This class allows the creation of a schedule that represents a list of intervals of time. The starting length of a schedule is 0.0. The length of a schedule depends upon the intervals added to it. The schedule's length encompasses the furthest interval added. If no intervals are added, then the schedule only has its start time and no response collection will occur.The user adds intervals and responses for which statistics need to be collected during the intervals. The intervals within the cycle may overlap in time. The start time of an interval is specified relative to the beginning of the cycle. The length of any interval must be finite.
The schedule can be started any time after the start of the simulation. The default starting time of the schedule is time 0.0. The schedule will start automatically at the designated start time.
The schedule can be repeated after the cycle length of the schedule is reached. The default is for the schedule to automatically repeat. Note that depending on the simulation run length only a portion of the scheduled intervals may be executed.
The classic use case of this class is to collect statistics for each hour of the day. In this case, the user would use the addIntervals() method to add 24 intervals of 1 hour duration. Then responses (response variables, time weighted variables, and counters) can be added to the schedule. In which case, they will be added to each interval. Thus, interval statistics for each of the 24 intervals will be collected for everyone of the added responses. If more than one day is simulated and the schedule is allowed to repeat, then statistics are collected across the days. That is, the statistics of hour 1 on day 1 are averaged with the statistics of hour 1 on all subsequent days.
This functionality is built on the ResponseInterval class, which can be used separately. In other words, response intervals do not have to be on a schedule. The schedule facilitates the collection of many responses across many intervals.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ResponseSchedule.StartScheduleAction
-
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 double
myCycleStartTime
The time that the schedule started for its current cycleprotected double
myLength
Represents the length of time of the schedule based on the intervals addedprotected boolean
myScheduledFlag
Indicates if the schedule has been scheduled to startprotected java.util.Set<ResponseInterval>
myScheduledIntervals
Holds the set of intervals that have been scheduledprotected java.util.List<ResponseScheduleItem>
myScheduleItems
Holds the intervals to be invoked on scheduleprotected boolean
myScheduleRepeatFlag
The schedule repeat flag controls whether or not the entire schedule will repeat after its entire cycle has elapsed.protected ResponseSchedule.StartScheduleAction
myStartAction
protected JSLEvent
myStartEvent
Represents the event scheduled to start the scheduleprotected double
myStartTime
The time that the schedule should startint
START_EVENT_PRIORITY
Need to ensure that start event happens before interval responses-
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
-
-
Constructor Summary
Constructors Constructor Description ResponseSchedule(ModelElement parent)
ResponseSchedule(ModelElement parent, double startTime)
ResponseSchedule(ModelElement parent, double startTime, boolean repeatSchedule)
ResponseSchedule(ModelElement parent, double startTime, boolean repeatSchedule, java.lang.String name)
ResponseSchedule(ModelElement parent, double startTime, java.lang.String name)
ResponseSchedule(ModelElement parent, java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCountersToAllIntervals(java.util.Collection<Counter> counters)
There must not be any duplicates in the collection or null values.void
addCounterToAllIntervals(Counter counter)
Causes interval statistics to be collected for the counter for every interval in the schedulevoid
addIntervals(double startTime, int numIntervals, double duration)
Add non-overlapping, sequential intervals to the schedule, each having the provided durationvoid
addIntervals(double startTime, int numIntervals, double duration, java.lang.String label)
Add non-overlapping, sequential intervals to the schedule, each having the provided durationvoid
addIntervals(int numIntervals, double duration)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration, starting 0 time units after the schedule startsvoid
addIntervals(int numIntervals, double duration, java.lang.String label)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration, starting 0 time units after the schedule startsResponseScheduleItem
addResponseInterval(double startTime, double duration, java.lang.String label)
Add an interval for collecting responses to the schedule.void
addResponsesToAllIntervals(java.util.Collection<ResponseVariable> responses)
There must not be any duplicates in the collection or null values.void
addResponseToAllIntervals(ResponseVariable response)
Causes interval statistics to be collected for the response for every interval in the scheduleprotected 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()
double
getCycleStartTime()
Returns the time that the schedule started its current cycledouble
getElapsedCycleTime()
The time that has elapsed into the current cycledouble
getLength()
Gets the total length of the schedule.int
getNumberOfIntervals()
The number of intervals in the scheduledouble
getRemainingCycleTime()
The time remaining within the current cyclejava.util.List<ResponseScheduleItem>
getResponseScheduleItems()
An unmodifiable list of the ResponseScheduleItemsboolean
getScheduleRepeatFlag()
Returns whether or not the schedule will repeat after it reaches it lengthdouble
getStartTime()
protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.boolean
isScheduled()
protected void
responseIntervalEnded(ResponseInterval responseInterval)
Used to communicate that the response interval endedvoid
setScheduleRepeatFlag(boolean flag)
Sets whether or not the schedule will repeat after it reaches it lengthjava.lang.String
toString()
Includes the model name, the id, the model element name, the parent name, and parent id-
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_, update, useControls, warmUp, warmUp_, week
-
-
-
-
Field Detail
-
START_EVENT_PRIORITY
public final int START_EVENT_PRIORITY
Need to ensure that start event happens before interval responses- See Also:
- Constant Field Values
-
myStartTime
protected double myStartTime
The time that the schedule should start
-
myCycleStartTime
protected double myCycleStartTime
The time that the schedule started for its current cycle
-
myScheduleRepeatFlag
protected boolean myScheduleRepeatFlag
The schedule repeat flag controls whether or not the entire schedule will repeat after its entire cycle has elapsed. The default is true.
-
myLength
protected double myLength
Represents the length of time of the schedule based on the intervals added
-
myScheduleItems
protected final java.util.List<ResponseScheduleItem> myScheduleItems
Holds the intervals to be invoked on schedule
-
myScheduledIntervals
protected final java.util.Set<ResponseInterval> myScheduledIntervals
Holds the set of intervals that have been scheduled
-
myStartEvent
protected JSLEvent myStartEvent
Represents the event scheduled to start the schedule
-
myStartAction
protected final ResponseSchedule.StartScheduleAction myStartAction
-
myScheduledFlag
protected boolean myScheduledFlag
Indicates if the schedule has been scheduled to start
-
-
Constructor Detail
-
ResponseSchedule
public ResponseSchedule(ModelElement parent)
- Parameters:
parent
- the parent model element
-
ResponseSchedule
public ResponseSchedule(ModelElement parent, java.lang.String name)
- Parameters:
parent
- the parent model elementname
- the name of the model element
-
ResponseSchedule
public ResponseSchedule(ModelElement parent, double startTime)
- Parameters:
parent
- the parent model elementstartTime
- the time to start the schedule, must be finite. If negative, it will never occur.
-
ResponseSchedule
public ResponseSchedule(ModelElement parent, double startTime, boolean repeatSchedule)
- Parameters:
parent
- the parent model elementstartTime
- the time to start the schedule, must be finite. If negative, it will never occur.repeatSchedule
- Whether or not the schedule will repeat
-
ResponseSchedule
public ResponseSchedule(ModelElement parent, double startTime, java.lang.String name)
- Parameters:
parent
- the parent model elementstartTime
- the time to start the schedule, must be finite. If negative, it will never occur.name
- the name of the model element
-
ResponseSchedule
public ResponseSchedule(ModelElement parent, double startTime, boolean repeatSchedule, java.lang.String name)
- Parameters:
parent
- the parent model elementstartTime
- the time to start the schedule, must be finite. If negative, it will never occur.repeatSchedule
- Whether or not the schedule will repeatname
- the name of the model element
-
-
Method Detail
-
getStartTime
public final double getStartTime()
- Returns:
- the time to start the schedule
-
isScheduled
public final boolean isScheduled()
- Returns:
- true if the schedule has been started
-
cancelScheduleStart
public final void cancelScheduleStart()
-
getCycleStartTime
public final double getCycleStartTime()
Returns the time that the schedule started its current cycle- Returns:
- the cycle start time
-
getElapsedCycleTime
public final double getElapsedCycleTime()
The time that has elapsed into the current cycle- Returns:
- the time within the cycle
-
getRemainingCycleTime
public final double getRemainingCycleTime()
The time remaining within the current cycle- Returns:
- time remaining within the current cycle
-
setScheduleRepeatFlag
public final void setScheduleRepeatFlag(boolean flag)
Sets whether or not the schedule will repeat after it reaches it length- Parameters:
flag
- true means repeats
-
getScheduleRepeatFlag
public final boolean getScheduleRepeatFlag()
Returns whether or not the schedule will repeat after it reaches it length- Returns:
- true means it repeats
-
getLength
public final double getLength()
Gets the total length of the schedule.- Returns:
- the length
-
getNumberOfIntervals
public final int getNumberOfIntervals()
The number of intervals in the schedule- Returns:
- number of interval in the schedule
-
getResponseScheduleItems
public final java.util.List<ResponseScheduleItem> getResponseScheduleItems()
An unmodifiable list of the ResponseScheduleItems- Returns:
- An unmodifiable list of the ResponseScheduleItems
-
addResponseToAllIntervals
public final void addResponseToAllIntervals(ResponseVariable response)
Causes interval statistics to be collected for the response for every interval in the schedule- Parameters:
response
- the response to add
-
addResponsesToAllIntervals
public final void addResponsesToAllIntervals(java.util.Collection<ResponseVariable> responses)
There must not be any duplicates in the collection or null values. Causes interval statistics to be collected for all the responses for every interval in the schedule.- Parameters:
responses
- a collection of unique ResponseVariable instances
-
addCounterToAllIntervals
public final void addCounterToAllIntervals(Counter counter)
Causes interval statistics to be collected for the counter for every interval in the schedule- Parameters:
counter
- the counter to add
-
addCountersToAllIntervals
public final void addCountersToAllIntervals(java.util.Collection<Counter> counters)
There must not be any duplicates in the collection or null values. Causes interval statistics to be collected for all the counters for every interval in the schedule.- Parameters:
counters
- a collection of unique Counter instances
-
addResponseInterval
public final ResponseScheduleItem addResponseInterval(double startTime, double duration, java.lang.String label)
Add an interval for collecting responses to the schedule. If the start time plus the duration reaches past the current schedule length, the schedule length is extended to include the interval.- Parameters:
startTime
- must be greater than or equal to zero. Represents start time relative to start of schedulelabel
- the label associated with the interval, must not be nullduration
- duration of the interval, must be finite and strictly positive- Returns:
- the ResponseScheduleItem
-
addIntervals
public final void addIntervals(int numIntervals, double duration, java.lang.String label)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration, starting 0 time units after the schedule starts- Parameters:
numIntervals
- the number of intervalsduration
- the duration of each intervallabel
- a base label for each interval, if null a label is created
-
addIntervals
public final void addIntervals(int numIntervals, double duration)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration, starting 0 time units after the schedule starts- Parameters:
numIntervals
- the number of intervalsduration
- the duration of each interval
-
addIntervals
public final void addIntervals(double startTime, int numIntervals, double duration)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration- Parameters:
startTime
- must not be negative. Represents start time of first interval relative to the start time of the schedulenumIntervals
- the number of intervalsduration
- the duration of each interval
-
addIntervals
public final void addIntervals(double startTime, int numIntervals, double duration, java.lang.String label)
Add non-overlapping, sequential intervals to the schedule, each having the provided duration- Parameters:
startTime
- must not be negative. Represents start time of first interval relative to the start time of the schedulenumIntervals
- the number of intervalsduration
- the duration of each intervallabel
- a base label for each interval, if null a label is created
-
toString
public java.lang.String toString()
Includes the model name, the id, the model element name, the parent name, and parent id- Overrides:
toString
in classModelElement
- Returns:
- a string representing the model element
-
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
-
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
-
responseIntervalEnded
protected void responseIntervalEnded(ResponseInterval responseInterval)
Used to communicate that the response interval ended- Parameters:
responseInterval
- the interval that ended
-
-