com.xj.anylogic.engine
Class Schedule<V extends java.io.Serializable>

java.lang.Object
  extended by com.xj.anylogic.engine.Schedule<V>
Type Parameters:
V - the type of schedule values
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, java.io.Serializable

public class Schedule<V extends java.io.Serializable>
extends java.lang.Object
implements java.io.Serializable, com.xj.anylogic.engine.internal.Child

Schedule class. Allows to track moments specified using time table with some period. Also, annual and single exceptions may be added to the schedule.
Schedule provides 4 types of information:

All these accessor methods are available in several forms: This object may be used for event scheduling. See the following code example (please note, that it is more preferable to use getTimeOfNextValue() method instead of getTimeoutToNextValue() because of possible numeric calculation errors). Create the timeout event which occurs once at the time:
        schedule.getTimeOfValue() == time() ? time() : schedule.getTimeOfNextValue()
 
and has the following action code:
        // ...your custom actions are here...
        event.restartTo( schedule.getTimeOfNextValue() );
 

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Constructor Summary
Schedule(Utilities owner, boolean calendarType, int firstDayOfWeek, long period, long timeUnits, java.lang.Long snapTo, V defaultValue, long[] starts, long[] ends, java.lang.Object[] values, boolean glueIntervals, boolean[] exceptionsAnnually, boolean singleThreadMode)
          Creates new schedule object
 
Method Summary
 java.util.Date getDateOfNextValue()
          Returns the model date of the next change moment in the schedule.
 java.util.Date getDateOfNextValue(java.util.Date date)
          Returns the model date of the schedule change moment next to the given model date.
 java.util.Date getDateOfNextValue(double time)
          Returns the model date of the schedule change moment next to the given model time.
 java.util.Date getDateOfValue()
          Returns the model date the current value of the schedule has been held since.
 java.util.Date getDateOfValue(java.util.Date date)
          Returns the model date of the schedule change moment of the value corresponding to the given model date.
 java.util.Date getDateOfValue(double time)
          Returns the model date of the schedule change moment of the value corresponding to the given model time.
 V getNextValue()
          Returns the value of the next change moment in the schedule.
 V getNextValue(java.util.Date date)
          Returns the value of the schedule change moment next to the given model date.
 V getNextValue(double time)
          Returns the value of the schedule change moment next to the given model time.
 double getTimeOfNextValue()
          Returns the model time of the next change moment in the schedule.
 double getTimeOfNextValue(java.util.Date date)
          Returns the model time of the schedule change moment next to the given model date.
 double getTimeOfNextValue(double time)
          Returns the model time of the schedule change moment next to the given model time.
 double getTimeOfValue()
          Returns the model time the current value of the schedule has been held since.
 double getTimeOfValue(java.util.Date date)
          Returns the model time of the schedule change moment of the value corresponding to the given model date.
 double getTimeOfValue(double time)
          Returns the model time of the schedule change moment of the value corresponding to the given model time.
 double getTimeoutToNextValue()
          Returns timeout to the next change moment in the schedule, measured in the model time units from the current model time.
 double getTimeoutToNextValue(java.util.Date date)
          Returns timeout to the schedule change moment next to the given model date, measured in the model time units from that model date.
 double getTimeoutToNextValue(double time)
          Returns timeout to the schedule change moment next to the given time, measured in the model time units from that time.
 long getTimeUnits()
          Returns time units of the schedule
 V getValue()
          Returns the value corresponding to the current model time
 V getValue(java.util.Date date)
          Returns the value of the schedule corresponding to the given model date.
 V getValue(double time)
          Returns the value of the schedule corresponding to the given model time.
 void restoreOwner(java.lang.Object owner)
          This method normally should not be called by user
This method restores owner of this object
This method is used in snapshot saving/loading
Note, that some objects may support several owners (e.g. of different types)
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Schedule

public Schedule(Utilities owner,
                boolean calendarType,
                int firstDayOfWeek,
                long period,
                long timeUnits,
                java.lang.Long snapTo,
                V defaultValue,
                long[] starts,
                long[] ends,
                java.lang.Object[] values,
                boolean glueIntervals,
                boolean[] exceptionsAnnually,
                boolean singleThreadMode)
Creates new schedule object

Parameters:
owner - active object or experiment owning the schedule
calendarType - if true then schedule works with calendar dates. For example, if you create a schedule for 8:00-17:00 each day - these times will be preserved even during the days of Daylight Saving Time switching.
If this parameter is false, "1 day" will be treated as 24*60*60 seconds - this is good for modeling the behavior of some automatic machines which don't watch at the wall-clock during e.g. self-maintenance procedures.
firstDayOfWeek - the first day of the week, this parameter is actually used when calendarType == true and timeUnit is week
period - recurrence period of the schedule, measured in milliseconds. Milliseconds may be actual - if calendarType is false, and hypothetical - if true, which means that 1000*60*60*24 milliseconds denotes one day independently on Daylight Saving Time switching.
timeUnits - time units of the schedule, one of TIME_UNIT_* constants
In the calendar-mode the only supported time units are day and week
snapTo - the absolute date (if calendarType==true) or the number of milliseconds from the zero model time (if calendarType==false) which points to the start of some period. All schedule periods are cloned, started from the given time moment in both directions.
defaultValue - the value used when there is no interval defined in the schedule
starts - start times of intervals, measured in milliseconds from the beginning of the period (milliseconds may be actual - if calendarType is false, and hypothetical - if true, which means that 1000*60*60*24 milliseconds denotes one day independently on Daylight Saving Time switching). This array may also contain starts of exceptions (see exceptionsAnnually parameter)
ends - end times of intervals, the same description as for starts
values - values for intervals
glueIntervals - if true then intersecting intervals with the same 'value' will be merged, e.g. two intervals "Day1 18:00-24:00 value=5" and "Day2 00:00-02:00 value=5" will be treated as one interval "Day1 18:00 - Day2 02:00 value=5"
exceptionsAnnually - the array of exception flags (true means annual exception, false - single occurrence), may be empty. The number of exceptions equals the length of exceptionsAnnually array. The exceptions are read from starts, ends, values arrays. Exceptions data is located in the tails of these arrays. Note that for exceptions, starts and ends arrays contain absolute dates encoded as long numbers (see Date.getTime()).
singleThreadMode - this parameter indicates whether schedule will work in single thread environment or will be used by multiple concurrent threads. This parameter is usually set to true for schedules inside active objects and experiment which don't allow parallel execution (e.g. simulation experiment). But for schedules, located in optimization and parameter variation experiment which allow parallel execution this parameter should be set to false.
Method Detail

getTimeUnits

public long getTimeUnits()
Returns time units of the schedule

Returns:
time units of the schedule, one of TIME_UNIT_* constants

getTimeoutToNextValue

public double getTimeoutToNextValue()
Returns timeout to the next change moment in the schedule, measured in the model time units from the current model time.
In case when there is no 'next' value, returns positive infinity

Returns:
the timeout to the next schedule change or +infinity

getTimeoutToNextValue

public double getTimeoutToNextValue(double time)
Returns timeout to the schedule change moment next to the given time, measured in the model time units from that time.
In case when there is no 'next' value, returns positive infinity.
In case of +/-infinity or NaN argument value, returns Double.NaN

Returns:
the timeout to the schedule change next to the given time or +infinity

getTimeoutToNextValue

public double getTimeoutToNextValue(java.util.Date date)
Returns timeout to the schedule change moment next to the given model date, measured in the model time units from that model date.
In case when there is no 'next' value, returns positive infinity.
In case of null argument value, returns Double.NaN

Returns:
the timeout to the schedule change next to the given date or +infinity

getTimeOfNextValue

public double getTimeOfNextValue()
Returns the model time of the next change moment in the schedule.
In case when there is no 'next' value, returns positive infinity

Returns:
the model time of the next schedule change or +infinity

getTimeOfNextValue

public double getTimeOfNextValue(double time)
Returns the model time of the schedule change moment next to the given model time.
In case when there is no 'next' value, returns positive infinity.
In case of +/-infinity or NaN argument value, returns Double.NaN

Returns:
the model time of the schedule change next to the given time or +infinity

getTimeOfNextValue

public double getTimeOfNextValue(java.util.Date date)
Returns the model time of the schedule change moment next to the given model date.
In case when there is no 'next' value, returns positive infinity.
In case of null argument value, returns Double.NaN

Returns:
the model time of the schedule change next to the given date or +infinity

getDateOfNextValue

public java.util.Date getDateOfNextValue()
Returns the model date of the next change moment in the schedule.
In case when there is no 'next' value, returns null

Returns:
the model date of the next schedule change or null

getDateOfNextValue

public java.util.Date getDateOfNextValue(double time)
Returns the model date of the schedule change moment next to the given model time.
In case when there is no 'next' value, returns null.
In case of +/-infinity or NaN argument value, returns null

Returns:
the model date of the schedule change next to the given time or null

getDateOfNextValue

public java.util.Date getDateOfNextValue(java.util.Date date)
Returns the model date of the schedule change moment next to the given model date.
In case when there is no 'next' value, returns null.
In case of null argument value, returns null

Returns:
the model date of the schedule change next to the given date or null

getNextValue

public V getNextValue()
Returns the value of the next change moment in the schedule.
In case when there is no 'next' value, returns null

Returns:
the value of the next schedule change or null

getNextValue

public V getNextValue(double time)
Returns the value of the schedule change moment next to the given model time.
In case when there is no 'next' value, returns null.
In case of +/-infinity or NaN argument value, returns null

Returns:
the value of the schedule change next to the given time or null

getNextValue

public V getNextValue(java.util.Date date)
Returns the value of the schedule change moment next to the given model date.
In case when there is no 'next' value, returns null.
In case of null argument value, returns null

Returns:
the value of the schedule change next to the given date or null

getTimeOfValue

public double getTimeOfValue()
Returns the model time the current value of the schedule has been held since.
If the schedule has always been holding the current value, the method returns negative infinity

Returns:
the model time of the current schedule change or -infinity

getTimeOfValue

public double getTimeOfValue(double time)
Returns the model time of the schedule change moment of the value corresponding to the given model time.
If the schedule has always been holding the current value (up to the given time), the method returns negative infinity.
In case of +/-infinity or NaN argument value, returns Double.NaN

Returns:
the model time of the schedule change corresponding to the given time or -infinity

getTimeOfValue

public double getTimeOfValue(java.util.Date date)
Returns the model time of the schedule change moment of the value corresponding to the given model date.
If the schedule has always been holding the current value (up to the given date), the method returns negative infinity.
In case of null argument value, returns Double.NaN

Returns:
the model time of the schedule change corresponding to the given date or -infinity

getDateOfValue

public java.util.Date getDateOfValue()
Returns the model date the current value of the schedule has been held since.
If the schedule has always been holding the current value, the method returns null

Returns:
the model date of the current schedule change or null

getDateOfValue

public java.util.Date getDateOfValue(double time)
Returns the model date of the schedule change moment of the value corresponding to the given model time.
If the schedule has always been holding the current value (up to the given time), the method returns null.
In case of +/-infinity or NaN argument value, returns null

Returns:
the model date of the schedule change corresponding to the given time or null

getDateOfValue

public java.util.Date getDateOfValue(java.util.Date date)
Returns the model date of the schedule change moment of the value corresponding to the given model date.
If the schedule has always been holding the current value (up to the given date), the method returns null.
In case of null argument value, returns null

Returns:
the model time of the schedule change corresponding to the given date or null

getValue

public V getValue()
Returns the value corresponding to the current model time

Returns:
the value corresponding to the current model time

getValue

public V getValue(double time)
Returns the value of the schedule corresponding to the given model time.
In case of +/-infinity or NaN argument value, returns null

Parameters:
time - the model time
Returns:
the value corresponding to the given model time

getValue

public V getValue(java.util.Date date)
Returns the value of the schedule corresponding to the given model date.
In case of null argument value, returns null

Parameters:
date - the model date
Returns:
the value corresponding to the given model date

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

restoreOwner

public void restoreOwner(java.lang.Object owner)
Description copied from interface: com.xj.anylogic.engine.internal.Child
This method normally should not be called by user
This method restores owner of this object
This method is used in snapshot saving/loading
Note, that some objects may support several owners (e.g. of different types)

Specified by:
restoreOwner in interface com.xj.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.