com.xj.anylogic.engine
Class Agent

java.lang.Object
  extended by com.xj.anylogic.engine.Presentable
      extended by com.xj.anylogic.engine.Utilities
          extended by com.xj.anylogic.engine.ActiveObject
              extended by com.xj.anylogic.engine.Agent
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, java.io.Serializable
Direct Known Subclasses:
AgentContinuous, AgentDiscrete2D

public abstract class Agent
extends ActiveObject

A subclass of ActiveObject designed to support agent based modeling, in particular:
- time (continuous or discrete)
- space (continuous or discrete) and spatial animation
- connections between agents, networks (e.g. social) and their visualization
- communication - message passing and broadcasting
There are several agent classes for different space types:

A user-defined agent class should be a subclass of one of these Agent* classes in order to use those features.
If your model is agent based, but none of the above features are required, it is recommended to use regular ActiveObject as a base class for your agents, and not this class: Agent classes require 36+ bytes more memory than ActiveObject.

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Field Summary
static int ALL
           
static int ALL_CONNECTED
           
static int ALL_NEIGHBORS
          This destination type is available only in discrete agents
static int EAST
           
static int NORTH
           
static int NORTHEAST
           
static int NORTHWEST
           
static int RANDOM
           
static int RANDOM_CONNECTED
           
static int RANDOM_NEIGHBOR
          This destination type is available only in discrete agents
static int SOUTH
           
static int SOUTHEAST
           
static int SOUTHWEST
           
static int WEST
           
 
Fields inherited from class com.xj.anylogic.engine.ActiveObject
DRAW_PARAMETER_DYNAMIC, DRAW_SD_ARRAY, DRAW_SD_CONSTANT, DRAW_SD_EXTERNAL, DRAW_SD_LINK_DELAY, DRAW_SD_LINK_INITIAL, DRAW_SD_NEGATIVE, DRAW_SD_NO_SOURCE, DRAW_SD_NO_TARGET, DRAW_SD_PUBLIC_ONLY, DRAW_SD_SHADOW, DRAW_SD_ZERO, EVENT_TIMEOUT_MODE_CYCLIC, EVENT_TIMEOUT_MODE_ONCE, EVENT_TIMEOUT_MODE_USER
 
Fields inherited from class com.xj.anylogic.engine.Utilities
AM, APRIL, AUGUST, DAY, DECEMBER, FEBRUARY, FRIDAY, HOUR, infinity, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK, YEAR
 
Fields inherited from class com.xj.anylogic.engine.Presentable
ALIGNMENT_CENTER, ALIGNMENT_LEFT, ALIGNMENT_RIGHT, CAD_ANTIALIASING, CAD_INVERTED, LINE_STYLE_DASHED, LINE_STYLE_DOTTED, LINE_STYLE_SOLID, NAVIGATION_FULL, NAVIGATION_LIMITED_TO_Z_ABOVE_ZERO, NAVIGATION_NONE, NAVIGATION_ROTATION_ONLY, SHAPE_ARC, SHAPE_BUTTON, SHAPE_CAD, SHAPE_CHART_BAR, SHAPE_CHART_HISTOGRAM, SHAPE_CHART_HISTOGRAM2D, SHAPE_CHART_PIE, SHAPE_CHART_PLOT, SHAPE_CHART_STACK, SHAPE_CHART_TIME_COLOR, SHAPE_CHART_TIME_PLOT, SHAPE_CHART_TIME_STACK, SHAPE_CHECKBOX, SHAPE_COMBOBOX, SHAPE_CURVE, SHAPE_EMBEDDED_OBJECT, SHAPE_FILECHOOSER, SHAPE_GROUP, SHAPE_IMAGE, SHAPE_LINE, SHAPE_LISTBOX, SHAPE_OVAL, SHAPE_PIXEL, SHAPE_POLYLINE, SHAPE_PROGRESSBAR, SHAPE_RADIOBUTTONS, SHAPE_RECTANGLE, SHAPE_ROUNDED_RECTANGLE, SHAPE_SLIDER, SHAPE_TEXT, SHAPE_TEXTFIELD
 
Constructor Summary
Agent(Engine engine, ActiveObject owner, ActiveObjectCollection<?> collection)
           
 
Method Summary
 java.lang.String agentInfo()
           
 void deliver(java.lang.Object msg, int mode)
          Delivers a message to an agent or a group of agents, as specified by the mode parameter immediately during this method call.
 boolean disconnectFrom(Agent a)
          Disconnects this agent from another given agent.
 void disconnectFromAll()
          Disconnects the agent from all other agents.
 Agent getConnectedAgent(int index)
          Returns the connected agent with a given index.
 java.util.LinkedList<? extends Agent> getConnections()
          Returns a collection of agents connected to this agent (bi-directionally), or null if there have not been any connections yet.
 int getConnectionsNumber()
          Returns the number of agents connected to this agent.
 Environment<?> getEnvironment()
          Returns the environment where this agent belongs to.
 double getShapeX(int id, int index)
          Should be overridden to return the X coordinate of a non-persistent shape.
 double getShapeY(int id, int index)
          Should be overridden to return the Y coordinate of a non-persistent shape.
 boolean isConnectedTo(Agent a)
          Tests if this agent is connectied to a given other agent.
 void onBeforeStep()
          A callback that is called at the beginning of every step in discrete time before onStep() of any agent is called.
 void onDestroy()
          This method must be called when the agent is destroyed.
 void onStep()
          A callback that is called at every step in discrete time after onStep() of any agent is called.
 void receive(java.lang.Object msg)
          Immediately delivers a message to this agent.
 void restoreConnections_xjal(java.util.LinkedList<?> connections)
          This method should not be called by user
This method restores connections of this agent
 void send(java.lang.Object msg, int mode)
          Sends a message to an agent or a group of agents, as specified by the mode parameter.
 void setEnvironment(Environment<?> env)
          Sets up time, space, etc. type for the agent.
 
Methods inherited from class com.xj.anylogic.engine.ActiveObject
assignInitialConditions_xjal, create, drawActionChart, drawActionChartLink, drawAuxiliaryVariable, drawAuxiliaryVariable, drawBranchExit, drawBranchState, drawBreakBlock, drawCausalLoop, drawCodeBlock, drawConnector, drawDecisionBlock, drawDynamicEvent, drawEmbeddedObjectModel, drawEmbeddedObjectModel, drawEmbeddedObjectModelDefault, drawEmbeddedObjectModelDefault, drawEnvironment, drawEvent, drawFinalState, drawFlow, drawFlow, drawFlowStockDependencyLine, drawHistoryState, drawInitialStatePointer, drawLink, drawLink, drawLocalVariable, drawLoopArea, drawLoopBlock, drawParameter, drawParameter, drawPlainDependencyArc, drawPlainDependencyLine, drawPort, drawReturnBlock, drawSchedule, drawState, drawStatechartEntryPoint, drawStock, drawStock, drawTransition, enterState, error, evaluateRateOf, evaluateRateOf, evaluateTimeoutOf, evaluateTimeoutOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeActionOf, executeOnReceiveActionOf, executeOnSendActionOf, exitInnerStates, exitState, finishSimulation, formulasExecute_xjal, getCameras3D, getContainerStateOf, getDynamicEvents, getEmbeddedObjects, getEngine, getFirstOccurrenceTime, getFullName, getIndex, getIntegrationManager_xjal, getModeOf, getName, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOf, getNameOfState, getOwner, getOwnerShape, getPresentation, getReplicatedCollection, getReplicatedList, getScalarPhaseVector_xjal, getScalarPhaseVectorForInitialConditions_xjal, getScalarRightPart_xjal, getScalarRightPartForInitialConditions_xjal, getStatechartOf, getStatechartOf, getStatechartOf, getStatechartOf, isReplicated, nothingChanged, onChange, onCreate, onStartup, pauseSimulation, putScalarPhaseVector_xjal, putScalarPhaseVectorForInitialConditions_xjal, restoreOwner, runSimulation, setDestroyed, setEngine, setOwnerShape_xjal, setParametersToDefaultValues, setupPlainDependencyArc, start, stateContainsState, stopSimulation, testConditionOf, testConditionOf, testGuardOf, testGuardOf, testGuardOf, testGuardOf, testMessageOf, toString
 
Methods inherited from class com.xj.anylogic.engine.Utilities
bernoulli, bernoulli, beta, beta, beta, beta, beta, binomial, binomial, binomial, binomial, binomial, briefInfoOn, cauchy, cauchy, cauchy, chi2, chi2, chi2, copyToClipboard, createURL_xjal, date, dateToTime, day, difference, difference, differenceInDateUnits, differenceInDateUnits, dropTime, erlang, erlang, erlang, error, exponential, exponential, exponential, exponential, exponential, exponential, format, format, format, format, format, format, formatDayOfWeek, formatGeoHeading, formatLatitude, formatLongitude, formatMonth, formatTimeInterval, gamma_frac, gamma, gamma, gamma, gamma, gamma, gammaLog, geometric, geometric, getAmPm, getAmPm, getDayOfMonth, getDayOfMonth, getDayOfWeek, getDayOfWeek, getDayOfYear, getDefaultRandomGenerator, getDistance, getDistance, getDistanceFromPointToLine, getDistanceFromPointToLineSq, getDistanceFromPointToSegment, getDistanceFromPointToSegmentSq, getDistanceSq, getDistanceSq, getHour, getHour, getHourOfDay, getHourOfDay, getLength, getLength, getMillisecond, getMillisecond, getMinute, getMinute, getMonth, getMonth, getRandom, getRandom, getSecond, getSecond, getTime, getYear, getYear, gumbel1, gumbel1, gumbel2, gumbel2, hour, hypergeometric, hypergeometric, inspectOf, isLineIntersectingLine, isLineIntersectingRectangle, isPointInsideRectangle, isPointOnTheSameLine, laplace, laplace, limit, limitMax, limitMin, logarithmic, logarithmic, logistic, logistic, lognormal, lognormal, millisecond, minute, negativeBinomial, negativeBinomial, negativeBinomial, negativeBinomial, normal, normal, normal, normal, normal, normal, pareto, pareto, pareto, pert, pert, poisson, poisson, poisson, poisson, prepareBeforeExperimentStart_xjal, pulse, pulseTrain, quantum, ramp, randomFalse, randomFalse, randomTrue, randomTrue, rayleigh, rayleigh, rayleigh, second, setDefaultRandomGenerator, sqr, step, time, timeToDate, toDate, toDateInMillis, toLatitude, toLongitude, toTimeout, trace, traceln, traceln, traceln, triangular, triangular, triangular, triangular, triangular, uniform_discr, uniform_discr, uniform_discr, uniform_pos, uniform_pos, uniform, uniform, uniform, uniform, uniform, week, weibull, weibull, weibull, weibull, weibull, xidz, zidz
 
Methods inherited from class com.xj.anylogic.engine.Presentable
contains, drawCollection, drawDatabase, drawDataset, drawExcelFile, drawFunction, drawHistogram2DData, drawHistogramData, drawInsert, drawKeyValueTable, drawModel, drawModelElements, drawPlainVariable, drawPresentation, drawQuery, drawShape, drawStatistics, drawTableFunction, drawTextFile, drawUpdate, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, finishReadObject_xjal, getExperiment, getNameOfShape, getPersistentShape, getShapeArcAngle, getShapeArcAngle, getShapeArcStartAngle, getShapeArcStartAngle, getShapeCADCustomLayerColors, getShapeCADDrawingAttributes, getShapeCADDrawingAttributes, getShapeCADFileName, getShapeCADFileName, getShapeCADVisibleLayerNames, getShapeChartColorFromDouble, getShapeChartDataColors, getShapeChartDataItems, getShapeChartDataPlotOptions, getShapeChartDataSets, getShapeChartDataTitles, getShapeChartHistogram2DOptions, getShapeChartHistogramOptions, getShapeChartHistograms, getShapeChartHistograms2D, getShapeChartProperties, getShapeControl, getShapeControl, getShapeControlDefaultValueBoolean, getShapeControlDefaultValueBoolean, getShapeControlDefaultValueDouble, getShapeControlDefaultValueDouble, getShapeControlDefaultValueInt, getShapeControlDefaultValueInt, getShapeControlDefaultValueString, getShapeControlDefaultValueString, getShapeControlManager, getShapeControlMaximum, getShapeControlMaximum, getShapeControlMinimum, getShapeControlMinimum, getShapeControlMultipleSelectionMode, getShapeControlMultipleSelectionMode, getShapeControlProgressString, getShapeControlProgressString, getShapeControlTexts, getShapeControlTexts, getShapeControlTexts2D, getShapeControlTexts2D, getShapeControlType, getShapeControlType, getShapeControlValueType, getShapeControlValueType, getShapeEmbeddedObject, getShapeEmbeddedObject, getShapeFillColor, getShapeFillColor, getShapeFont, getShapeFont, getShapeGroupContent, getShapeHeight, getShapeHeight, getShapeImageFileNames, getShapeImageFileNames, getShapeImageNumber, getShapeImageNumber, getShapeLineColor, getShapeLineColor, getShapeLineDx, getShapeLineDx, getShapeLineDy, getShapeLineDy, getShapeLineStyle, getShapeLineStyle, getShapeLineWidth, getShapeLineWidth, getShapeNPoints, getShapeNPoints, getShapePackagePrefix, getShapePointsDx, getShapePointsDx, getShapePointsDy, getShapePointsDy, getShapeRadiusX, getShapeRadiusX, getShapeRadiusY, getShapeRadiusY, getShapeReplication, getShapeRotation, getShapeRotation, getShapeScaleX, getShapeScaleX, getShapeScaleY, getShapeScaleY, getShapeText, getShapeText, getShapeTextAlignment, getShapeTextAlignment, getShapeType, getShapeWidth, getShapeWidth, getShapeX, getShapeY, getViewAreas, iconContains, isShapeCADNegative, isShapeCADNegative, isShapeClosed, isShapeClosed, isShapeControlEnabled, isShapeControlEnabled, isShapeControlVertical, isShapeControlVertical, isShapePublic, isShapeVisible, isShapeWithManualControlPoints, isShapeWithManualControlPoints, modelElementContains, modelElementContains, onClickIconAt, onClickModelAt, onClickPresentationAt, onItemRemoved, onSelectionChanged, onShapeClick, onShapeClickAt, onShapeGroupDraw, presentationContains, readCustomData, setControlValueToDefault, setControlValueToDefault, writeCustomData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
See Also:
Constant Field Values

SOUTH

public static final int SOUTH
See Also:
Constant Field Values

EAST

public static final int EAST
See Also:
Constant Field Values

WEST

public static final int WEST
See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
See Also:
Constant Field Values

NORTHWEST

public static final int NORTHWEST
See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
See Also:
Constant Field Values

ALL

public static final int ALL
See Also:
Constant Field Values

ALL_CONNECTED

public static final int ALL_CONNECTED
See Also:
Constant Field Values

ALL_NEIGHBORS

public static final int ALL_NEIGHBORS
This destination type is available only in discrete agents

See Also:
Constant Field Values

RANDOM

public static final int RANDOM
See Also:
Constant Field Values

RANDOM_CONNECTED

public static final int RANDOM_CONNECTED
See Also:
Constant Field Values

RANDOM_NEIGHBOR

public static final int RANDOM_NEIGHBOR
This destination type is available only in discrete agents

See Also:
Constant Field Values
Constructor Detail

Agent

public Agent(Engine engine,
             ActiveObject owner,
             ActiveObjectCollection<?> collection)
Method Detail

setEnvironment

public void setEnvironment(Environment<?> env)
Sets up time, space, etc. type for the agent. Must be called during the startup of the agent and provide the environment where the agent belongs to as a parameter.

Parameters:
env - the agent's environment

getEnvironment

public Environment<?> getEnvironment()
Returns the environment where this agent belongs to.

Returns:
the environment where this agent belongs to

onDestroy

public void onDestroy()
This method must be called when the agent is destroyed.

Overrides:
onDestroy in class ActiveObject

onBeforeStep

public void onBeforeStep()
A callback that is called at the beginning of every step in discrete time before onStep() of any agent is called. Can be used as a preparatory action if two-phase steps. Should be defined in a subclass if an action is needed.


onStep

public void onStep()
A callback that is called at every step in discrete time after onStep() of any agent is called. Should be defined in a subclass if an action is needed.


getConnections

public java.util.LinkedList<? extends Agent> getConnections()
Returns a collection of agents connected to this agent (bi-directionally), or null if there have not been any connections yet. You should not modify this collection.

Returns:
collection of connected agents, or null

restoreConnections_xjal

public void restoreConnections_xjal(java.util.LinkedList<?> connections)
This method should not be called by user
This method restores connections of this agent

Parameters:
connections - list of connections, may be null

getConnectionsNumber

public int getConnectionsNumber()
Returns the number of agents connected to this agent.

Returns:
the number of agents connected to this agent

getConnectedAgent

public Agent getConnectedAgent(int index)
Returns the connected agent with a given index.

Parameters:
index - the index of connection
Returns:
the connected agent with a given index

isConnectedTo

public boolean isConnectedTo(Agent a)
Tests if this agent is connectied to a given other agent.

Parameters:
a - another agent
Returns:
true if the agents are connected, false otherwise

disconnectFrom

public boolean disconnectFrom(Agent a)
Disconnects this agent from another given agent.

Parameters:
a - another agent
Returns:
true if the agents were connected, false otherwise

disconnectFromAll

public void disconnectFromAll()
Disconnects the agent from all other agents.


send

public void send(java.lang.Object msg,
                 int mode)
Sends a message to an agent or a group of agents, as specified by the mode parameter. The message will be delivered during a separate event scheduled to occur in zero time after the current one. If you are OK with the message delivered immediately during this event, use deliver() method, which has better performance.

Parameters:
msg - a message
mode - specifies the message sending mode (ALL, RANDOM, ...)

deliver

public void deliver(java.lang.Object msg,
                    int mode)
Delivers a message to an agent or a group of agents, as specified by the mode parameter immediately during this method call. If you wish this to happen in a separate event, use send() method.

Parameters:
msg - the message
mode - specifies the message sending mode (ALL, RANDOM, ...)

receive

public void receive(java.lang.Object msg)
Immediately delivers a message to this agent. Sender is set to null.

Parameters:
msg - the message

agentInfo

public java.lang.String agentInfo()

getShapeX

public double getShapeX(int id,
                        int index)
Description copied from class: Presentable
Should be overridden to return the X coordinate of a non-persistent shape.

Overrides:
getShapeX in class Presentable
Parameters:
id - the shape id
index - index of the shape (for replicated shapes)
Returns:
the X coordinate of the shape, 0 by default

getShapeY

public double getShapeY(int id,
                        int index)
Description copied from class: Presentable
Should be overridden to return the Y coordinate of a non-persistent shape.

Overrides:
getShapeY in class Presentable
Parameters:
id - the shape id
index - index of the shape (for replicated shapes)
Returns:
the Y coordinate of the shape, 0 by default


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.