You make agent move to new location by calling one of its numerous movement functions.
The continuous space has the biggest number of functions that define movement. There are also specific functions for movement in GIS space and discrete space.
Check what specific features have agents when moving inside and outside of networks.
You can set the initial speed and rotation of agent animation and define agent reaction on reaching the destination.
moveTo() and moveToInTime() functions provide several notations, enabling defining target location in different ways:
You can define location as:
Function |
Description |
void setXY(double x, double y) |
Sets the coordinates of the agent location. Should only be used to initialize the agent location. Assumes the agent is not moving. Parameters: |
Function |
Description |
double getX() |
Returns the current (up-to-date) x coordinate of the
agent in |
double getY() |
Returns the current (up-to-date) y coordinate of the
agent in |
double getZ() |
Returns the current (up-to-date) z coordinate of the agent in continuous space |
Position getPosition() |
Returns the current (up-to-date) x, y (and z in case of 3D space) coordinate of the agent in continuous space and its orientation as well. |
Function |
Description |
void moveTo(double x, double y) |
Starts movement in the direction of the given target location in continuous 3D space. Parameters: |
void moveTo(double x, double y, double z) |
Starts movement in the direction of the given target
location in Parameters: x
- the x coordinate of the target location |
void moveTo(Point location) |
Starts movement in the direction of the given target location in continuous 3D. Parameters: |
void moveTo(Node node, Point location) |
Starts movement to the given network node. Parameters: |
void moveTo(Attractor attractor) |
Starts movement to the given attractor. Parameters: |
void moveToNearestAgent (java.lang.Iterable agents) |
Starts movement to the nearest agent from the given
collection. Stops any current movement. |
boolean isMoving() |
Tests if the agent is currently moving in continuous 3D space. Returns: true if the agent is moving, false otherwise |
double timeToArrival() |
Returns the time to arrival to the target location in continuous space, in model-time units. If the agent is not moving, returns 0. |
void stop() |
Stops the agent (if it was moving) and leaves it at the current location. On Arrival is not executed |
Function |
Description |
void moveToInTime(Point location, double tripTime) |
Starts movement in the direction of the given target location. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
void moveToNearestAgent (java.lang.Iterable agents, double tripTime) |
Starts movement to the nearest agent from the given collection. Stops any current movement. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
void moveToInTime(double x, double y, double tripTime) |
Starts movement in the direction of the given target location in continuous 3D or GIS space. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
void moveToInTime(double x, double y, double z, double tripTime) |
Starts movement in the direction of the given target location in continuous 3D. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
void moveToInTime(Node node, Point location, double tripTime) |
Starts movement to the given network node. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
void moveToInTime(Attractor attractor, double tripTime) |
Starts movement to the given attractor. Changes the speed of the agent in order to reach target in tripTime model time units. Parameters: |
Function |
Description |
void jumpTo(double x, double y) |
Instantly moves the agent to a given location in continuous 3D space. Terminates any movement. Doesn't call "on arrival" code. Parameters: |
void jumpTo(double x, double y, double z) |
Instantly moves the agent to a given location. Terminates any movement. Doesn't call "on arrival" code. Parameters: |
void jumpTo(Node node, Point location) |
Instantly moves the agent to a given network location. Terminates any movement. Doesn't call "on arrival" code. Parameters: |
void jumpTo(Point location) |
Instantly moves the agent to a given location without. Terminates any movement. Doesn't call "on arrival" code. Parameters: |
Function |
Description |
double getTargetX() |
Returns the x of the target location if moving, otherwise current x in continuous 3D space space. |
double getTargetY() |
Returns the y of the target location if moving, otherwise current y in continuous 3D space space. |
double getTargetZ() |
Returns the z of the target location if moving, otherwise current z in continuous space. |
Function |
Description |
double distanceTo(Agent other) |
Calculates the distance from this agent to another one in continuous 3D space. Parameters: |
double distanceTo(double x, double y) |
Calculates the distance from this agent to a given point in continuous 3D space. Parameters: |
double distanceTo(double x, double y, double z) |
Calculates the distance from this agent to a given
point (x,y,z) in continuous space. |
double distanceTo(Point p) |
Calculates the distance from this agent to a given point (x,y,z) in continuous space. Parameters: |
Function |
Description |
double getSpeed() |
Returns the current value of the agent speed in continuous space (measured in pixels per model-time-unit). Note that nonzero speed does not mean the agent is moving - it starts moving only after moveTo is called. |
void setSpeed(double v) |
Changes
speed of the agent in continuous space (measured in pixels per
model-time-unit). If the agent is moving, it continues moving with the
new speed. Note that nonzero speed does not mean the agent is moving -
it starts moving only after moveTo()
is called. |
Function |
Description |
double getRotation() |
Returns the current rotation angle of the agent (in radians) in continuous 3D space (measured from animation point (1, 0), CW around (0, 0) point). If rotation is not frozen, the rotation changes each time the agent starts moving and also changes multiple times during movement in GIS space. |
void setRotation(double rotation) |
Sets the rotation angle (in radians) of the agent animation in continuous 3D space. Depending on automatic rotation setting, this rotation value may be overridden during the next call of moveTo() or during current movement (if any exists). Parameters: |
void setAutomaticHorizontalRotation (boolean yes) |
Tells agent to rotate automatically during movements. Parameter: |
boolean isAutomaticHorizontalRotation() |
Returns true if agent is set to be rotated during movement, false otherwise. |
void setVerticalRotation (double rotation) |
Sets the vertical rotation (angle in radians), along Z-axis of the agent animation in 3D space. Depending on automatic vertical rotation setting, this rotation value may be overridden during the next call of moveTo() or during current movement (if any exists) along path/polyline. Parameters: |
double getVerticalRotation() |
Returns the current vertical rotation angle of the agent in 3D space in radians around Y axis (CW from Z to X). If automatic vertical rotation mode is set, the rotation changes each time the agent starts moving and also changes multiple times during movement along path/polyline. |
void setAutomaticVerticalRotation (boolean yes) |
Tells agent to rotate automatically (in vertical direction, along Z-axis) during movement in 3D. Parameters: |
boolean isAutomaticVerticalRotation() |
Returns true if agent is set to be rotated in 3D (in vertical direction, along Z-axis) during movement (e.g. box travelling on conveyor slope), false otherwise. |
There are also specific functions for movement in GIS space and discrete space.
To define the reaction
on reaching the destination
Although AnyLogic directly supports movement at a constant speed and zero acceleration, you can model acceleration/deceleration by changing the speed at the appropriate time moments. You can use statechart with states like Static, Slow, Medium, Fast, etc. and timeout transitions to control the motion.