org.primordion.xholon.base
Class Patch

java.lang.Object
  extended byorg.primordion.xholon.base.Xholon
      extended byorg.primordion.xholon.base.XholonWithPorts
          extended byorg.primordion.xholon.base.AbstractGrid
              extended byorg.primordion.xholon.base.GridEntity
                  extended byorg.primordion.xholon.base.Patch
All Implemented Interfaces:
IGrid, IPatch, IXholon
Direct Known Subclasses:
Grass, HabitatCellStupidModel16nl

public class Patch
extends GridEntity
implements IPatch

A patch is an agent in the turtle mechanism. The turtle mechanism is based on Logo and NetLogo.

Since:
0.5 (Created on February 28, 2007)
Author:
Ken Webb
See Also:
NetLogo website http://ccl.northwestern.edu/netlogo/

Field Summary
 int pcolor
           
 int pxcor
           
 int pycor
           
 
Fields inherited from class org.primordion.xholon.base.AbstractGrid
P_BEHAVIOR, P_NEXT, P_PREVIOUS
 
Fields inherited from class org.primordion.xholon.base.XholonWithPorts
port
 
Fields inherited from class org.primordion.xholon.base.Xholon
DEFAULT_LEVEL, interaction, interactionsEnabled
 
Fields inherited from interface org.primordion.xholon.base.IPatch
COMMANDID_NONE, FILTERID_NONE
 
Fields inherited from interface org.primordion.xholon.base.IXholon
DEFAULT_SIZE_MSG_Q, NINCLUDE_PSC, NINCLUDE_PSx, NINCLUDE_PxC, NINCLUDE_Pxx, NINCLUDE_xSC, NINCLUDE_xSx, NINCLUDE_xxC, NINCLUDE_xxx
 
Fields inherited from interface org.primordion.xholon.base.IGrid
BOUNDARY_GRID, BOUNDARY_TORUS, NEIGHBORHOOD_1DCA, NEIGHBORHOOD_HEXAGONAL, NEIGHBORHOOD_MOORE, NEIGHBORHOOD_SIBLING, NEIGHBORHOOD_VON_NEUMANN, P_CAFUTURESELF, P_CALEFTNEIGHBOR, P_CARIGHTNEIGHBOR, P_EAST, P_HEX0, P_HEX1, P_HEX2, P_HEX3, P_HEX4, P_HEX5, P_NORTH, P_NORTHEAST, P_NORTHWEST, P_SOUTH, P_SOUTHEAST, P_SOUTHWEST, P_STAYHERE, P_WEST, REGULAR_COMPLETE, REGULAR_COMPLETE_SELF, REGULAR_CYCLE, REGULAR_WHEEL
 
Constructor Summary
Patch()
           
 
Method Summary
 void aggregate(double amount)
          Aggregate by keeping a count of the number of individuals of a given type of Patch.
 void beep()
          Make a single short beep sound.
 double distance(IXholon turtleOrPatch)
          Return the distance between self and the specified turtle or patch.
 double distancexy(double x, double y)
          Return the distance between yourself and the specified x, y coordinates.
 int getPcolor()
          Get the patch's pcolor.
 java.lang.String getPlabel()
          Get the patch's label, a String that helps to identify it.
 int getPxcor()
          Get the patch's x coordinate.
 int getPycor()
          Get the patch's y coordinate.
 java.util.Vector inRadius(int radius)
          This works for a torus or grid where each cell has 8 neighbors.
 java.util.Vector inRadius(int radius, int filterId)
          This works for a torus or grid where each cell has 8 neighbors.
 java.util.Vector neighbors()
          Return the 8 surrounding neighbor patches.
 java.util.Vector neighbors4()
          Return the 4 surrounding neighbor patches.
 IPatch patch(int pxcor, int pycor)
          Return the patch with the specified absolute coordinates.
 IPatch patchAt(int dx, int dy)
          Return the single patch at the specified x and y relative distance.
 IPatch patchAtHeadingAndDistance(double heading, double distance)
          Return the single patch at the specified absolute heading and relative distance.
 void setPcolor(int pcolor)
          Set the patch's pcolor.
 void setPlabel(java.lang.String plabel)
          Set or change the patch's label.
 void setPxcor(int pxcor)
          Set the patch's x coordinate.
 void setPycor(int pycor)
          Set the patch's y coordinate.
 void sprout(IXholonClass xhClazz, int numTurtles, int commandId)
          Create a specified number of new turtles on the current patch.
 java.lang.String toString()
           
 double towards(IXholon turtleOrPatch)
          Return the heading between self and the specified turtle or patch.
 double towardsxy(double x, double y)
          Return the heading between self and the specified x, y coordinates.
 java.util.Vector turtlesAt(int dx, int dy)
          Return the turtles located at the single patch at the specified x and y relative distance.
 java.util.Vector turtlesHere()
          Return the turtles located at the current patch.
 java.util.Vector turtlesOn()
          Return the turtles that are on the given patch or patches, or standing on the same patch as the given turtle or turtles.
 java.util.Vector with(java.util.Vector vIn, int filterId)
          Filters the input vector to produce an output vector.
 
Methods inherited from class org.primordion.xholon.base.GridEntity
getMaxPorts, setPorts
 
Methods inherited from class org.primordion.xholon.base.AbstractGrid
configure, getNeighType, getNumNeighbors, initialize, moveXholonsToGrid, postConfigure, postReconfigure, preReconfigure, reconfigure, setCaFuture, setCaLeft, setCaRight, setEast, setHex0, setHex1, setHex2, setHex3, setHex4, setHex5, setNorth, setNorthEast, setNorthWest, setSiblingsComplete, setSiblingsCompleteSelf, setSiblingsCycle, setSiblingsWheel, setSouth, setSouthEast, setSouthWest, setWest
 
Methods inherited from class org.primordion.xholon.base.XholonWithPorts
configure, getPort, isActiveObject, isBound, isContainer, isPassiveObject, setMaxPorts, terminate
 
Methods inherited from class org.primordion.xholon.base.Xholon
act, appendChild, appendChild, appendChild, cleanup, createStructure, decVal, decVal, depth, draw, getChildNodes, getFirstChild, getFirstSibling, getId, getLastChild, getLastSibling, getName, getNeighbors, getNextId, getNextSibling, getNthChild, getNthSibling, getNumChildren, getNumSiblings, getParentNode, getPreviousSibling, getRoleName, getRootNode, getSiblings, getSizeMessageQ, getUid, getVal_boolean, getVal_byte, getVal_char, getVal_double, getVal_float, getVal_int, getVal_long, getVal_Object, getVal_short, getVal_String, getVal, getXhc, getXhcId, getXhcName, getXhType, handleNodeSelection, hasAncestor, hasChildNodes, hasChildOrSiblingNodes, hasNextSibling, hasParentNode, height, incVal, incVal, initStatics, inOrderPrint, insertAfter, insertBefore, insertFirstChild, isExternal, isInternal, isLeaf, isRootNode, performActivity, performActivity, performBooleanActivity, performBooleanActivity, performDoubleActivity, performGuard, performVoidActivity, postAct, postOrderPrint, preAct, preConfigure, preOrderPrint, print, println, processMessageQ, processReceivedMessage, remove, removeChild, resetNextId, sendMessage, sendMessage, sendMessage, setAttributeVal, setFactory, setFirstChild, setId, setNextSibling, setParentChildLinks, setParentNode, setParentSiblingLinks, setRoleName, setSizeMessageQ, setUid, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVariableValue, setXhc, swapNode, treeSize, writeXml
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.primordion.xholon.base.IXholon
act, appendChild, appendChild, appendChild, cleanup, configure, configure, createStructure, decVal, decVal, depth, draw, getChildNodes, getFirstChild, getFirstSibling, getId, getLastChild, getLastSibling, getName, getNeighbors, getNextSibling, getNthChild, getNthSibling, getNumChildren, getNumSiblings, getParentNode, getPort, getPreviousSibling, getRoleName, getRootNode, getSiblings, getUid, getVal_boolean, getVal_byte, getVal_char, getVal_double, getVal_float, getVal_int, getVal_long, getVal_Object, getVal_short, getVal_String, getVal, getXhc, getXhcId, getXhcName, getXhType, handleNodeSelection, hasAncestor, hasChildNodes, hasChildOrSiblingNodes, hasNextSibling, hasParentNode, height, incVal, incVal, initialize, initStatics, inOrderPrint, insertAfter, insertBefore, insertFirstChild, isActiveObject, isBound, isContainer, isExternal, isInternal, isLeaf, isPassiveObject, isRootNode, performActivity, performActivity, performBooleanActivity, performBooleanActivity, performDoubleActivity, performGuard, performVoidActivity, postAct, postConfigure, postOrderPrint, postReconfigure, preAct, preConfigure, preOrderPrint, preReconfigure, print, println, processMessageQ, processReceivedMessage, reconfigure, remove, removeChild, sendMessage, sendMessage, sendMessage, setAttributeVal, setFirstChild, setId, setNextSibling, setParentChildLinks, setParentNode, setParentSiblingLinks, setPorts, setRoleName, setUid, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVariableValue, setXhc, swapNode, terminate, treeSize, writeXml
 
Methods inherited from interface org.primordion.xholon.base.IGrid
getNeighType, getNumNeighbors, moveXholonsToGrid, setCaFuture, setCaLeft, setCaRight, setEast, setHex0, setHex1, setHex2, setHex3, setHex4, setHex5, setNorth, setNorthEast, setNorthWest, setSiblingsComplete, setSiblingsCompleteSelf, setSiblingsCycle, setSiblingsWheel, setSouth, setSouthEast, setSouthWest, setWest
 

Field Detail

pcolor

public int pcolor

pxcor

public int pxcor

pycor

public int pycor
Constructor Detail

Patch

public Patch()
Method Detail

beep

public void beep()
Description copied from interface: IPatch
Make a single short beep sound.

Specified by:
beep in interface IPatch

distance

public double distance(IXholon turtleOrPatch)
Description copied from interface: IPatch
Return the distance between self and the specified turtle or patch.

Specified by:
distance in interface IPatch
Parameters:
turtleOrPatch - A turtle or patch object.
Returns:
A distance in units.

distancexy

public double distancexy(double x,
                         double y)
Description copied from interface: IPatch
Return the distance between yourself and the specified x, y coordinates.

Specified by:
distancexy in interface IPatch
Parameters:
x - A global x coordinate.
y - A global y coordinate.
Returns:
A distance in units.

inRadius

public java.util.Vector inRadius(int radius)
This works for a torus or grid where each cell has 8 neighbors.

Specified by:
inRadius in interface IPatch
Parameters:
radius - Distance from the current patch. The current patch is a radius of 0 from itself.
Returns:
A vector containing zero or more gridCells.
See Also:
IPatch.inRadius(int)

inRadius

public java.util.Vector inRadius(int radius,
                                 int filterId)
This works for a torus or grid where each cell has 8 neighbors.

Specified by:
inRadius in interface IPatch
Parameters:
radius - Distance from the current patch. The current patch is a radius of 0 from itself.
filterId - An ID that can be used by performBooleanActivity() to select a specific filter.
Returns:
A vector containing zero or more gridCells.
See Also:
IPatch.inRadius(int, int)

neighbors

public java.util.Vector neighbors()
Description copied from interface: IPatch
Return the 8 surrounding neighbor patches.

Specified by:
neighbors in interface IPatch
Returns:
A collection of IPatch instances.

neighbors4

public java.util.Vector neighbors4()
Description copied from interface: IPatch
Return the 4 surrounding neighbor patches.

Specified by:
neighbors4 in interface IPatch
Returns:
A collection of IPatch instances.

patch

public IPatch patch(int pxcor,
                    int pycor)
Description copied from interface: IPatch
Return the patch with the specified absolute coordinates.

Specified by:
patch in interface IPatch
Parameters:
pxcor - An x coordinate.
pycor - A y coordinate.
Returns:
A patch instance, or null.

patchAt

public IPatch patchAt(int dx,
                      int dy)
Description copied from interface: IPatch
Return the single patch at the specified x and y relative distance.

Specified by:
patchAt in interface IPatch
Parameters:
dx - A relative distance in the x direction, in patches.
dy - A relative distance in the y direction, in patches.
Returns:
A patch, or null.

patchAtHeadingAndDistance

public IPatch patchAtHeadingAndDistance(double heading,
                                        double distance)
Description copied from interface: IPatch
Return the single patch at the specified absolute heading and relative distance.

Specified by:
patchAtHeadingAndDistance in interface IPatch
Parameters:
heading - An absolute angle measured in degrees.
distance - A distance measured in units.
Returns:
A patch, or null.

sprout

public void sprout(IXholonClass xhClazz,
                   int numTurtles,
                   int commandId)
Description copied from interface: IPatch
Create a specified number of new turtles on the current patch.

Specified by:
sprout in interface IPatch
Parameters:
xhClazz - The XholonClass that the new turtles should be members of.
numTurtles - The number of new turtles to hatch.
commandId - The ID of a set of turtle commands that can be executed by calling performActivity(int commandId) on each new turtle.

towards

public double towards(IXholon turtleOrPatch)
Description copied from interface: IPatch
Return the heading between self and the specified turtle or patch.

Specified by:
towards in interface IPatch
Parameters:
turtleOrPatch - A turtle or patch object.
Returns:
A A heading angle in degrees.

towardsxy

public double towardsxy(double x,
                        double y)
Description copied from interface: IPatch
Return the heading between self and the specified x, y coordinates.

Specified by:
towardsxy in interface IPatch
Parameters:
x - A global x coordinate.
y - A global y coordinate.
Returns:
A heading angle in degrees.

turtlesAt

public java.util.Vector turtlesAt(int dx,
                                  int dy)
Description copied from interface: IPatch
Return the turtles located at the single patch at the specified x and y relative distance.

Specified by:
turtlesAt in interface IPatch
Parameters:
dx - A relative distance in the x direction, in patches.
dy - A relative distance in the y direction, in patches.
Returns:
A collection of ITurtle instances.

turtlesHere

public java.util.Vector turtlesHere()
Description copied from interface: IPatch
Return the turtles located at the current patch.

Specified by:
turtlesHere in interface IPatch
Returns:
A collection of ITurtle instances.

turtlesOn

public java.util.Vector turtlesOn()
Description copied from interface: IPatch
Return the turtles that are on the given patch or patches, or standing on the same patch as the given turtle or turtles.

Specified by:
turtlesOn in interface IPatch
Returns:
A collection of ITurtle instances.

with

public java.util.Vector with(java.util.Vector vIn,
                             int filterId)
Description copied from interface: IPatch
Filters the input vector to produce an output vector.

Specified by:
with in interface IPatch
Parameters:
vIn - A collection of ITurtle instances.
filterId - The ID of a turtle filter.
Returns:
A filtered collection of ITurtle instances.

getPcolor

public int getPcolor()
Description copied from interface: IPatch
Get the patch's pcolor.

Specified by:
getPcolor in interface IPatch
Returns:
A pcolor value, as defined in ITurtlePatchColor.

setPcolor

public void setPcolor(int pcolor)
Description copied from interface: IPatch
Set the patch's pcolor. NetLogo: set pcolor value

Specified by:
setPcolor in interface IPatch
Parameters:
pcolor - A pcolor value, as defined in ITurtlePatchColor.

getPlabel

public java.lang.String getPlabel()
Description copied from interface: IPatch
Get the patch's label, a String that helps to identify it.

Specified by:
getPlabel in interface IPatch
Returns:
A label.

setPlabel

public void setPlabel(java.lang.String plabel)
Description copied from interface: IPatch
Set or change the patch's label. Warning: Use caution when changing the label.

Specified by:
setPlabel in interface IPatch

getPxcor

public int getPxcor()
Description copied from interface: IPatch
Get the patch's x coordinate.

Specified by:
getPxcor in interface IPatch
Returns:
The pxcor value.

setPxcor

public void setPxcor(int pxcor)
Description copied from interface: IPatch
Set the patch's x coordinate.

Specified by:
setPxcor in interface IPatch

getPycor

public int getPycor()
Description copied from interface: IPatch
Get the patch's y coordinate.

Specified by:
getPycor in interface IPatch
Returns:
The pycor value.

setPycor

public void setPycor(int pycor)
Description copied from interface: IPatch
Set the patch's y coordinate.

Specified by:
setPycor in interface IPatch

aggregate

public void aggregate(double amount)
Description copied from interface: IPatch
Aggregate by keeping a count of the number of individuals of a given type of Patch.

Specified by:
aggregate in interface IPatch
Parameters:
amount - The amount to increment or decrement the current population count. The amount can be a positive (increment) or negative (decrement) number.

toString

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