antsim.genie
Class GeneticCode

java.lang.Object
  |
  +--antsim.genie.GeneticCode

public final class GeneticCode
extends Object

For a nest, the genetic code of an ant is simply a sequence of bits. The exact interpretation of the sequence depends on the class of the ant being used. For this reason, class GeneticCode abstracts the basic operations that a nest is enabled to perform on a genetic code, which are (i) to read the contents of each bit in the code; (ii) to obtain the total size of the code; and (iii) to read the content of the sequence as a list of parameters.

For performance reasons, the class is final. Implementation note: the bits are currently maintained in an array of booleans. Alternative implementations could be based on integer array and bit-to-bit arithmetics, if they prove to be faster than this one.

Version:
$Revision: 1.1 $
Author:
Alberto Montresor

Constructor Summary
GeneticCode(boolean[] bits)
          Construct a new GeneticCode object starting from a sequence of bits maintained in a boolean array.
GeneticCode(GeneticCode code)
          Construct a new GeneticCode object starting from another GeneticCode object.
 
Method Summary
 boolean equals(Object obj)
          Check whether this GeneticCode is equal to the specified object.
 boolean get(int i)
          Returns the content of bit i.
 int[] get(int[] sizes)
          Read the content of this genetic code formattted as specified by the sizes array.
 int size()
          Returns the size of this genetic code.
 String toString()
          Returns a String containing this genetic code represented as a 0/1 string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneticCode

public GeneticCode(boolean[] bits)
Construct a new GeneticCode object starting from a sequence of bits maintained in a boolean array.


GeneticCode

public GeneticCode(GeneticCode code)
Construct a new GeneticCode object starting from another GeneticCode object. Implements the semantics of Cloneble without incurring in interface implementation and casting.

Method Detail

size

public int size()
Returns the size of this genetic code.


get

public boolean get(int i)
Returns the content of bit i.

Parameters:
i - the index of the bit to be read

get

public int[] get(int[] sizes)
Read the content of this genetic code formattted as specified by the sizes array. Argument sizes contains the size of each of the arguments in which the sequence of bits must be subdivided. For example, if sizes is equal to { 4, 8, 4 }, the first parameter takes the first four bits; the second parameter takes the next eight bits; and the last parameter takes the last four bits.

Parameters:
sizes - the array containing the sizes in bits of the parameters to be read
Returns:
an array of integers containing the read parameters
Throws:
IllegalArgumentException - if the sum of sizes in the specified array is not equal to the length of this genetic code, as returned by size().

equals

public boolean equals(Object obj)
Check whether this GeneticCode is equal to the specified object.

Overrides:
equals in class Object

toString

public String toString()
Returns a String containing this genetic code represented as a 0/1 string.

Overrides:
toString in class Object