Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

imit_model / AnyLogic / UsersManual(AnyLogic)

.pdf
Скачиваний:
141
Добавлен:
06.06.2015
Размер:
4.28 Mб
Скачать

AnyLogic V User’s Manual

3.Otherwise, to define adaptive update rate, choose the Adaptive option and specify the update rate with a slider. Choose between smooth animation (Smooth) and fast simulation (Fast).

4.Click the Apply button to apply changes.

The animation will appear with the specified update rate.

5.If needed, repeat steps 2-4 to specify another update rate and click OK when finished.

Figure 173. Settings dialog box

18.3.3.2 Animation anti-aliasing

AnyLogic animation supports anti-aliasing – one of the most important techniques in making graphics more smooth and pleasing to the eye. With anti-aliasing set, graphics look smoother due to the performed approximation of the colors of rendered pixels. However, note that more time is spent on rendering the animation with the anti-aliasing set.

© 1992-2004 XJ Technologies http://www.xjtek.com

397

Chapter 18. Standalone model running

To enable/disable anti-aliasing

1.Click the Animation Settings toolbar button.

The Animation Settings dialog box is displayed, see Figure 173.

2.Select/clear the Enable anti-aliasing checkbox.

3.Click OK.

398

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

19. Libraries and external files

19.1 External files

AnyLogic allows the user to add external Java files to a project. This capability is used to add code of any kind to a model. AnyLogic does not modify external files during the code generation. Just before the model is built, all external files are copied into build directories with respect to their packages names. When AnyLogic builds the model, external files are compiled together with the code generated by AnyLogic.

To add an external file to a package

1.Choose Insert|Add External File… from the main menu. The Add External File dialog box is displayed.

Choose the package, which will contain the external file, and click OK.

2.Alternatively, in the Project window, right-click the package and choose Add External File… from the popup menu.

3.The Open dialog box is displayed.

4.Browse for the existing Java file, or type the name of the new file you want to add to the package.

5.Click the Open button.

External files reside in AnyLogic packages, as well as active object classes. If the external file is added to a package, it must be logically placed inside Java package having the same name. For example, if the external file is added to the AnyLogic package mypackage, it must contain the line “package mypackage;”. If a new file is created when you add an external file to a package, this line is added automatically.

Properties

Name – [read only] the name of the external file.

© 1992-2004 XJ Technologies http://www.xjtek.com

399

Chapter 19. Libraries and external files

Path name – [read-only] the full path the external file is loaded from.

Persist as – [read-only] shows how the file is saved in the project. This field can contain a relative or an absolute path. If you move the project to another folder, the information of this field will be used to obtain the full path and load the file.

Exclude from build – if set, the file is excluded from the model, i.e., it is not compiled.

19.2 Libraries

Libraries are collections of active object classes, animations, timer classes, message classes, and Java modules developed for some particular application area or modeling task. Libraries have several benefits:

Provide for better reuse of classes across multiple models. A class can be developed and stored once and referenced from several projects.

Libraries enable you to organize teamwork in AnyLogic projects: a part of the model developed by a team member may be put into a library, and others use consistent versions of the library in their work.

By developing the right library, you can convert AnyLogic into a high-level modeling tool with point-and-click interface for a specific domain.

19.2.1Creating a library

A library is actually a project, which is compiled and packed into a Java archive. Any project can be made a library if you specify its property Target file and build it.

To create a library

1.Open a project which you would like to make a library, or create a new project.

2.Click the project in the Project window.

3.Type the name of the Java archive (e.g. MyLibrary.jar) in the Target file property of the project.

400

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

You do not need to specify the root object class for a library. However, if you specify it, you can run the library having that object as a root. This might be useful for testing while developing a library.

If you modify a library being used in a project, do not forget to rebuild the library (you need a separate instance of AnyLogic to open it). Note that when a project using a library is being compiled, the library itself is not compiled.

We recommend you to take special note of the future reuse of the class you wish to place in a library. Add comprehensive descriptions to the library classes. Keep them simple, flexible, and independent one from another as much as possible.

AnyLogic standard distribution includes several libraries, covering specific domains. They are: Enterprise Library, Dynamic Systems Library, Material Flow Library. AnyLogic libraries are located in the Lib directory. Have a look at these libraries to get an idea of how to develop your own ones.

19.2.2Working with libraries

AnyLogic shows libraries in the Libraries window (a page in the Workspace window, see Figure 174). Each AnyLogic library is represented with an individual stencil containing library object classes. Each class is represented with the icon designed for it. The Libraries window does not allow you to modify anything within libraries.

© 1992-2004 XJ Technologies http://www.xjtek.com

401

Chapter 19. Libraries and external files

Figure 174. Libraries window

To show the Libraries window

1.Click the Libraries toolbar button, or Choose View|Libraries from the main menu, or Press Alt+1.

If you have created a library and wish to use it in other projects, you must tell AnyLogic where the library is located. Only libraries located in folders, specified in AnyLogic options, are displayed in the Libraries window. To use your own or third-party library, you should list

402

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

the folder containing the library in AnyLogic options or copy the library into the folder C:\Program Files\AnyLogic 5.0\Lib, where the standard libraries are located.

To add a library folder to AnyLogic options

1.Choose Tools|Options… from the main menu. The Options dialog box is displayed.

2.On the Miscellaneous page, type the name of the folder in the Library folders edit box. Use a semicolon to separate your folder from other folders.

3.Click OK.

If you create a model in a specific domain, which is covered by a library, you usually reuse active object classes defined in a library just by dragging them on a structure diagram and connecting them.

To create an instance of an active object class defined in a library

1.Drag an active object class from the Libraries window onto a structure diagram. The instance of the active object class is created.

Moreover, you can pass a message defined in a library between your custom model objects. Or you can use a message defined in a library as a base class or as a parameter of your custom message (all message classes defined in AnyLogic libraries are listed in the Base class and the Type message class’ properties correspondingly).

© 1992-2004 XJ Technologies http://www.xjtek.com

403

Chapter 20. Database Support

20. Database Support

Sometimes you need your model to access databases. For example, you may want to construct and connect active objects based on information stored in a database. AnyLogic allows you to link a database to your model.

You need this when:

You have values of active object parameters in a database already;

There are too much data to encode them in a model;

A database is shared between your model and other applications.

To access a database, you have to code it manually using Java database connectivity technology – JDBC. JDBC documentation is included into Java SDK documentation available at:

http://java.sun.com/docs

There is also a basic JDBC tutorial at:

http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html

In addition, AnyLogic Engine provides com.xj.anylogic.DataSource class that wraps JDBC and simplifies access to databases. See AnyLogic Class Reference for description of this class.

20.1 Introduction

What is a database? A database is a structured storage of information. What does this mean? Consider that most ubiquitous of databases – the phone book. The phone book contains several items of information – name, address, and phone number – about each phone subscriber in a particular area. Each subscriber's information takes the same form.

In the database terms, the phone book is a table that contains a record for each subscriber. Each subscriber record contains three fields: name, address, and phone number. Other

404

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

examples of databases are: customer lists, library catalogs, parts inventories. The list of possible databases is infinite. Using a database management system such as Microsoft Access you can design your own database.

Information in a database table is held in records. A record contains information about a single entity – for example, a person, a product. Records are represented as rows in tables. For every record, the data is held in fields. The fields contain individual pieces of data about the record – for instance, name, telephone number. A table usually has one or more fields uniquely identifying a record in the table. Such a field is called the key field. The key field provides the means to distinguish one record from all the others in a table. It allows one to identify, locate, and refer to one particular record in the table.

A database can contain a single table of information, such as the phone book, or several tables.

A database can contain queries. A query is a filter used to obtain specific information from a database. The result of a query is a view – virtual table that contains records matching the query. Once a view is defined, it can be used as an ordinary table.

If you need views (virtual tables) other than those available in a database itself, you create them directly in AnyLogic as described in section 20.4, “Custom queries”.

20.2 Creating a data source

A data source is an element of an AnyLogic project that represents an actual database and is responsible for communication with the database. By creating a data source, you declare that your model will be able to access a corresponding database. That is, you cannot access a database unless you have created a data source representing that database.

To create a data source

1.Choose Insert|New Data Source… from the main menu. The New Data Source dialog box is displayed.

Specify the name of the new data source, choose the package, which will contain the data source, and click OK.

© 1992-2004 XJ Technologies http://www.xjtek.com

405

Chapter 20. Database Support

2.Alternatively, in the Project window, right-click the package, which will contain the data source, and choose New Data Source… from the popup menu.

The New Data Source dialog box is displayed.

Specify the name of the new data source and click OK.

The name is used to identify and access the data source. An AnyLogic data source name is not related to either a database filename or ODBC data source name.

After a data source is created, it is necessary to associate it with a database. You can associate it either with a database file (see subsection 20.2.1, “Associating with a database file”) or with an ODBC data source (see subsection 20.2.2, “Associating with an ODBC data source”).

20.2.1Associating with a database file

You use association with a database file to access, e.g., an MS Access database or MS Excel spreadsheet. This approach is simple and does not require you to have anything else than one of the mentioned tools. Its drawback is that it requires storing an absolute file path in an AnyLogic project. Therefore, if you change the location of a database, you have to change a corresponding path manually in AnyLogic project.

To associate a data source with a database file

1.In the Project window, click the data source.

2.In the Properties window, select the File option.

3.Click the Browse button.

The Open dialog box is displayed.

4.Browse for the MS Access or MS Excel file you want to use. Double-click the file or click the Open button to select the file.

5.Enter Login and Password if they are required by the database.

406

© 1992-2004 XJ Technologies http://www.xjtek.com

Соседние файлы в папке AnyLogic