AnyLogic
Expand
Font size

Embedded agent presentation

AnyLogic presentations are associated with model components — agents — and are composed according to the model hierarchy. You develop presentations in a modular way, separately for each agent type. They can be incorporated into any higher-level presentation scene associated with a container agent. When you create an agent, its presentation automatically appears on the presentation of a container agent. It is called agent presentation, also referred below as the embedded presentation shape.

The agent presentation's name is automatically set to <agent name>_presentation, e.g. for people population, its embedded presentation shape will be named people_presentation.

Agent presentation is drawn as a rectangle showing the content of the presentation of the embedded agent.

In case an embedded agent is created and destroyed dynamically, its presentation appears and disappears synchronously with the agent.

Properties

General

Name — The name of the shape. The name is automatically set to <agent name>_presentation and cannot be changed.

Ignore — If selected, the shape is excluded from the model.

Visible on upper agent — If selected, the shape is also visible on the presentation of the upper-level agent where this agent lives.

Visible — Here you specify whether the shape is visible in the animation at the model runtime, or not. Choose yes or no using the control. If you expect visibility to change dynamically or to depend on some conditions, you may specify the expression defining the shape’s visibility here. This expression will be dynamically re-evaluated at the model runtime. It should return boolean value. The shape is visible when the specified expression evaluates to true, and not visible otherwise.

Position and size

X — X-coordinate of the animation. *

Y — Y-coordinate of the animation. *

Z — Z-coordinate of the animation. *

Rotation — Shape’s rotation angle in XY plane.

* Coordinates and rotation are applied if the Layout type setting in the Space and network section of the properties of the upper level agent type where this embedded agent lives, is set to User-defined. Otherwise, the location is defined by the predefined Layout type that is set in this property. Also, they are applied only if the Place agent(s) property of the embedded agent (population) is set to at the agent animation location. Otherwise, the agent is placed at the specified explicitly coordinates or node, and is animated at this particular location.

Scale is — Here you can define whether the scale of the embedded agent presentation is Automatically calculated or Defined explicitly. If Automatically calculated is selected, the shape will be automatically resized to correspond to the scale of the upper level agent where this embedded agent lives. For example, if the scale of the embedded agent's type is 1 meter = 10 px, and the scale of the upper level agent (e.g. Main) is 1 meter = 20 px, the embedded agent's animation will become twice larger on the Main diagram. In the Defined explicitly mode, the original size of the shape in pixels will be used, and the user can adjust it using the properties below.

Scale X — [Visible if the Scale is: Defined explicitly] Here you can specify the expression returning the X-direction scale factor for the shape. **

Scale Y — [Visible if the Scale is: Defined explicitly] Here you can specify the expression returning the Y-direction scale factor for the shape. **

Scale Z — [Visible if the Scale is: Defined explicitly] Here you can specify the expression returning the Z-direction scale factor for the shape. **

** The scale factor will be applied at the model runtime. If the field is empty, the default scale value 1 is assumed (i.e. the scale factor is not applied).
Advanced

Show in — Here you can choose whether you want this shape to be shown both in 2D and 3D animation, or in 2D only, or in 3D only.

On click — Here you can type Java code that will be called each time a user clicks on the shape at the model runtime. If there are several shapes overlapping in the click point, the click will interact with the topmost shape only.

Local variables:
self — the embedded animation itself.
clickx — X-coordinate of the click relative to the shape coordinates.
clicky — Y-coordinate of the click relative to the shape coordinates.

Draw agent with offset to this position — If agents live in discrete or continuous space, their animations will be displayed inside the rectangular area of the specified size corresponding to this space. By default, this area will be drawn at runtime with its upper left corner being put into the (0, 0) point. However, you may want to animate the agent space at some other place of the model window. To do this, select this option. Then the embedded agent's presentation will define the position of the upper left corner of the space, so you will be able to easily place the agent space animation at the required location by simply moving there this shape in the graphical diagram.

Demo model: Wandering Elephants Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

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

Please note that when you create a new agent type using the wizard, and set up its animation there, the animation shape is always placed to the axis origin at the agent type diagram (see the figure below). It is the rule you should always follow, and if you add any custom animation for an agent type, you should always place the agent animation there, otherwise at runtime the agent animation will become shifted by its offset from the axis origin.

If you cannot see the embedded agent presentation

When you create new agent type, you can select one of standard 2D pictures or 3D objects as animation shape for these agents in the New agent wizard. In this case the embedded agent presentation will automatically appear on the diagram of the upper level agent (e.g. Main) where you will place agents or populations of agents of this type.

However, you may decide to draw the animation later, and skip doing it via the agent creation wizard. In this case, when you embed agents of the agent type without the presentation, the embedded agent presentation is not created since it is void. And when you will later add any presentation shapes in this agent type, it will not appear automatically for the already existing agents and populations. To make the embedded presentation appear, you have to manually create an embedded presentation shape.

If you define presentation for the embedded agent’s type after that, you have to .

To create an embedded presentation shape manually

  1. Open the diagram of the container agent type (e.g. Main).
  2. Select the embedded agent or population (e.g. people) by clicking it.
  3. Go to the Properties and expand the Advanced section. Then click the Show presentation button. Once this is done, you will see the presentation of the embedded agent appeared on the diagram of the container agent.
  4. If the button is disabled, the embedded presentation shape already exists. You can access it from the Projects view tree. Expand the container agent’s branch and search for the embedded presentation ( icon) in a level subbranch inside its Presentation branch (e.g. people_presentation). Double clicking on the embedded agent’s presentation in the tree you will select the shape in the graphical editor.

Embedded animation's movement

You can move and rotate an embedded presentation shape in the graphical editor, or you can assign expressions to necessary properties to allow a model to move, scale, and rotate an embedded presentation shape at runtime.

Motion of a shape in an embedded presentation is a composition of its motion defined in an embedded agent and the motion of an embedded presentation shape defined in a container agent.

Position and size of an embedded presentation on a container presentation can be changed dynamically. This can be defined in two ways:

  • You can assign expressions to the properties of the presentation developed for the type of the embedded agent, or
  • You can assign expressions to properties of the embedded presentation shape on the graphical diagram of the container.

If an embedded agent itself knows its position with respect to a parent, then you use the first technique. In this case, you have to leave properties of the embedded presentation shape blank, because properties of an embedded presentation shape (if they are defined) override properties of an embedded presentation. If a container knows position of an embedded agent, then you use the second technique.

Animating hierarchical models

The presentation of a container agent can, in its turn, be embedded somewhere else, and so on to any desired level. This way, you can construct very complex presentations in a modular way, developing individual pictures independently one from another.

Animating structures not matching the model hierarchy

Although in the majority of cases the presentation structure naturally reproduces the model structure, sometimes they do not match. This means that sometimes you compose a presentation of shapes corresponding to agents lying in different levels of model hierarchy. There are two ways to do so:

  • If those agents have their own presentations defined, and you wish to display them at some presentation several agents up the model hierarchy, then you define presentations for all intermediate agents, which just contain necessary embedded presentations and no other shapes.
  • In case you just wish to define presentation for one (e.g. top-level) agent, you can draw all shapes on its graphical diagram, and then associate them with the data of embedded agents. Obviously, you should make sure those data are accessible.
How can we improve this article?