AnyLogic
Expand
Font size

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:

How can we improve this article?