AnyLogic
Expand
Font size

Schedule

AnyLogic provides users with a Schedule — a special element allowing to define how some value changes in time according to the defined (optionally cyclic) pattern.

Schedule is frequently used to define:

  • Timetable for a pool of resources defined with the ResourcePool.
  • Agent generation times, or time pattern of agent arrival rate in the block Source.
  • Pedestrian generation times, or time pattern (e.g. daily) of pedestrian arrival rate in the block PedSource.

Moreover, you can use schedule in none of the AnyLogic blocks but work with it from your code, obtaining its value using the corresponding API.

The following demo model illustrates how Source generates agents according to the daily rate pattern defined by rate schedule:

Modes

Schedule works in one of two modes: it can either define intervals, or discrete time moments.

The first mode (intervals) is used when you need to define how some value continuously changes in time (usually according to some cyclic pattern). In the present case at any moment of time there is current value defined by the schedule. Intervals are used to define work timetables for worker shifts, cyclic pattern of pedestrian or agent arrival rate, etc.

The second mode (moments) is used when you need to define a sequence of key time moments and some values corresponding to this particular moments (or perform some actions, see the abstract below). The example — train arrival schedule: the specified number of pedestrians appears in the railway station model at the defined arrival moments.

Moreover, you can associate actions with key moments of the schedule (either interval switch times, or time moments — it depends on the schedule mode), by typing Java code in the Action section of the schedule properties. Actions are executed in those key moments, so that you can use schedule as a perfect tool for scheduling an unlimited number of actions in the future (probably, mapped to the particular calendar dates).

Types of value defined by a schedule

Schedule can control values of the following types:

  • on/off (boolean type) — choose this option when the schedule defines time pattern of resource availability for ResourcePool.
  • integer value — the schedule defines e.g. number of workers in a shift; number of agents or pedestrians that enter the system in the defined time moments.
  • real value — the schedule defines e.g. pedestrian or agent arrival rate, but in this case we recommend to use the next option, Rate.
  • Rate — the schedule defines the time pattern for agent or pedestrian arrival rate (when your Source or PedSource block’s Arrivals defined by this Rate schedule). You specify the rate values in the table in the schedule properties and choose the rate units in the Unit property (per second, per minute, per hour, per day, etc.)

Views

You can define a schedule in one of three alternative views:

  • Week  — Use this view in case your schedule has weekly recurrence, e.g. if you need to define a weekly schedule for office men.
  • Days/Weeks — The Calendar view is used when you need to define a schedule as a sequence of calendar dates and times, but with non-weekly recurrence. For instance, it is convenient for defining shift schedules, e.g. every third day (24 hours on, 48 hours off) — such schedule has 3-day recurrence. One more example — daily pattern of pedestrian arrival rate.
  • Custom (no calendar mapping) — There is no mapping to calendar dates in this view. Schedule intervals and moments are defined simply as number of time units (milliseconds, seconds, minutes, hours, days, or weeks) passed from the model start. This view is convenient e.g. for defining maintenance intervention times, failures, etc. for various devices. Define schedule in this view when only interval durations are important, not the exact calendar times.

Schedules defined in the calendar views (Week and Days/Weeks) may have exceptions — particular time intervals when the value defined by this schedule should have other values, differing from the ones specified in the schedule.

Defining a schedule

In general, you define schedule similarly in all views: first, you select the type of the value that you want to control with this schedule (on/off, integer or real), and then define time intervals (or just time moments, it depends on the schedule mode) and specify values for each particular interval or moment. When defined the complete cycle of intervals or moments, you tell the schedule what is the recurrence time for this cycle.

But since the schedule definition varies a bit depending on the currently used view, we decided to consider several examples of schedule definitions:

Properties

General

Name — The name of the schedule. The name is used to access the schedule from block's properties and from code.

Show name — If selected, the name of the schedule is displayed on the presentation diagram.

Ignore — Ibf selected, the schedule is excluded from the model.

Visible — If selected, the schedule icon is visible on a presentation at runtime.

Data

Type — Type of the value defined by this schedule:on/off (the schedule defines the resource availability for ResourcePool), integer, real , or Rate (the schedule defines time pattern of agent or pedestrian arrival rate for Source or PedSource).

Unit — [Visible and applies when the schedule’s Type is set to Rate] Here you define the units for the rate values defined in the schedule’s table. The options are: per second, per minute, per hour, per day, etc.

The schedule defines — Here you can choose the schedule mode: whether it defines Intervals (Start, End), or discrete Time moments.

  • Intervals (Start, End) mode is used when you need to define how some value continuously changes in time (usually according to some cyclic pattern). In the present case at any moment of time there is current value defined by the schedule. Intervals are used to define work timetables for worker shifts, cyclic pattern of pedestrian/agent arrival rate, etc.
  • Moments is used when you need to define a sequence of key time moments and some values corresponding to this particular moments (or perform some actions).

Duration type — Here you choose the duration type of the schedule. Depending on this choice, the schedule is defined in one of three alternative views:

  • Week — Choose this option in case your schedule has weekly recurrence, e.g. if you need to define a weekly schedule for employees.
  • Days/Weeks — Choose this option if you need to define a schedule as a sequence of calendar dates and times, but it has non-weekly recurrence (some number of days or weeks). For instance, it is convenient for defining shift schedules, e.g. every third day (24 hours on, 48 hours off) — such schedule has 3-day recurrence.
  • Custom (no calendar mapping) — There is no mapping to calendar dates in this view. Schedule intervals/moments are defined simply as number of time units (milliseconds, seconds, minutes, hours, days, or weeks) passed from the model start. This view is convenient e.g. for defining maintenance intervention times, failures, etc. for various devices. Define schedule in this view when only interval durations are important, not the exact calendar times.

Default value — [Visible if The schedule defines option is set to Intervals (Start, End)] Here you define the default value for the schedule — the value that will be used for the intervals not defined in the schedule.

Repeat schedule weekly — [Visible if Duration type is set to Week] Here you need to define the weekly schedule for employees, which week days are working and which are not, when the shift starts and ends. Select on / off for Value for each weekly schedule variant.

Repeat every — [Visible if the Duration type is set to Days/Weeks, or Custom (no calendar mapping)] Here you define the recurrence of the schedule.

Snap to — [Visible if the Duration type is set to Days/Weeks or Custom (no calendar mapping)] If you want your schedule to be applied not from its start moment on model launch, here you can define, what model time corresponds to the start moment of the schedule. Please note that this setting does not define the time when the schedule starts applying - it defines how the start of the schedule is shifted regarding the zero model time.

Week starts from — [Visible if Repeat every is set to Weeks] The first day of the week in some countries (e.g. USA) is Sunday, while in some other (e.g. Russia) — Monday. Therefore if you will define a schedule with N-weekly recurrence considering that the first day of the week is Sunday and then send the model to the user from some other country, where the week starts from Monday, the schedule will be misinterpreted. So if you expect that your model will be used in other countries too, please define explicitly the first day of the week in your schedule so that this schedule will be locale-independent. And please do it before defining the schedule intervals, because all interval data in the table are deleted when you change the Weeks start from setting.

Loaded from database — [Visible if the Duration type is set to Days/Weeks or Custom (no calendar mapping)] If selected, allows to load data from the existing table in AnyLogic database defined by the user.

Table — Here you can specify the existing table from AnyLogic database.

  • Choice conditions — Here you define a condition that specifies the particular value to be selected from the specified table column. You can add , duplicate , delete and arrange the conditions (, ).
  • Start column — The column of the table that stores either interval start time data, if your schedule defines non-weekly recurrent intervals, or time moments data, if your schedule defines discrete time moments.
  • End column — [Visible if The schedule defines: Intervals (Start, End)] The column of the table that stores interval end time data.
  • Value column — The column of the table that stores a set of values, each value corresponding to a particular time interval or moment.
Action

Here you can type Java code to be executed in key moments of the schedule (either interval switch times, or time moments — it depends on the schedule mode). Actions are executed in those key moments, so that you can use schedule as a perfect tool for scheduling an unlimited number of actions in the future (probably, mapped to the particular calendar dates).

Exceptions

On this page you can define exceptions for the schedule — particular time intervals when the value defined by this schedule should have other values, differing from the ones specified in the schedule.

Preview

Here you can preview the schedule in the convenient way that is commonly used in digital diaries, organizers, and office software tools. This may help you to check whether the schedule was defined correctly and the resulting picture is the one you have expected to see.

Advanced

System dynamics units — If selected, you will be able to specify units of measurements for the value returned by this schedule in the edit box to the right. Having specified units for elements of your model, you may perform unit checking to find out dimension inconsistencies in the model.

Daylight Saving Time

In some countries Daylight Saving Time (DST) is practiced: time is temporarily adjusted to achieve longer evening daylight by setting the clocks an hour ahead of the standard time (you can find more information on DST in Wikipedia).

AnyLogic schedules consider DST automatically. The information about DST dates in the current country is taken from the computer’s OS settings (the Current locale is taken into account).

  • If the schedule maps to calendar dates (duration type is Week, or Days/Weeks), and e.g. the schedule defines that the resource works from 00:00 to 08:00, at the night the DST starts the resource will actually work seven hours instead of eight, and when the DST ends — nine hours. But the resource will always work from 00:00 to 08:00.

  • And now let’s consider the analogous schedule defined without mapping to the calendar. In this case intervals will always have the same well-defined duration regardless DST. Let’s assume that the model with such schedule starts on some day at 00:00. In this case at the night when DST starts the resource will work 8 hours, but the work hours will shift from 00:00-08:00 to 01:00-09:00 until the DST ends.

Defining a weekly schedule

Use the Week view when your schedule has weekly recurrence, e.g. if you need to define a weekly schedule for office men.

If you need to define a schedule as a sequence of calendar dates and times, but with non-weekly recurrence, please use the Days/Weeks view.

Let’s study how to define a simple weekly schedule of a bank office. Bank office works from Monday till Saturday, from 9 AM till 8 PM, with a dinner hour from 2PM to 3PM. Sunday is day off.

To create a schedule

  1. Drag the  Schedule element from the Agent palette on the graphical diagram of the agent.
  2. Go to the Properties view.
  3. Specify the name of the element in the Name field. This name will be used later on for accessing the schedule from AnyLogic block(s) properties or code.
  4. Go to the Data section of the schedule properties. Choose the type of the value that will be controlled by this schedule from the Type group of buttons: on/off, integer, or real. Since we want to define only how the availability status for the resources controlled by this schedule changes in time (workers are either working (on state), or not (off)), leave the option on/off selected.
  5. Since we want to define values not for some discrete moments, but for time intervals, choose Intervals (Start, End) option from the group of buttons The schedule defines.
  6. Choose the most suitable Duration type for your task: Week, Days/Weeks, or Custom (no calendar mapping) and define the schedule in the chosen view. Since our schedule has weekly recurrence, we choose the most suitable view — Week.
  7. In the Default value field you can specify the default value for the schedule — the value that will be used for the intervals not defined in the schedule. In our case we want to define only work intervals and to assume that the staff is not working in other times, so leave the default off choice selected here.

Now you can complete the schedule definition by defining its intervals. In our case we can mark out two intervals: morning work time before lunch from 9AM to 2 PM and after-lunch time from 3PM to 8PM.

To define schedule intervals

  1. Intervals are defined in the table in the Data section of the schedule properties. Each interval is defined in a separate row of the table.
  2. To add a new interval, click the button to the right of the table. You will see a new row added in the table.

  3. By default five work days (from Monday till Friday) are selected in the row — the corresponding cells have ticked off checks inside. These checks mean that the interval defined in this row will be applied to these particular days.
  4. We need to define the interval for the Saturday too, so tick off the cell in the Sat column also. To change the state of some day of the week, just click in the corresponding cell of the table.

    Until you choose any day(s) in the row, you are not able to add more rows to the table.
  5. Now we need to specify the work interval that corresponds to the time before lunch for these days. Choose 09:00 in the Start cell and 14:00 in the End cell of this table row.

  6. Now let’s define the after-lunch work time for the same days. Thereto we will add one more row into the table. You will see that the same days as in the previous row are automatically selected, so Saturday is already selected and all you need is to define start and end times for this interval: 15:00 and 20:00 correspondingly.

Considering national holidays

Schedules defined in the modes mapped to calendar (Week and Days/Weeks) may have exceptions — particular time intervals when the value defined by this schedule should have other values, differing from the ones defined in the schedule. This is the way you can e.g. consider national holidays in your schedule. You can find more information on defining exceptions in the Exceptions section.

Previewing the schedule

Now you can preview a schedule in the convenient way that is commonly used in digital diaries, organizers, and office software tools. This may help you to check whether the schedule was defined correctly and the resulting picture is the one you have expected to see.

To preview the schedule

  1. Go to the Preview section of the schedule properties. You will see the calendar for several days shown in the tabular form. Columns of this table correspond to days. Schedule intervals are drawn with stripes of different colors. In our case there are intervals of two types: work intervals are marked with blue stripes, “off” intervals — with white ones:

  2. In case you have defined holidays for the schedule, you may use the Go to date chooser control to scroll the calendar e.g. to the beginning of the year and check that the New Year day is day off in this schedule.

The importance of the intervals order in the table

Please note that here we defined only work intervals. There is no necessity in explicit definition of the lunch time since we have chosen off as the default value, so this particular value will be used in the 2PM–3PM interval that is not explicitly defined.

If several intervals refer to the same time (overlap each other), the one that is defined later has greater priority and overrides values of the intervals defined above.

For example, we could define the same schedule in another way (see the figure below).

Since here the interval 14:00–15:00 is defined after the interval 09:00–20:00, it overrides the on value for this time interval with off value, and as the result we get the required pattern (you can check how the schedule looks like on the Preview properties page of the schedule):

However, if the intervals are defined in another order (see the figure below), they will define quite a different pattern:

In conclusion, we can recommend you to use the approach from the scenario described above (all intervals are defined explicitly in the natural sequence (09:00–14:00, 15:00–20:00)) if you are not sure how intervals in the table override each other.

You may delete any intervals from the table and move them in the table up and down (in this case you should contain the schedule integrity by yourself). This can be done by selecting the row in the table and using the corresponding buttons , and to the right of the table.

Schedule in ResourcePool block

If your schedule defines work timetable for some resources, you should tell your ResourcePool block that it should use this schedule as a work timetable for the resources it defines.

To specify the schedule in ResourcePool

  1. Select the required ResourcePool block and go to the Properties view.
  2. Choose the option By "on/off" schedule from the Capacity defined drop-down list.
  3. Type the name of the schedule in the property Schedule below (you may use code completion assistant here).
In the given example all resources are either working, or not. In more complex cases, when the number of working resources changes over time (the value type of the schedule is integer, not on/off), choose By schedule in the Capacity defined list and type the name of the schedule in the Schedule field below.

Schedule with N Days/Weeks duration

Use Days/Weeks duration type when you define a schedule as a sequence of calendar dates and times, but with non-weekly recurrence — when the schedule has recurrence of several days or weeks.

For instance, you define a daily pattern of pedestrian arrival rate. One more example — you define a shift schedule, e.g. 48 hours on, 48 hours off — such schedule has 4-day recurrence.

Let’s study how to define a schedule with N days/weeks recurrence by this example of shifts. Assume that the working time lasts from 10AM to 6PM, without lunch time.

To define a shift schedule

  1. Drag the  Schedule element from the  Agent palette onto the graphical diagram of the agent.
  2. Go to the Properties view.
  3. Specify the name of the element in the Name field. This name will be used later on for accessing the schedule from AnyLogic block(s) properties or code.
  4. Go to the Data section of the schedule properties. Choose the type of the value that will be controlled by this schedule from the Type group of buttons: on/off, integer, or real. In our case we should define the number of workers, so choose integer here.
  5. Choose the schedule mode — whether it defines intervals or discrete time moments. Choose the option Intervals (Start, End) from the group of buttons The schedule defines.
  6. Choose the most convenient Duration type for your task — in our case it is Days/Weeks.
  7. Specify the recurrence time for the cyclic pattern you have defined using the control Repeat every.... In our case the schedule has 4-day recurrence, so type 4 here and leave day(s) in the control to the right.
  8. In the Default value field you can specify the default value for the schedule - the value that will be used for the intervals not defined in the schedule. Let’s leave 0 there.

  9. Leave List of ranges selected and define intervals in the table below. To add a new interval, click the button to the right of the table. You will see new row added in the table.

  10. Specify the Start and the End for this interval using the date chooser control and then specify the value corresponding to this interval in the Value cell of this table row. Let’s assume that the shift composes of 5 men, so type 5 in the Value cell.

  11. Add one more interval to define work time for the second workday. Please note that Start and End times should be defined for Day 2 here.

You may delete any intervals from the table and move them in the table up and down (in this case you should contain the schedule integrity by yourself). This can be done by selecting the row in the table and using the corresponding buttons , and to the right of the table.

That’s all — we have finished defining this very simple schedule! Now we will pay attention to some advanced features of the Days/Weeks schedule that enable users to configure schedules for their needs.

First, you may define exceptions — particular time intervals when the value defined by this schedule should have other values, differing from the values specified in the schedule. The most frequent use cases of exceptions are national holidays and workday transfers caused by the holidays.

Schedule for the complementary shift

Actually it is evident that there should be one more shift that works in the complementary schedule: when the first shift is working, the second one is off and vice versa. This can be easily implemented by creating a copy of the existing schedule and setting that it should start working not from the first day of the simulation, but from the third one.

This can be done with the Snap to option: just go to the Snap to option of the cloned schedule and choose there the day that is two days after the day specified in the Snap to option of the original schedule.

Applying a schedule in ResourcePool

If you define a work schedule for some resources, you should tell your ResourcePool block that it should use this specific schedule as a work timetable.

Go to the properties of the required ResourcePool block and choose By schedule from the Capacity defined drop-down list. This is the way we tell the block that the number of available resources will be defined by the schedule. Type the name of your schedule in the Capacity schedule field below (you can use code completion).

Usually this option (Capacity schedule) is used when the number of available resources changes in time (there are more options than just 0 and 5 as in our example). In case the number of resources is always constant and only the status changes (i.e. all resources are either available or not), you may explicitly define the number of resources once in the Capacity parameter of ResourcePool and use on/off Type of value in your schedule. In this case you will need to choose the option By "on/off" schedule from the Capacity defined drop-down list and specify the name of the schedule in the On/off schedule parameter of ResourcePool.

“Weeks starts from” option

Please note that when you choose weeks in the Repeat every control, the option Week starts from is shown to the right. This option makes sense only in the case the schedule duration is several weeks.

The reason is that in some countries (e.g. USA) the first day of the week is Sunday, while in some other (e.g. Russia) — Monday. Therefore if you will define a schedule with N-weekly recurrence considering that the first day of the week is Sunday and then send the model to the user from some other country, where the week starts from Monday, the schedule will be misinterpreted.

So if you expect that your model will be used in other countries too, please define explicitly the first day of the week in your schedule so that this schedule will be locale-independent. And please do it before defining the schedule intervals, because all interval data in the table are deleted when you change the Weeks start from setting.

Schedule with no calendar mapping

Time units view is used when there is no mapping to calendar dates. Schedule intervals/moments are defined simply as number of time units (milliseconds, seconds, minutes, hours, days, or weeks) passed from the model start. Define schedule in this view when only interval durations are important, not the exact calendar times.

This view is convenient e.g. for defining maintenance intervention times, failures, etc. of various devices.

Let’s study how to define the device maintenance intervention times using the schedule in the Custom (no calendar mapping) view. Assume that maintenance is held regardless of calendar time, after 50 operational hours. Maintenance lasts 2 hours.

To define device maintenance times using the schedule in the Time units view

  1. Drag the Schedule  element from the Agent palette on the graphical diagram of the agent.
  2. Go to the Properties view.
  3. Specify the name of the element in the Name field. This name will be used later on for accessing the schedule from AnyLogic block(s) properties or code.
  4. Go to the Data section of the schedule properties. Choose the type of the value that will be controlled by this schedule from the Type group of buttons: on/off, integer, or real. In our case we need just to define how the device status changes from available (on) to unavailable (off) during the maintenance, so leave the default option on/off selected.
  5. Choose the schedule mode — whether it defines intervals or discrete time moments. Choose the option Intervals (Start, End) from the group of buttons The schedule defines.
  6. Choose the most convenient view for your task — in our case it is Custom (no calendar mapping), so choose this option from the Duration type group of buttons.
  7. Specify the recurrence of the schedule in the Repeat every... field. In our case the full cycle composes 50 2 = 52 hours. Therefore type 52 and choose hours there.
  8. In the Default value field you can specify the default value for the schedule — the value that will be used for the intervals not defined in the schedule. In our case it makes no sense, since we will define the whole life cycle for the device. Leave the default value unchanged.
  9. Leave List of ranges selected. Define intervals in the table below. Each interval is defined in a separate row of the table. Add new row in the table by clicking the button to the right of the table. Define Start and End times for this interval and the value that will correspond to this interval, in the Value cell. First, we want to define operational interval — so, leave 0 as Start, type 50 as interval’s End and leave on as its Value.

  10. Now define one more interval corresponding to maintenance hours. Add one more row in the table as described above. Specify 50 as Start time of this interval, 52 as the End and click in the Value cell to change its state from on to off.

    You may delete any intervals from the table and move them in the table up and down (in this case you should contain the schedule integrity by yourself). This can be done by selecting the row in the table and then using the corresponding buttons , and to the right of the table.
  11. If you want to shift the schedule in time anyhow (so that its start moment will correspond not to the start of the model, but to some other moment of model time), you can choose this particular moment in the Snap to control (here you define it again as the number of selected time units passed from the model start).

You can preview the schedule in the convenient way that is commonly used in digital diaries, organizers, and office software tools. Just open the Preview properties page of the schedule and check whether the schedule defines the desired behavior:

When finished with defining the schedule, you may use it in your model by referring to it in the properties of required block — or in your code, using the corresponding functions of the schedule.

Exceptions

Schedules having duration types with mapping to the calendar (Week and Days/Weeks) may have exceptions — particular time intervals when the value defined by this schedule should have other values, differing from the ones defined in the schedule.

Schedule may have unlimited number of exceptions.

Exceptional intervals may have any duration — e.g. a half an hour in some particular day, or the whole day of the year (or even several days in succession).

Exceptions are defined in the Exceptions section of the Properties view of the schedule. In general you will need to define both start and end dates and times for each particular interval. But since frequently exceptions are exactly one day long, AnyLogic supports special simplified definition mode for this case, named All day. In this mode you only specify particular days you want to make exceptions but do not have to define start and end times for each exceptional interval.

National holidays

The most frequent use case of “all day” exceptions are national holidays. In case your schedule defines a work timetable for some resources and you want to consider days off caused by national holidays, you can declare holidays as exceptions and set zero value or off status (depending on the schedule’s Type) for them. This will lead to considering these days as days off further to regular days off.

Below you can see an example. Please note that the Annually checkbox is selected in all table rows since all these holidays are celebrated annually and there is no need to specify them separately for each year you plan to simulate.

Workday transfers

Other frequently met case — workday transfers caused by national holidays. There are some countries (Russia, Ukraine, etc.) where workdays are transferred to days off. For instance, when a holiday falls on Tuesday, a day off is transferred from Saturday to Monday so that citizens will have three days off (Su Mo Tu) in succession. To define workday transfers, you need to declare the days off that will become workdays as the exceptions and set a non-zero value or on status (depending on the schedule’s Type) for them.

While holidays can be easily defined by picking the required days in the All day mode, you can not define workday transfers in the same simple way. The reason is that you will have not only to mention all these days, but also define the work timetable for the days that became workdays and this certainly requires specifying Start and End times for each exceptional interval.

You can see the following workday transfer defined in the given example. In 2013 the Victory Day is celebrated on Thursday, May, 9. So, the day off is transferred from Sunday, May, 12 to Friday, May, 10.

Let’s assume that this schedule defines that some resources work regularly from 10 AM till 6 PM. As you can see, we have defined those particular intervals for the day off that was made the workday due to transfers.

Please note that the checkbox Annually is cleared since the transfer pattern is specific for each particular year.

Other use cases
You can also use exceptions for modeling less trivial tasks like the demand boost in the New Year’s and Christmas Eve, or extension of the shop staff in those days.

To define exceptions for a schedule

  1. Go to the Exceptions section of the schedule properties.

  2. If you want to define day-long exceptional intervals, select the checkbox All day. If some intervals have other duration, leave this checkbox cleared.
  3. Define the required number of intervals in the table below. Each interval is defined in the separate row of the table. To add one more row, click the button to the right of the table. Then define the interval duration.
  4. If the All day option is chosen, all exceptions in the table are day-long, so you should only specify the required day in the Day cell of this table row using the date chooser.

  5. If some exceptional intervals have other duration, do not choose the All day option. In this case you will have to define start and end date and times of the exceptional interval in the Start and End cells correspondingly using the date chooser.

  6. If you want the defined exception to occur annually in the specified day, leave the checkbox in the Annually cell selected. Otherwise, if you want it to occur only in the specified year, clear it.
  7. Type the value corresponding to this particular interval, in the Value cell (the type of the value here is the same you have chosen in the Type group of buttons in the general properties of this schedule).
  8. Add more exceptional intervals in the same way by repeating steps 4-7.

Finally, you can preview the resulting schedule on the Preview properties section of the schedule. Just navigate to the days that contain exceptional intervals and make sure that these intervals are defined correctly.

Schedule preview

You can preview a schedule in the convenient way that is commonly used in digital diaries, organizers, and office software tools. This may help you to check whether the schedule was defined correctly and the resulting picture is the one you have expected to see.

To preview the schedule

  1. Go to the Preview section of the schedule properties.

  2. You will see the calendar for several days shown in the tabular form. Columns of this table correspond to days. Schedule intervals are drawn as stripes of different colors. The intensity of the stripe color depends on the value defined for the corresponding time interval (white color means 0).
    Intervals may have any duration: hours displayed in the leftmost column does not define interval borders, they just act as “time axis grid”.
  3. The preview is shown starting from some particular date. You can navigate to any other date you like using the Go to date chooser control.
Examples

Loading schedule data from database

You can import schedule data from an external database.

You can retain the schedule data you have loaded from the database.

Loading “Moments” schedule data from the DB

Suppose we have to specify a schedule for a shuttle bus arriving to airport terminal.

Your MS Excel table can look like this:

Note that timestamps contain not only time, but also date. Otherwise, after import to AnyLogic database a default date 31-12-1899 will be added to every timestamp.

To load the data for a schedule in the “Moments” mode

  1. First, you should import your data into the built-in AnyLogic database. The imported data in the database table will look like this:

  2. Open the schedule properties and adjust the parameters of Data section as shown in the figure below.

  3. Select the Loaded from database checkbox.
  4. From the Table drop-down list choose the table of the built-in database that contains bus arrival schedule. In this example it is named shuttle_schedule.
  5. From the Start column drop-down list choose the table column containing timestamps: time.
  6. From the Value column drop-down list choose the column containing values: number_of_passengers.

Note that ... column drop-down lists only contain names of columns where data of corresponding type is stored. Start column drop-down list contains names of columns with data of Date type, while Value column drop-down list contains names of columns containing data of the required type (could be integer, double, boolean).

Since in our example the schedule is of integer type, only columns of int type are listed in the Value column list.

Loading “Intervals” schedule data from the DB

Assume we have a daily schedule with two shifts and a lunch break.

Your table in MS Excel can look like this:

Note that timestamps contain not only time, but also date. Otherwise, after import to AnyLogic database a default date 31-12-1899 will be added to every time stamp.

To load the data for a schedule in the “Intervals” mode

  1. First, you should import your data into the built-in AnyLogic database. The imported data in the built-in database will look like this:

  2. Open the schedule properties and adjust the parameters of Data section as shown in the figure below.

  3. Select the Loaded from database checkbox.
  4. From the Table drop-down list choose the table of the built-in database that contains the shift schedule. In this example the table is named shift_schedule.
  5. From the Start column drop-down list choose the column that contains the timestamps marking the time interval start: start_of_shift.
  6. From the End column drop-down list choose the column that contains the timestamps marking the time interval end: end_of_shift.
  7. From the Value column drop-down list choose the column that contains values: number_of_operators.

Note that ... column drop-down lists only contain names of columns where data of corresponding type is stored. Start column and End column drop-down lists contain names of columns with data of Date type, while Value column drop-down list contains names of columns containing data of the required type (could be integer, double, boolean).

In our example the schedule is of integer type, therefore only columns of int type are listed in the Value column list.

Defining conditions to fetch particular values from the database

Assume we are simulating airport shuttle service at an airport. There are two shuttle buses operating in two different airport terminals. Each shuttle is defined with an individual ResourcePool.

We have external database with just one table containing schedules for both shuttles. We will show you how to load a specific schedule data from such a table for a particular ResourcePool.

Your table in MS Excel can look like this:

Note that timestamps contain not only time, but also date. Otherwise, after import to AnyLogic database a default date 31-12-1899 will be added to every time stamp.

In this scenario, we only want to use the shuttle schedule for terminal 1, therefore we will fetch entries relevant to the terminal 1 from the table.

To fetch particular values from the DB

  1. First, you should import your data into the built-in AnyLogic database. The imported data will be displayed like this:

  2. Load the schedule data.
  3. Open the schedule’s properties and in the Data section click the  Add choice condition button.
  4. In the Choice conditions group of controls, from the upper drop-down list choose the column that contains the value you will use to filter the data. In this example the column is named terminal.

  5. Leave the control next to this list set to equals. This control defines how two values relate to each other, and you can see all available options by clicking on it.
  6. In the combo box below select "terminal 1". We have specified the filter and now only the rows that contain values equal to "terminal 1" will be fetched from the built-in database table. You can type the value you need directly in the combo box. Since in our scenario we deal with entries of String type, we have to follow Java conventions and use quotation marks as shown in the image below.

Making the loaded schedule data autonomous

Assume the model uses data from several external databases imported to the built-in database. Some of these we need to update on model startup which can be done automatically, but we also need the shuttle bus schedule data to remain unchanged.

To make the loaded data autonomous, after loading the schedule data to the AnyLogic database, in the schedule properties clear the Loaded from database checkbox. AnyLogic will offer an option to copy these data to a table.

Click the Yes button. The retained data will be displayed as shown in the image below:

Schedule API

You can work with a schedule from code using the corresponding API of the Schedule class.

Obtaining schedule values
Getting the value: getValue()
Function Description
<ValueType> getValue() Returns the value corresponding to the current model date.
<ValueType> getValue(double time) Returns the value corresponding to the given model time (time).
<ValueType> getValue(double time, TimeUnits units) Returns the schedule value corresponding to the given model time. You define the time moment as the number of specified time units (minutes, hours, etc.). For example, getValue(9, TIME_UNIT_HOUR)returns the schedule value for model time: 9 hours.

time — the number of time units.
units — time unit constant (TIME_UNIT_MINUTE, TIME_UNIT_HOUR, etc.).
<ValueType> getValue(Date date) Returns the value corresponding to the given model date.
Getting a timeout to the next change moment: getTimeoutToNextValue()
Function Description
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(double time) Returns timeout to the schedule change moment next to the given time, measured in the model time units from that time.
double getTimeoutToNextValue(Date date) Returns timeout to the schedule change moment next to the given date, measured in the model time units from that date.
Getting a time of the next change moment: getTimeOfNextValue()
Function Description
double getTimeOfNextValue() Returns time of the schedule change moment next to the current model time.
double getTimeOfNextValue(double time) Returns time of the schedule change moment next to the given time.
double getTimeOfNextValue(Date date) Returns time of the schedule change moment next to the given date.
Getting a date of the next change moment: getDateOfNextValue()
Function Description
Date getDateOfNextValue() Returns date of the schedule change moment next to the current model time.
Date getDateOfNextValue(double time) Returns date of the schedule change moment next to the given time.
Date getDateOfNextValue(Date date) Returns date of the schedule change moment next to the given date.
Getting next value: getNextValue()
Function Description
<ValueType> getNextValue() Returns value corresponding to the schedule change moment next to the current model time.
<ValueType> getNextValue(double time) Returns value corresponding to the schedule change moment next to the given time.
<ValueType> getNextValue(double time, TimeUnits units) Returns value corresponding to the schedule change moment next to the given model time (defined as the number of specified time units). For example, getValue(9, TIME_UNIT_HOUR) returns the schedule value for the next schedule change moment after 9 hours.

time — the number of time units.
units — time unit constant (TIME_UNIT_MINUTE, TIME_UNIT_HOUR, etc.).
<valuetype> getNextValue(Date date) Returns value corresponding to the schedule change moment next to the given date.
Getting a date of value: getDateOfValue()
Function Description
Date getDateOfValue() Returns the model date the current value of the schedule has been held since.
Date getDateOfValue(Date date) Returns the model date of the schedule change moment of the value corresponding to the given model date.
Date getDateOfValue(double time) Returns the model date of the schedule change moment of the value corresponding to the given model time.
Getting a time of value: getTimeOfValue()
Function Description
double getTimeOfValue() Returns the model time the current value of the schedule has been held since.
double getTimeOfValue(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.
Getting time units of the schedule: getTimeUnits()
Function Description
long getTimeUnits() Returns time units of the schedule, one of the time unit constants (TIME_UNIT_MINUTE, TIME_UNIT_HOUR, etc.)

Creating and initializing schedule from code on model startup

Creating empty schedule with no data using the simple constructor
Function Description
new Schedule() Creates a new schedule with no data. You can specify the type of data this schedule will use like this:
new Schedule<Boolean>() — “on/off”.
new Schedule<Integer>() — integer.
new Schedule<Double>() — real.
new ScheduleWithUnits(U units) Creates a new rate schedule with the specified rate measure units.

units — rate measure unit.
Adding intervals: addInterval()
Depending on the type of schedule you are creating, in the following functions use the value argument to pass the value of the corresponding type. For example, for an “on/off” schedule pass the value of boolean type to specify the interval you are adding to the schedule. If the period you are adding is “on”, pass true. If the period you are adding is “off”, pass false.
Function Description
void addInterval(int startWeek, int startDayOfWeek, int startHour, int startMinute, int startSecond, int endWeek, int endDayOfWeek, int endHour, int endMinute, int endSecond, V value) Adds new particular time interval to this schedule.

startWeek — start week of the interval.
startDayOfWeek — start day of week of the interval.
startHour — start hour of the interval.
startMinute — start minute of the interval.
startSecond — start second of the interval.
endWeek — end week of the interval.
endDayOfWeek — end day of week of the interval.
endHour — end hour of the interval.
endMinute — end minute of the interval.
endSecond — end second of the interval.
value — value of the interval.
void addInterval(int startDay, int startHour, int startMinute, int startSecond, int endDay, int endHour, int endMinute, int endSecond, V value) Adds new particular time interval to this schedule.

startDay — start day of the interval.
startHour — start hour of the interval.
startMinute — start minute of the interval.
startSecond — start second of the interval.
endDay — end day of the interval.
endHour — end hour of the interval.
endMinute — end minute of the interval.
endSecond — end second of the interval.
value — value of the interval.
void addInterval(int startHour, int startMinute, int startSecond, int endHour, int endMinute, int endSecond, V value) Adds new particular time interval to this schedule.

startHour — start hour of the interval.
startMinute — start minute of the interval.
startSecond — start second of the interval.
endHour — end hour of the interval.
endMinute — end minute of the interval.
endSecond — end second of the interval.
value — value of the interval.
void addInterval(int startHour, int startMinute, int startSecond, int endHour, int endMinute, int endSecond, V value, int[] weekDays) Adds new particular time intervals to this schedule.

startHour — start hour of the interval.
startMinute — start minute of the interval.
startSecond — start second of the interval.
endHour — end hour of the interval.
endMinute — end minute of the interval.
endSecond — end second of the interval.
value — value of the interval.
weekDays — an array of week days to create intervals.
void addInterval(long start, long end, V value) Adds new particular time interval to this schedule.

start — start time of the interval, measured in milliseconds.
end — end time of the interval, measured in milliseconds.
value — value of the interval
Adding exact time moments: addMoment()
Depending on the type of schedule you are creating, in the following functions use the value argument to pass the value of the corresponding type.
Function Description
void addMoment(int week, int dayOfWeek, int hour, int minute, int second, V value) Adds new particular time moment to this schedule.

week — week of the moment.
dayOfWeek — day of the week of the moment.
hour — hour of the moment.
minute — minute of the moment.
second — second of the moment.
value — value of the moment.
void addMoment(int day, int hour, int minute, int second, V value) Adds new particular time moment to this schedule.

day — day of the moment.
hour — hour of the moment.
minute — minute of the moment.
second — second of the moment.
value — value of the moment.
void addMoment(int hour, int minute, int second, V value) Adds new particular time moment to this schedule.

hour — hour of the moment.
minute — minute of the moment.
second — second of the moment.
value — value of the moment.
void addMoment(int hour, int minute, int second, V value, int[] weekDays) Adds new particular time moment to this schedule.

hour — hour of the moment.
minute — minute of the moment.
second — second of the moment.
value — value of the moment.
weekDays — an array of week days to create moments.
void addMoment(long time, V value) Adds new particular time moment to this schedule.

time — time of the moment, measured in milliseconds.
value — value of the moment.
Adding exceptions: addException()
Depending on the type of schedule you are creating, in the following function use the value argument to pass the value of the corresponding type.
Function Description
void addException(int startYear, int startMonth, int startDay, int startHour, int startMinute, int startSecond, int endYear, int endMonth, int endDay, int endHour, int endMinute, int endSecond, V value, boolean annually) Adds new particular time intervals when the value defined by this schedule should have other values.

startYear — start year of the interval.
startMonth — start month of the interval.
startDay — start day of the interval.
startHour — start hour of the interval.
startMinute — start minute of the interval.
startSecond — start second of the interval.
endYear — end year of the interval.
endMonth — end month of the interval.
endDay — end day of the interval.
endHour — end hour of the interval.
endMinute — end minute of the interval.
endSecond — end second of the interval.
value — value of the interval.
annually — if you want the defined exception to occur annually in the specified day, sets true. Otherwise, if you want it to occur only in the specified year, sets false.
Setting the start time of the schedule: setSnapTo()
Function Description
void setSnapTo(int year, int month, int day, int hour, int minute, int second) Sets start time of the schedule.

year — start year of the interval.
month — start month of the interval.
day — start day of the interval.
hour — start hour of the interval.
minute — start minute of the interval.
second — start second of the interval
void setSnapTo(long snapTo) Sets start time of the schedule.

snapTo — the absolute date (if calendarType == true) or the number of milliseconds from the zero model time.
Setting a calendar type: setCalendarType()
Function Description
void setCalendarType(boolean calendarType) Sets the calendar type.

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.
Setting the default value: setDefaultValue()
Function Description
void setDefaultValue(V defaultValue) Sets the default value used when there is no interval defined in the schedule.
defaultValue — the value used when there is no interval defined in the schedule.
Setting the first day of week: setFirstDayOfWeek()
Function Description
void setFirstDayOfWeek(int firstDayOfWeek) Sets the first day of the week.

firstDayOfWeek — the first day of the week, this parameter is actually used when calendarType is true and timeUnit is week.
Setting intervals merging: setGlueIntervals()
Function Description
void setGlueIntervals(boolean glueIntervals) Sets the intervals with the same value to merge.

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.
Setting a calendar period: setPeriod()
Function Description
void setPeriod(int period) Sets the recurrence period of the schedule.

period — recurrence period of the schedule, measured in the time units specified in setTimeUnit() function. Time units may be actual — if calendarType is false, and hypothetical — if true.
Setting the thread mode: setThreadMode()
Function Description
void setSingleThreadMode(boolean singleThreadMode) Sets the thread mode.

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 agents 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.
Setting time units of the schedule: setTimeUnits()
Function Description
void setTimeUnits(long timeUnits) Sets the time units of the schedule.

timeUnits — time units of the schedule, one of the time unit constants (TIME_UNIT_MINUTE, TIME_UNIT_HOUR, etc.). In the calendar-mode the only supported time units are day and week.
Creating and initializing schedules using one complex constructor (not recommended)
Function Description
new Schedule<ValueType>(Utilities owner, boolean calendarType, int firstDayOfWeek, long period, long timeUnits, Long snapTo, <valuetype> defaultValue, long[] starts, long[] ends, Object[] values, boolean glueIntervals, boolean[] exceptionsAnnually, boolean singleThreadMode) Example:
Schedule<Integer> NursePlan = new Schedule<Integer>(this, true, MONDAY, 1L * TIME_UNIT_DAY, TIME_UNIT_DAY, null, 0, varNursePlanTime, null, varNursePlanNumber, false, null, true );

owner — owner agent 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 is true and timeUnit is TIME_UNIT_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 the time unit constants (TIME_UNIT_MINUTE, TIME_UNIT_HOUR, etc.).
snapTo — the absolute date (if calendarType == true) or the number of milliseconds from the zero model time (if calendarType == false) which points to the time moment to which the schedule should be snapped (usually it is defined in the Snap to property of the schedule). Moments are cloned started from the given time moment in both directions of the time-axis, with the schedule’s recurrence period. May be null — in this case schedule will be snapped to the date corresponding to the zero model time.
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 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 agents 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.
How can we improve this article?