com.xj.anylogic.engine
Class Environment<T extends Agent>

java.lang.Object
  extended by com.xj.anylogic.engine.Environment<T>
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, java.io.Serializable
Direct Known Subclasses:
EnvironmentContinuous, EnvironmentDiscrete2D

public abstract class Environment<T extends Agent>
extends java.lang.Object
implements java.io.Serializable, com.xj.anylogic.engine.internal.Child

Base class for agent environments. There are several subclasses for different space types:

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

Nested Class Summary
static class Environment.AgentCollection<T extends Agent>
          A collection of agents.
 
Field Summary
static int LAYOUT_ARRANGED
           
static int LAYOUT_RANDOM
           
static int LAYOUT_RING
           
static int LAYOUT_SPRING_MASS
           
static int LAYOUT_USER_DEFINED
           
static int NETWORK_ALL_IN_RANGE
          This network type is available only in continuous environments
static int NETWORK_RANDOM
           
static int NETWORK_RING_LATTICE
           
static int NETWORK_SCALE_FREE
           
static int NETWORK_SMALL_WORLD
           
static int NETWORK_USER_DEFINED
           
static int SPACE_CONTINUOUS_2D
           
static int SPACE_DISCRETE_2D
           
static int TIME_CONTINUOUS
           
static int TIME_DISCRETE
           
 
Constructor Summary
Environment(ActiveObject activeObject)
          Creates an environment with default settings:
- continuous time
- continuous space of size 500 x 500
- no connections ("user-degfined" network)
You may change these settings by calling the corresponding methods while the environment is empty (no agents registered).
 
Method Summary
 void applyNetwork()
          Discards all existing connections and establishes new connection network according to the current network settings.
 boolean areStepsEnabled()
          Tests if the time steps are enabled.
 void deliverToAll(java.lang.Object msg)
          Immediately delivers a nessage to all agents in the environment.
 void deliverToRandom(java.lang.Object msg)
          Immediately delivers a nessage to a random agent in the environment, if there are any agents.
 void disableSteps()
          Disables time steps.
 void enableSteps(double stepDuration)
          Enables discrete time steps with a given duration.
abstract  java.lang.String formatSpaceType()
          Returns the name of the space type
 Environment.AgentCollection<T> getAgentCollection()
          Returns the collection of all agents registered with this environment.
 double getConnectionsPerAgent()
          Returns the average (or exact) number of connections per agent.
 double getHeight()
          Returns the height of environment space.
 double getNeighborLinkProbability()
          Returns the probability of an agent connection to be a neighbor.
 int getNetworkType()
          Returns the network type.
 T getRandomAgent()
          Returns a randomly chosen agent in the environment or null if there are no agents
 int getScaleFreeM()
          Returns the M parameter of a scale free network.
abstract  int getSpaceType()
          Deprecated. this method is deprecated since different space types are presented in different Environment* classes
 double getWidth()
          Returns the width of environment space.
static java.lang.String layoutTypeToString(int type)
           
 void onAfterStep()
          A callback that is called when at the end of every step after the agents have performed all their step actions.
 void onBeforeStep()
          A callback that is called at the beginning of every step before the agents are asked to perform any their step actions.
 void onDestroy()
          This method must be called when the environment is destroyed.
 void restoreOwner(java.lang.Object owner)
          This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
 void setNetworkRandom(double connectionsPerAgent)
          Sets network type to random with a given average number of connections per agent.
 void setNetworkRingLattice(int connectionsPerAgent)
          Sets network type to ring lattice.
 void setNetworkScaleFree(int m)
          Sets the network type to "scale free".
 void setNetworkSmallWorld(int connectionsPerAgent, double neighborLinkProbability)
          Sets network type to "small world".
 void setNetworkUserDefined()
          Sets network type to user-defined.
 int size()
          Returns the number of agents registered with this environment.
static java.lang.String spaceTypeToString(int type)
          Deprecated. use formatSpaceType()
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIME_CONTINUOUS

public static final int TIME_CONTINUOUS
See Also:
Constant Field Values

TIME_DISCRETE

public static final int TIME_DISCRETE
See Also:
Constant Field Values

SPACE_CONTINUOUS_2D

public static final int SPACE_CONTINUOUS_2D
See Also:
Constant Field Values

SPACE_DISCRETE_2D

public static final int SPACE_DISCRETE_2D
See Also:
Constant Field Values

NETWORK_USER_DEFINED

public static final int NETWORK_USER_DEFINED
See Also:
Constant Field Values

NETWORK_RANDOM

public static final int NETWORK_RANDOM
See Also:
Constant Field Values

NETWORK_ALL_IN_RANGE

public static final int NETWORK_ALL_IN_RANGE
This network type is available only in continuous environments

See Also:
Constant Field Values

NETWORK_RING_LATTICE

public static final int NETWORK_RING_LATTICE
See Also:
Constant Field Values

NETWORK_SMALL_WORLD

public static final int NETWORK_SMALL_WORLD
See Also:
Constant Field Values

NETWORK_SCALE_FREE

public static final int NETWORK_SCALE_FREE
See Also:
Constant Field Values

LAYOUT_USER_DEFINED

public static final int LAYOUT_USER_DEFINED
See Also:
Constant Field Values

LAYOUT_RANDOM

public static final int LAYOUT_RANDOM
See Also:
Constant Field Values

LAYOUT_ARRANGED

public static final int LAYOUT_ARRANGED
See Also:
Constant Field Values

LAYOUT_RING

public static final int LAYOUT_RING
See Also:
Constant Field Values

LAYOUT_SPRING_MASS

public static final int LAYOUT_SPRING_MASS
See Also:
Constant Field Values
Constructor Detail

Environment

public Environment(ActiveObject activeObject)
Creates an environment with default settings:
- continuous time
- continuous space of size 500 x 500
- no connections ("user-degfined" network)
You may change these settings by calling the corresponding methods while the environment is empty (no agents registered).

Parameters:
activeObject - the active object where environemnt is defined
Method Detail

onDestroy

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


getAgentCollection

public Environment.AgentCollection<T> getAgentCollection()
Returns the collection of all agents registered with this environment. You may iterate over that collection.


size

public int size()
Returns the number of agents registered with this environment.

Returns:
the number of agents registered with this environment

getRandomAgent

public T getRandomAgent()
Returns a randomly chosen agent in the environment or null if there are no agents

Returns:
a randomly chosen agent in the environment, or null

disableSteps

public void disableSteps()
Disables time steps.


enableSteps

public void enableSteps(double stepDuration)
Enables discrete time steps with a given duration.

Parameters:
stepDuration - the duration of a step, normally 1

areStepsEnabled

public boolean areStepsEnabled()
Tests if the time steps are enabled.

Returns:
true if the time steps are enabled, false otherwise

onBeforeStep

public void onBeforeStep()
A callback that is called at the beginning of every step before the agents are asked to perform any their step actions. Should be defined in a subclass if an action is needed.


onAfterStep

public void onAfterStep()
A callback that is called when at the end of every step after the agents have performed all their step actions. Should be defined in a subclass if an action is needed.


getSpaceType

@Deprecated
public abstract int getSpaceType()
Deprecated. this method is deprecated since different space types are presented in different Environment* classes

Returns the space type, e.g. SPACE_DISCRETE_2D
(In case of GIS-based environment, always returns SPACE_CONTINUOUS_2D)

Returns:
the space type

getWidth

public double getWidth()
Returns the width of environment space.
(In case of GIS-based environment, returns 360)

Returns:
the width of environment space

getHeight

public double getHeight()
Returns the height of environment space.
(In case of GIS-based environment, returns 180)

Returns:
the height of environment space

deliverToAll

public void deliverToAll(java.lang.Object msg)
Immediately delivers a nessage to all agents in the environment.

Parameters:
msg - the message

deliverToRandom

public void deliverToRandom(java.lang.Object msg)
Immediately delivers a nessage to a random agent in the environment, if there are any agents.

Parameters:
msg - the message

restoreOwner

public void restoreOwner(java.lang.Object owner)
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading

Specified by:
restoreOwner in interface com.xj.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup

setNetworkUserDefined

public void setNetworkUserDefined()
Sets network type to user-defined. As a result, a subsequent call of applyNetwork() will do nothing. This is also a default network type.


setNetworkRandom

public void setNetworkRandom(double connectionsPerAgent)
Sets network type to random with a given average number of connections per agent. Call applyNetwork() to actually create network connections.

Parameters:
connectionsPerAgent - average number of connections per agent

setNetworkRingLattice

public void setNetworkRingLattice(int connectionsPerAgent)
Sets network type to ring lattice. All agents are considered to be in a ring in their natural order and each agent is connected to a given number of closest neighbors. Call applyNetwork() to actually create network connections.

Parameters:
connectionsPerAgent - number of connections per agent (even)

setNetworkSmallWorld

public void setNetworkSmallWorld(int connectionsPerAgent,
                                 double neighborLinkProbability)
Sets network type to "small world". Small world network can be obtained from a ring lattice by rewiring some links to long-distant links. Call applyNetwork() to actually create network connections.

Parameters:
connectionsPerAgent - number of connections per agent (even)
neighborLinkProbability - probability of connection to link neighbors

setNetworkScaleFree

public void setNetworkScaleFree(int m)
Sets the network type to "scale free". Scale free network is constructed according to Barabasi, A. L. and R. Albert. 1999. Emergence of scaling in random networks. Science 286(5439): 509-512. Call applyNetwork() to actually create network connections.

Parameters:
m - parameter of the scale free network (start number of hubs?)

getNetworkType

public int getNetworkType()
Returns the network type. Note that this type has not necessarily been applied.

Returns:
the network type

getConnectionsPerAgent

public double getConnectionsPerAgent()
Returns the average (or exact) number of connections per agent. Applies to random, ring lattice and small world networks.

Returns:
the average (or exact) number of connections per agent

getNeighborLinkProbability

public double getNeighborLinkProbability()
Returns the probability of an agent connection to be a neighbor. Applies to "small world" network.

Returns:
the probability of an agent connection to be a neighbor

getScaleFreeM

public int getScaleFreeM()
Returns the M parameter of a scale free network. Applies to "scale free" network.

Returns:
the M parameter of a scale free network

applyNetwork

public void applyNetwork()
Discards all existing connections and establishes new connection network according to the current network settings.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

formatSpaceType

public abstract java.lang.String formatSpaceType()
Returns the name of the space type

Returns:
the name of the space type

spaceTypeToString

@Deprecated
public static java.lang.String spaceTypeToString(int type)
Deprecated. use formatSpaceType()


layoutTypeToString

public static java.lang.String layoutTypeToString(int type)


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