AnyLogic
Expand
Font size

AnyLogic database

Each AnyLogic model now has a built-in fully integrated database to read input data and write simulation output. Export the database with the model, it is as portable and cross-platform as the model itself.

With the new database, you can:

  • Read parameter values and configure models
  • Create parameterized agent populations
  • Generate agent arrivals in the process models
  • Import data from other databases or Excel spreadsheets and store it in the readily available form
  • Log flowchart activities, events, statechart transitions, message passing, and agent biographies
  • View resource utilization, waiting, processing, and travel times
  • Store and export statistics, datasets, and custom logs
  • Export data to MS Excel spreadsheets
  • Backup and restore data.

The database can contain tables and views. Both tables and views can be grouped into groups of tables.

You can easily import the database into your AnyLogic project from an external database or spreadsheet. Alternatively, you can create empty database tables and enter data manually.

Properties

General

Size — The label displays the size of the database on disk.

Create or import a table… — Click this link to create a new database table, or import data into the DB from the external database.

Back up database…* — Click this link to create a backup copy of the database. AnyLogic saves the backup copy in TAR.GZ file format. Having backed up the database, you will be able to revert all changes in the database you are working with, by restoring the database from the backup (see the description of the Restore database property below).

Restore database…* — Click this link to restore the database from the backup file. Restoring the database you replace your current database with the reserve copy you have previously created using the Backup database command (see above). The restored database gets reverted to the state it was when you backed it up.

Delete database* — Click this link to completely delete the database. This will automatically disable the Compact on model close option.

Compact on model close* — If selected, the data within the database will be compressed upon the model shutdown, reducing the disk space it requires. However, if the database is huge, compact shutdowns will take a significant time. If the option is not selected, data is saved as-is.
This option automatically becomes enabled and unresponsive to further actions, if you switch on the logging in the Log model execution parameter. It also is enabled automatically, when you export the model data to AnyLogic Cloud or a standalone Java application. The same goes for any old model if it has logging enabled or any logs saved to the database.
For information on the compact shutdown, see the HyperSQL User Guide.

* The option is available only if the database is not empty.
Import

This properties section is visible if this database contains tables that were imported from an external database. You can set up data synchronization and update data in the imported tables after making some modifications in the external database.

Autoupdate imported tables on model startup — If selected, data in all imported tables will be automatically updated from the external database on each startup of this model.

Update tables data — Click this link to update data in all imported tables from the external database.

Input data sources — Contains a list of paths to all external sources of data for the imported AnyLogic database tables. If the source file is located outside of the model folder, an absolute path is displayed. If the file is located in the model folder, only the name of the file is displayed.

Export

This section contains properties related to database export to Excel files. To learn how to export the AnyLogic database, please see Exporting data to MS Excel workbook.

Export settings — Here you can specify the Excel file where you want to export your DB data and select the DB tables (and logs if logging is enabled) for export.

Export tables to Excel — Click this link to export data to the specified Excel file.

Export tables at the end of model execution — Select this option if you want data to be automatically exported when model execution is finished.

Export to — This field displays the path to the Excel file you have specified for data export.

Log

Log model execution — If selected, the model execution will be logged. Enabling this option automatically enables the Compact on model close option. Please note that model execution logging is supported only for simulation experiments.

Delete log — Click this link to delete the current model execution log.

Functions

To access functions of the built-in model database, address the ModelDatabase Java object by calling the following function:

getEngine().getModelDatabase()

The primary purpose of the object is to establish connections between the internal database and external data sources (such as Excel files).

Working with external databases
Function Description
void importFromExternalDB(Connection sourceConnection, String sourceTableName, String targetTableName, boolean clearTargetTable, boolean autoCommit) Import data from a single table of an external database.
For this function to work, the column types of both the internal table and built-in model table should match or be convertible.

sourceConnection — an existing Connection to a database, retrievable via the Database.getConnection() method call.
sourceTableName — a string with the name of the database table you want to import from the external data source.
targetTableName — a string with the name of a database table within the model’s internal database which will be populated upon execution of the function.
clearTargetTable — if true, attempts to wipe all the data from the target table (the one within the model’s database) before executing the function.
autoCommit — if false, the function call will not attempt to commit a database transaction, so it won’t affect the performance.
void exportToExternalDB(String sourceTableName, Connection targetConnection, String targetTableName, boolean clearTargetTable, boolean autoCommit) Exports a single table of data from the model’s built-in database to an external database.
For this function to work, the column types of both the internal table and built-in model table should match or be convertible.
If the target table in the external database is an Excel sheet, the following conditions must be met:
  • The sheet with the name specified as targetTableName must exist in the XLS/XLSX file
  • The sheet must include the header row, where each column must be named identically to those in the source table
sourceTableName — a string with the name of the database table you want to import from the model’s built-in database.
targetConnection — an existing Connection to a database, retrievable via the Database.getConnection() method call.
targetTableName — a string with the name of a database table within the external database.
clearTargetTable — if true, attempts to wipe all the data from the target table before executing the function. As of now, clearTargetTable does not work with Excel tables, so the value of this argument must be set to false when importing to an XSL/XSLX file.
autoCommit — if false, the function call will not attempt to commit a database transaction, so it won’t affect the performance.
A more context-specific description of these functions is available in the following articles: Importing database tables, Exporting data to MS Excel workbook.
Working with the model log
Function Description
void deleteExistingLogObjects​(connection) Deletes all the log data of the model, provided logging has been enabled.

connection — an existing Connection to a database, retrievable via the Database.getConnection() method call.
How can we improve this article?