The continuous space support includes ability to set and retrieve the current agent location, to move the agent with the specified speed from one location to another, to execute action upon arrival, to animate the (static or moving) agent at its location, to establish connections based on agents layout, and other useful services. Part of continuous space functionality does not even require the agents to belong to an explicitly specified environment — without the environment the default space type assumed is continuous space.
To set the environment space type to continuous
- In the Projects view, click the environment agent type where your agents live (e.g. Main). This shows the agent types properties in the Properties view.
- Open the Space and network section of the properties.
- In the list of agents, select agent populations that you want to place in this environment.
- Choose Continuous option from the group of options Space type.
The space dimensions specified in the same section (Width and Height) are only used to lay out agents when any of the standard layout types are applied and do not restrict the agents mobility.
You can use the following methods to get the space dimensions:
- double spaceHeight() — Returns the height of environment in continuous space.
- double spaceWidth() — Returns the width of environment in continuous space.
- double spaceZHeight() — Returns the height of environment space along Z-axis.
Location of an agent in continuous space is defined by real coordinates. There are several ways to define initial locations for agents living in continuous space:
- Place agent in the specified network node
- Define X-, Y-, Z- coordinates of the agent location.
- Call the function setXYZ() on the model startup
- Use one of predefined layout patterns (Random, Arranged, Ring, Spring mass).
To place agent in a network node
- Click the agent population to open its properties.
- In the Initial position properties section, choose the option Place agent(s): in the node.
- In the Node field below, specify the name of the network node, where you want to place the agent. If you define location just for one agent, or if you want to place all the agents from the population in the same network node, you can just choose the node name from the drop-down list, or select it by clicking in the graphical editor.
- Otherwise, if you want to set different nodes for agents here, you can write a Java expression that will return different nodes depending on some conditions.
To place agent in the point with the specified X, Y, Z coordinates
- Click the agent population to open its properties.
- In the Initial position properties section, choose the option Place agent(s): in the specified point.
- Specify the location coordinates in the X, Y, Z fields below.
The initial location can either be defined “centrally” by environment or specified at the agent type.
You can set initial location for agents, by calling the function setXYZ() in the top-level agent’s On startup code (in the Agent actions section of the agent type properties).
void setXYZ(double x, double y, double z) — Sets the coordinates of the agent location. It is only used to initialize the agent location. Assumes the agent is not moving.
x — X-coordinate of the location.
y — Y-coordinate of the location.
z — Z-coordinate of the location.
To define the initial layout for agent population
- Open the properties of the agent where this population lives (e.g. Main).
- Open the Space and network properties section.
- Check the agent population in the Select the agents ... list.
- Choose the initial layout from the Layout type drop-down list, and unless you have chosen the User-defined layout, check the Apply on startup checkbox.
The User-defined layout type assumes you will take care of the agent locations yourself in e.g. Startup code of the top-level agent (Main). The standard continuous layouts supported by AnyLogic are:
Random an agent location is chosen randomly and uniformly within the space dimensions |
Ring the agents are uniformly distributed on a ring whose diameter is smaller than the smallest space dimension |
Arranged the agents are arranged within the space dimensions |
Spring mass the agents are located as a spring mass system where agents are masses and their connections are springs. This is network-dependent layout type |
You can change the layout type dynamically while the model is running using the environment API, for example:
setLayoutType( type ); // this will just set the default type of layout, the agents will not get relocated
applyLayout(); // this will relocate the agents according to the layout type currently set.
The type parameter can take one of the constants: Agent.LAYOUT_RANDOM, Agent.LAYOUT_ARRANGED, Agent.LAYOUT_RING, Agent.LAYOUT_SPRING_MASS, Agent.USER_DEFINED.
Demo model: Agent Network and Layouts Demo Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).While the agent is moving, its presentation will also be animated as moving and will always be at its current position (x,y) relative to its origin. This means that if in design time the agent’s presentation was placed at (50,100) on the container (e.g. Main diagram) and the current location of the agent is (17,64), the agent will be shown at (67,164). The rotation of the agent’s presentation is always set to its heading.
-
How can we improve this article?
-