org.ascape.model
Class Cell

java.lang.Object
  extended by org.ascape.model.AscapeObject
      extended by org.ascape.model.Agent
          extended by org.ascape.model.LocatedAgent
              extended by org.ascape.model.Cell
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Location, Node, HasName, RandomFunctions
Direct Known Subclasses:
AllOutputViewTest.TestAgent, CellOccupant, HostCell

public class Cell
extends LocatedAgent
implements Node

The base class for all members of lattices. Currently considered a node, although nodes might be become a superclass of this class as the notion of a coordinate may not be useful in all graphs.

Since:
1.0
Version:
3.0
Author:
Miles Parker
See Also:
Serialized Form

Field Summary
static Rule CALCULATE_NEIGHBORS_RULE
          A rule causing the taget agent to move to a random location.
protected  java.util.List neighbors
          For better performance we store neighbors so we only have to calculate them once.
static Rule PLAY_NEIGHBORS_RULE
          A rule causing the target agent to interact with each of its neighbors as specified by the Agent.play() method.
static Rule PLAY_RANDOM_NEIGHBOR_RULE
          A rule causing the target agent to interact with one of its neighbors as specified by the Agent.play() method.
 
Fields inherited from class org.ascape.model.LocatedAgent
agentSize, coordinate, MOVE_RANDOM_LOCATION_RULE, RANDOM_WALK_RULE, thisUpdate
 
Fields inherited from class org.ascape.model.Agent
DEATH_RULE, FISSIONING_RULE, FORCE_DIE_RULE, FORCE_FISSION_RULE, FORCE_MOVE_RULE, INITIALIZE_RULE, ITERATE_AND_UPDATE_RULE, ITERATE_RULE, METABOLISM_RULE, MOVEMENT_RULE, PLAY_OTHER, UPDATE_RULE
 
Fields inherited from class org.ascape.model.AscapeObject
ARBITRARY_SEED, name, scape
 
Constructor Summary
Cell()
           
 
Method Summary
 void calculateNeighbors()
          Computes the cells neighbors in the context of the primary scape and assigns them as this cell's neighbors.
 java.lang.Object clone()
          Clones the host cell, making coordinate null.
 int countNeighbors(Conditional condition)
          Returns the number of cells that are neighbors and that meet the supplied condition.
 java.util.List findNeighbors()
          Returns this cells neighbors, that is, the set of cells adjoining this cell as defined by the scape's geometry.
static java.util.List findOccupants(java.util.List candidates)
          Returns all cell occupants of the provided cells.
 Node findRandomAvailableNeighbor()
          Find random neighbor.
 Node findRandomNeighbor()
          Returns a cell randomly selected from among this cell's neighbors.
 Cell findRelative(Coordinate c)
           
 int getDistance(Cell target)
           
 Cell[] getNeighbors()
          Deprecated. use findNeighbors instead.
 java.util.List getNeighbors(Conditional condition)
          Returns the neighbors of the cell that meet the supplied condition.
 java.util.List getNetwork()
          Returns some network of related cells.
 Node getOccupant()
          Returns any occupants of this cell.
protected static Conditional hostedCondition(Conditional condition)
           
 void initialize()
          Initialize any values.
 boolean isAvailable()
          Is this cell available for occupation? Again, this will always return false because base cells can not host agents.
 void playNeighbors()
          Interact with each neighbor as specified by the Agent.play() method.
 void playRandomNeighbor()
          Interact with each neighbor as specified by the Agent.play() method.
 void removeOccupant()
          Removes this cell's occupant.
 void setNeighbors(Cell[] neighbors)
          Sets this cell's neighbors.
 void setNeighborsList(java.util.List neighbors)
          Sets this cell's neighbors.
 void setNetwork(java.util.List network)
          Sets a network of related cells.
 void setOccupant(Node occupant)
          Sets this cell's occupant.
 java.lang.String toString()
          A string representation of this cell.
 
Methods inherited from class org.ascape.model.LocatedAgent
calculateDistance, calculateDistance, countWithin, countWithin, countWithin, findMaximumWithin, findNearest, findNearest, findNearest, findNearest, findNearest, findWithin, findWithin, findWithin, findWithin, getAgentSize, getCoordinate, hasWithin, hasWithin, hasWithin, isUpdateNeeded, moveAway, moveAway, moveAway, moveTo, moveToRandomLocation, moveToward, moveToward, moveToward, randomWalk, requestUpdate, requestUpdateNext, setAgentSize, setCoordinate
 
Methods inherited from class org.ascape.model.Agent
clearDeleteMarker, death, deathCondition, die, execute, execute, fission, fissionCondition, fissioning, getColor, getColor, getImage, getImage, getIteration, getRoot, isDelete, isInitialized, iterate, markForDeletion, metabolism, move, movement, movementCondition, play, scapeCreated, setInitialized, setScape, update
 
Methods inherited from class org.ascape.model.AscapeObject
diffDeep, diffDeep, diffDeepBFS, diffDeepDFS, diffDeepValidate, diffDeepVisit, equalsDeep, equalsDeep, equalsDeep, getComparisonStream, getName, getRandom, getRandomSeed, getScape, randomInRange, randomInRange, randomIs, randomToLimit, reseed, setComparisonStream, setName, setRandom, setRandomSeed
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ascape.model.space.Location
clearDeleteMarker, getCoordinate, isDelete, markForDeletion, setCoordinate
 

Field Detail

PLAY_NEIGHBORS_RULE

public static final Rule PLAY_NEIGHBORS_RULE
A rule causing the target agent to interact with each of its neighbors as specified by the Agent.play() method.


PLAY_RANDOM_NEIGHBOR_RULE

public static final Rule PLAY_RANDOM_NEIGHBOR_RULE
A rule causing the target agent to interact with one of its neighbors as specified by the Agent.play() method.


CALCULATE_NEIGHBORS_RULE

public static final Rule CALCULATE_NEIGHBORS_RULE
A rule causing the taget agent to move to a random location.


neighbors

protected java.util.List neighbors
For better performance we store neighbors so we only have to calculate them once. Typically only used by scapes with a static strucure.

Constructor Detail

Cell

public Cell()
Method Detail

initialize

public void initialize()
Description copied from class: Agent
Initialize any values. This method will be called automatically when the parent scape is initialized or started, so override this to provide initial values, location, etc... Any parent models of this agent's scape can be assumed to be initialized. Of course, other agents within the scape should be assumed not to have been initialized.

Specified by:
initialize in interface Location
Overrides:
initialize in class LocatedAgent

calculateNeighbors

public void calculateNeighbors()
Computes the cells neighbors in the context of the primary scape and assigns them as this cell's neighbors.


getNeighbors

public Cell[] getNeighbors()
Deprecated. use findNeighbors instead.

Returns this cells neighbors, that is, the set of cells as an array of cells. (Principally here for backward compatibility.) adjoing this cell as defined by the scape's geometry.


findNeighbors

public java.util.List findNeighbors()
Returns this cells neighbors, that is, the set of cells adjoining this cell as defined by the scape's geometry. Note: returned as unmodifieable list for perforamnce reasons. If you need to modify this list, make a copy.

Specified by:
findNeighbors in interface Node
Returns:
the list

findRelative

public Cell findRelative(Coordinate c)
                  throws java.lang.UnsupportedOperationException
Throws:
java.lang.UnsupportedOperationException

getNeighbors

public java.util.List getNeighbors(Conditional condition)
Returns the neighbors of the cell that meet the supplied condition.

Parameters:
condition - the condition that found cell must meet

countNeighbors

public int countNeighbors(Conditional condition)
Returns the number of cells that are neighbors and that meet the supplied condition.

Parameters:
condition - the condition that found cell must meet

playRandomNeighbor

public void playRandomNeighbor()
Interact with each neighbor as specified by the Agent.play() method.


playNeighbors

public void playNeighbors()
Interact with each neighbor as specified by the Agent.play() method.


getDistance

public int getDistance(Cell target)

setNeighborsList

public void setNeighborsList(java.util.List neighbors)
Sets this cell's neighbors. Used by agent scape intialize methods to inform the cell of it's neighbors. When creating new lattice classes, be sure to set all cell's neighbors using this method. Note that this method could also be used for creating dynamic spaces!

Parameters:
neighbors - the array of neighbors to set

setNeighbors

public void setNeighbors(Cell[] neighbors)
Sets this cell's neighbors. Used by agent scape intialize methods to inform the cell of it's neighbors. When creating new lattice classes, be sure to set all cell's neighbors using this method. Note that this method could also be used for creating dynamic spaces! Preferred method is to use setNeighborsList.

Parameters:
neighbors - the array of neighbors to set

findRandomNeighbor

public Node findRandomNeighbor()
Returns a cell randomly selected from among this cell's neighbors.

Specified by:
findRandomNeighbor in interface Node
Returns:
the node

findRandomAvailableNeighbor

public Node findRandomAvailableNeighbor()
Description copied from interface: Node
Find random neighbor.

Specified by:
findRandomAvailableNeighbor in interface Node
Returns:
the node

getOccupant

public Node getOccupant()
Returns any occupants of this cell. Cell occupants are incapable of hosting agents, so this will always be null for instantiations of this class.

Specified by:
getOccupant in interface Node
Returns:
the occupant

getNetwork

public java.util.List getNetwork()
Returns some network of related cells. The network itself is implementation specific.


setNetwork

public void setNetwork(java.util.List network)
Sets a network of related cells.


isAvailable

public boolean isAvailable()
Is this cell available for occupation? Again, this will always return false because base cells can not host agents.

Specified by:
isAvailable in interface Node
Returns:
true, if is available

setOccupant

public void setOccupant(Node occupant)
Sets this cell's occupant. Produces an error, because base cells can not host agents.

Specified by:
setOccupant in interface Node
Parameters:
occupant - the occupant

removeOccupant

public void removeOccupant()
Removes this cell's occupant. Produces an error, because base cells can not host agents.


clone

public java.lang.Object clone()
Clones the host cell, making coordinate null.

Specified by:
clone in interface Location
Overrides:
clone in class Agent
Returns:
the object

toString

public java.lang.String toString()
A string representation of this cell.

Overrides:
toString in class LocatedAgent

hostedCondition

protected static Conditional hostedCondition(Conditional condition)

findOccupants

public static java.util.List findOccupants(java.util.List candidates)
Returns all cell occupants of the provided cells.

Parameters:
candidates - the cells to return occupants of


Copyright © 1998-2008 The Brookings Institution, NuTech Solutions, Metascape, LLC All Rights Reserved.