Defining initial locations for agents in continuous space

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: 

Using one of predefined layout patterns

  To define the initial layout for agent population

  1. Open the properties of the agent where this population lives (e.g. Main).
  2. Open the Space and network properties section.
  3. Check the agent population in the Select the agents ... list.
  4. 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:

an agent location is chosen randomly and uniformly within the space dimensions

the agents are uniformly distributed on a ring whose diameter is smaller than the smallest space dimension

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:

Placing an agent in the specified network node

  To place agent in a network node
  1. Click the agent population to open its properties.
  2. In the Initial location properties section, choose the option Place agent(s): in the node.
  3. 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 form the drop-down list, or select it by clicking in the graphical editor.
  4. 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.

Specifying X, Y, Z coordinates

  To place agent in the point with the specified X, Y, Z coordinates
  1. Click the agent population to open its properties.
  2. In the Initial location properties section, choose the option Place agent(s): in the specified point.
  3. Specify the location coordinates in the X, Y, Z fields below.

Setting the initial location programmatically at model startup

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

Demonstration model: Agent Network and Layouts Demo