AnyLogic 9
Expand
Font size

Source creates agents according to timestamps in DB

You can configure the Source block to generate agents according to the timestamps in the database.

Source can generate one agent per one database record or multiple agents per record.

To learn how to generate agents with certain parameters read from the database, see Source generates agents with parameters read from DB.

Demo model: Source With Arrivals From Database Table Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: Source With Arrivals From Database TableOpen the model in your AnyLogic desktop installation.

Generating one agent per database record

Assume we have data on arrivals and all agent attributes stored in an external database.

To make the Source block generate agents according to the database records, one agent per record

  1. Import the data from the external database into the AnyLogic built-in database.
  2. In the Source properties, select Arrivals defined by: Arrival table in Database.
  3. In the Database table field, select the name of the internal AnyLogic database containing the agent arrival data.
  4. In the Arrival parameters mapping property, select the database table column containing the agent arrival timestamps as Arrival date:

    Do not forget to enable the property by selecting the corresponding check box to the left.
  5. To create agents with custom attributes, you must first create a custom agent type in your model. If you have agent attribute values defined in a database, we recommend creating a new agent type using that database table as a template.
  6. To create a new agent type with parameters corresponding to the columns of a database table, open the Agent section of the Source block. In the New agent property, click in the edit box, then select New agent from the menu that appears. Follow the steps of the New agent wizard, specify the Agent type name, select an animation shape, and set up the agent parameters on the subsequent pages of the wizard.
  7. Now you have created a custom agent type with the attributes you need. In the table below, you can map the agent parameters to the columns of the database table you have specified earlier. Select a parameter using the check box on the left, then select a column from the drop-down list on the right.
    If there is a type mismatch, the column will not be available for selection.
  8. This Source block now will generate agents according to the records in the database. Each record defines one agent arrival. The agent attributes will be read and stored in the corresponding agent parameters.

Generating multiple agents per one record

You may need to adjust the Source block to generate multiple agents for each arrival. For example, when a shuttle bus arrives at the airport terminal, multiple new passengers appear in the model. Similarly, when a delivery truck arrives, a number of pallets appear.

Using the same example as before, but now assuming we are defining the process for the cargo rather than the truck, our Source block should generate the specified number of agents (pallets) with every truck arrival.

To make Source generate multiple agents per database record

  1. Repeat the previous scenario.
  2. In the Source properties, locate the Arrival parameters mappings table again.
  3. Enable the Agents per arrival property there. Assuming we have a column in the database table named n that stores the number of pallets delivered by the truck, set the Source block to use the data from that column:

  4. Click the icon to the right of the Agents per arrival field, and select Table column from the list. Finally, select the name of the required column (n) from the Agents per arrival list.

How can we improve this article?