AnyLogic
Expand
Font size
All Superinterfaces:
AgentExtension, ExtAgentInteractive, ExtAnimationParams, ExtWithSpaceType, Serializable

public interface ExtAgentDiscrete
extends ExtAgentInteractive, ExtAnimationParams, ExtWithSpaceType
An extension of Agent designed to support agent based modeling in discrete 2D space, in particular:
- time (continuous or discrete)
- 2D discrete space
- connections between agents, networks (e.g. social) and their visualization
- communication - message passing and broadcasting
Author:
AnyLogic North America, LLC https://anylogic.com

Field Summary

Method Summary

Modifier and TypeMethodDescription
AgentgetAgentAtCell(int r, int c)
Returns the agent located in the cell with a given row and column, or null.
AgentgetAgentNextToMe(CellDirection dir)
Returns the agent next to this agent in a given direction, if any.
intgetC()
Returns the column of the agent's cell.
Agent[]getNeighbors()
Returns the array of neighbor agents, subject to the current neighborhood type (Euclidean - {N,S,E,W}, Moore - also {..,NW,NW,SE,SW})
intgetR()
Returns the row of the agent's cell.
booleanisNextCellInsideSpace(CellDirection dir)
Returns true if there is an adjacent cell in a given direction.
voidjumpToCell(int r, int c)
Moves the agent into a cell with the given row and column.
booleanjumpToRandomEmptyCell()
Finds a random empty cell and places the agent there.
voidmoveToNextCell(CellDirection dir)
Moves the agent to an adjacent cell in a given direction.
CellPositionrandomEmptyCell()
Finds a pseudo-randomly located empty cell and returns its row and column in the array with two elements.
voidsetCell(int r, int c)
Puts the agent into a given cell.
voidsetRC_xjal(int r, int c)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
voidswapWithAgent(Agent anotherAgent)
Swaps the cell location of this agent with another agent.
voidswapWithCell(int r, int c)
Swaps this agent with an agent at the cell with the given row and column.
voidswapWithNextCell(CellDirection dir)
Swaps the agent with an agent at the adjacent cell in a given direction.

Methods inherited from interface com.anylogic.engine.AgentExtension

getAgent, next_xjal, onDestroy, onExtensionRemoved, priority, setNext_xjal, supportsInterface_xjal

Methods inherited from interface com.anylogic.engine.ExtAnimationParams

getAnimationPosition, getAnimationX, getAnimationY, getAnimationZ, getPresentationScaleOnOwnerSpace, getSpace, isAnimationVisible_xjal, setSpace

Method Details

getR

int getR()
Returns the row of the agent's cell.
Returns:
the row of the agent's cell

getC

int getC()
Returns the column of the agent's cell.
Returns:
the column of the agent's cell

setCell

void setCell(int r,
 int c)
Puts the agent into a given cell. Should only be used to initialize the agent location. Agent is put into the given cell of discrete 2D environment (it is assumed the cell is empty, and the agent has not yet been assigned a cell).
Parameters:
r - the row of the cell
c - the column of the cell

jumpToCell

void jumpToCell(int r,
 int c)
Moves the agent into a cell with the given row and column. Raises error if that cell is nonempty.
Parameters:
r - the row of the new cell
c - the column of the new cell

moveToNextCell

void moveToNextCell(CellDirection dir)
Moves the agent to an adjacent cell in a given direction.
Parameters:
dir - the direction (NORTH, SOUTH, ..., NORTHEAST, ...)

isNextCellInsideSpace

boolean isNextCellInsideSpace(CellDirection dir)
Returns true if there is an adjacent cell in a given direction. Note that the cell may be occupied by some agent.
Returns false if going in a given direction will push agent outside the discrete space grid (e.g. moveToNextCell(CellDirection) will throw error in such case)
Parameters:
dir - the direction (NORTH, SOUTH, ..., NORTHEAST, ...)
Returns:
whether the adjacent cell in the given direction exists (true) in the discrete space grid, or not (false)

swapWithCell

void swapWithCell(int r,
 int c)
Swaps this agent with an agent at the cell with the given row and column. That cell may be empty - is this case simply moves the agent there.
Parameters:
r - the row of the new cell
c - the column of the new cell

swapWithNextCell

void swapWithNextCell(CellDirection dir)
Swaps the agent with an agent at the adjacent cell in a given direction.
Parameters:
dir - the direction (NORTH, SOUTH, ..., NORTHEAST, ...)

swapWithAgent

void swapWithAgent(Agent anotherAgent)
Swaps the cell location of this agent with another agent.
Parameters:
anotherAgent - agent to swap cell location with. Should be located on the same environment

randomEmptyCell

CellPosition randomEmptyCell()
Finds a pseudo-randomly located empty cell and returns its row and column in the array with two elements.
Returns:
the cell position (row and column) of the empty cell, or null

jumpToRandomEmptyCell

boolean jumpToRandomEmptyCell()
Finds a random empty cell and places the agent there. If there is no empty cell, does nothing.
Returns:
true if empty cell was found and agent was moved there, otherwise false

getAgentAtCell

Agent getAgentAtCell(int r,
 int c)
Returns the agent located in the cell with a given row and column, or null.
Parameters:
r - the row of the cell
c - the column of the cell
Returns:
the agent at (r,c) or null

getAgentNextToMe

Agent getAgentNextToMe(CellDirection dir)
Returns the agent next to this agent in a given direction, if any.
Parameters:
dir - the direction (NORTH, SOUTH, ..., NORTHEAST, ...)
Returns:
the agent next to this agent in a given direction, or null

getNeighbors

Agent[] getNeighbors()
Returns the array of neighbor agents, subject to the current neighborhood type (Euclidean - {N,S,E,W}, Moore - also {..,NW,NW,SE,SW})
Returns:
the array of neighbor agents, or null if there are none

setRC_xjal

@AnyLogicInternalAPI
void setRC_xjal(int r,
 int c)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. Please use Agent.setCell(int, int) instead.
Parameters:
r -
c -