|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--antsim.genie.GeneticCode
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.
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 |
public GeneticCode(boolean[] bits)
GeneticCode
object starting from a sequence
of bits maintained in a boolean array.
public GeneticCode(GeneticCode code)
GeneticCode
object starting from another
GeneticCode
object. Implements the semantics of
Cloneble
without incurring in interface implementation
and casting.
Method Detail |
public int size()
public boolean get(int i)
i
.
i
- the index of the bit to be readpublic int[] get(int[] sizes)
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.
sizes
- the array containing the sizes in bits of the
parameters to be read
IllegalArgumentException
- if the sum of sizes in the
specified array is not equal to the length of this genetic
code, as returned by size()
.public boolean equals(Object obj)
GeneticCode
is equal to the specified object.
equals
in class Object
public String toString()
toString
in class Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |