Movement in GIS space

There are several functions you can employ programmatically to make an agent move in GIS space, including the moveTo()and jumpTo()functions.

Movement with moveTo() functions:  moving an agent toward a destination

Each function in the family of moveTo() functions moves an agent toward a destination. With these functions, an agent will move along the routes of a GIS map's existing transportation network unless you override the existing routes and locations with GIS space markup elements. If there is no direct route from the agent to the destination, the agent first moves to the nearest point on the transportation network, and then follows the network to the destination. If network routes do not reach the destination, the agent moves to the point on the network that is closest to the destination, and then follows a line to the destination.

Moving toward a location downloaded from an online route service

Perhaps the simplest way to make an agent move toward a specific location is to use the function moveTo(String geographicPlace). For example, if you want a truck agent to move toward London, you could use the function truck.moveTo(“London”). Then at runtime, when the function is executed, the truck would move toward London by following an existing road that is downloaded from an online route service. Using this approach, you would not need to employ GIS space markup elements.

Moving toward a GIS Point along a GIS Route

If you have used GIS space markup elements to specify locations and routes for your model, you can move an agent using the function moveTo(node). For example, to move a truck agent toward a GIS Point named gisPointLondon, you could use the function truck.moveTo(gisPointLondon). Then at runtime, when the function is executed, the truck would move toward the GIS Point along the nearest GIS Route you have provided. Using this approach, you would not have to obtain route or location data from an online route service. However, if you have not used GIS Route elements to provide a custom transportation network, AnyLogic will download route data from an online route service.

Moving toward a location with given coordinates

You can make an agent move toward a location with given coordinates:

moveTo(double latitude, double longitude)- Starts movement toward the given location
Parameters:
latitude - the location's latitude, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90) 
longitude - the location's longitude, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)

Moving toward a specified agent

To move one agent toward another, you could use the function moveTo(agent), where agent is the name of the destination agent. 

If you need to make an agent move toward the closest agent of another population, you could use the function moveToNearestAgent(population). For example, if you want a truck agent to move to the nearest gas station among the agent population gasStations, use the function truck.moveToNearestAgent(gasStations).

Moving to a destination in a specified length of time

All the moveTo() functions have moveToInTime() counterparts that enable you to specify the length of time it will take for an agent to reach its destination. When you use the function moveToInTime(), an agent moves with a constant speed so that it reaches the destination over the length of time specified as one of the function’s arguments. For example, if you want the truck agent to reach the agent londonAgent in 25 model time units, you could use the function truck.moveToInTime(londonAgent, 25). You can also specify the trip duration in time units other than the model’s time unit. For example, if the model time unit is days but you want the truck to reach London in 25 minutes, you could use the function truck.moveToInTime(London, 25, MINUTE), with an additional argument that gives the alternate time unit. This additional argument can take one of the following constants:   MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.

Controlling and probing an agent’s movement

While an agent is moving toward a destination, you can control and probe its movement using the following functions:
stop() - Stops the agent at its current location. If the agent has arrived at its destination, the function is not executed.

boolean isMoving() - Tests if the agent is currently moving. Returns true if the agent is moving and false otherwise.

double timeToArrival()- Returns the length of time remaining (in model time units) until the agent arrives at its destination. If the agent is not moving, returns 0.

double getTargetLat()- If the agent is moving, returns the latitude of the target location. Otherwise returns the latitude of the agent’s current location, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90).

double getTargetLon()- If the agent is moving, returns the longitude of the target location. Otherwise returns the longitude of the agent’s current location, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180).

double getGISHeading()- For an agent moving in continuous 2D GIS space, returns the agent’s current heading angle, measured in radians clockwise from the North.

There are also functions to probe current locations and to calculate distance:

double getX() - Returns the longitude of the agent’s current location, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180).

double getY() - Returns the latitude of the agent’s current location, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90).

double getTargetX() - Returns the longitude of the agent’s destination, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180).

double getTargetY() - Returns the latitude of the agent’s destination, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90).

double distanceTo(Agent other) - Returns the distance (in meters) from this agent to another one specified as an argument.

Instant movement with jumpTo() functions:  placing an agent at a new location

You can instantly move an agent to a new location (i.e. relocate the agent) using the function jumpTo(). If this function is executed while the agent is already moving, it stops the movement and relocates the agent to the given location. The function jumpTo() is different from the function setLocation(). The function setLocation() places an agent at a specified location on a GIS map before starting the simulation. It is typically invoked from the On startup code of the model's top-level agent. By contrast, the jumpTo() function relocates an agent when it is executed at model runtime.

As with the moveTo() functions, AnyLogic supports alternative jumpTo() functions:

jumpTo(String geographicPlace)- Immediately places the agent at the specified location. When you execute this function, AnyLogic searches for the specified location on the GIS map, takes the first element from the search results list, and instantly relocates the agent there.
Example: truck.jumpTo("London")

jumpTo(node)
- Immediately places the agent at a given GIS Point or GIS Region.
Example:
truck.jumpTo(gisPointLondon)

jumpTo(double latitude, double longitude) - Immediately places the agent at the given location coordinates.
Parameters:
latitude - the location's latitude, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90) 
longitude - the location's longitude, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)
Example: truck.jumpTo(51.3 , 0.7)


Related topics

 GIS tutorial

Defining routes for GIS map

Finding locations on a GIS map