Class 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.

    • 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
      • 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 element
        name - the name of the model element
      • ResponseSchedule

        public ResponseSchedule​(ModelElement parent,
                                double startTime)
        Parameters:
        parent - the parent model element
        startTime - 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 element
        startTime - 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 element
        startTime - 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 element
        startTime - the time to start the schedule, must be finite. If negative, it will never occur.
        repeatSchedule - Whether or not the schedule will repeat
        name - 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 schedule
        label - the label associated with the interval, must not be null
        duration - 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 intervals
        duration - the duration of each interval
        label - 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 intervals
        duration - 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 schedule
        numIntervals - the number of intervals
        duration - 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 schedule
        numIntervals - the number of intervals
        duration - the duration of each interval
        label - 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 class ModelElement
        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 class ModelElement
        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 class ModelElement
      • 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 class ModelElement
      • responseIntervalEnded

        protected void responseIntervalEnded​(ResponseInterval responseInterval)
        Used to communicate that the response interval ended
        Parameters:
        responseInterval - the interval that ended