physis.core.virtualmachine
Class CellGeneticCodeTape

java.lang.Object
  |
  +--physis.core.virtualmachine.CellGeneticCodeTape
All Implemented Interfaces:
CodeTape, GeneticCodeTape

public class CellGeneticCodeTape
extends java.lang.Object
implements GeneticCodeTape

Cell-like implementations of the genetic codetape. For each organism there's a separated cell. (Avida-like)


Field Summary
private  boolean alreadyallocated
          It's a flag which indicates whether an allocation has happened or not.
private  byte[] attributes
          Each byte represents the attributes of an instruction.
private static short blank_inst
           
private  short[] child
          When the organism is pregnant the child's code is being developed here.
private  byte[] childattributes
           
private static InstructionSet instruction_set
           
private  short[] memory
          The instructions are represented with a thin class called InstructionCode.
 
Fields inherited from interface physis.core.virtualmachine.GeneticCodeTape
COPIED, EXECUTED, EXECUTED_OR_COPIED, MUTATED
 
Constructor Summary
(package private) CellGeneticCodeTape(short[] instructions, byte[] attribs)
          Creates codetape from instructionarray.
  CellGeneticCodeTape(java.lang.String filename)
          It reads the instructions from a file.The first organism is created this way.(One instruction per line, lines beginning with # are discarded.
 
Method Summary
 void allocate(int numberof_newcells)
          It's a biological operator.
 boolean blockCopy(int source, int destination, int length)
          Copies an instruction from source position to destination position.
 int calculateEffectiveLength()
          The effective length can be calculated by the number of executed instructions.
 void clearExecutedFlag(int position)
           
 boolean contains(short instcode)
          Returns true if the codetape contains the specified instruction.
 boolean copy(int source, int destination)
          Copies an instruction from source cell to destination cell.
 void delete()
          Removes an instruction from a random position.
 GeneticCodeTape divide()
          It divides the codetape.
 short fetchInst(int position)
          Just returns the value without checking.
 Genome getChildGenome()
          Returns the genetic information from the codetape.
 Genome getGenome()
          Returns the genetic information from the codetape.
private  int getNumberOfCopiedInstructionsInChild()
           
static GeneticCodeTape getRandomTape(int length)
           
 int getSize()
          Returns the size of the codetape.
 void insert()
          Inserts an instruction on a random position.
 boolean isAllocated()
          Returns true if the cell already allocated space for the spawn.
 boolean isAllocationPossible(int numberof_newcells)
          The size must be in a predefined range, otherwise the allocation fails.
 boolean isCopied(int position)
          Answers the question: is the positionth instruction copied?
 boolean isExecuted(int position)
          Answers the question: is the positionth instruction executed?
 boolean isMutated(int position)
          Answers the question: is the positionth instruction mutated?
 boolean isProliferationPossible()
          Checks whether the organism is able to spawn.
 void mutate(int position)
          Mutate the specified instruction.
 short read(int position)
          It gives the instruction on the specified position.
 java.lang.String toString()
          Returns the string representation of the codetape.
 void write(int position, short new_value)
          The position is mapped into the proper range.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

instruction_set

private static InstructionSet instruction_set

blank_inst

private static short blank_inst

memory

private short[] memory
The instructions are represented with a thin class called InstructionCode. Due memory saving and performance considerations it stores only the instructioncode, and this code is available directly without method invocation.

child

private short[] child
When the organism is pregnant the child's code is being developed here.

alreadyallocated

private boolean alreadyallocated
It's a flag which indicates whether an allocation has happened or not.

attributes

private byte[] attributes
Each byte represents the attributes of an instruction. Each bit represents one attribute. (executed, copied, mutated..)

childattributes

private byte[] childattributes
Constructor Detail

CellGeneticCodeTape

public CellGeneticCodeTape(java.lang.String filename)
It reads the instructions from a file.The first organism is created this way.(One instruction per line, lines beginning with # are discarded.

CellGeneticCodeTape

CellGeneticCodeTape(short[] instructions,
                    byte[] attribs)
Creates codetape from instructionarray.
Method Detail

read

public short read(int position)
It gives the instruction on the specified position. If the index is out of bounds then it will be mapped into the proper range.
Specified by:
read in interface CodeTape

write

public void write(int position,
                  short new_value)
The position is mapped into the proper range.
Specified by:
write in interface CodeTape

fetchInst

public short fetchInst(int position)
Just returns the value without checking. SIDE EFFECT!!! The executed flag is set!
Specified by:
fetchInst in interface GeneticCodeTape

allocate

public void allocate(int numberof_newcells)
It's a biological operator. It allocates instruction cells at the end of the codetape. The size must be more than half and less than the current size, otherwise the allocation fails. One allocation may occur between divides.
It also allocates the information arrays (iscopied...etc.)
Specified by:
allocate in interface GeneticCodeTape

isAllocated

public boolean isAllocated()
Description copied from interface: GeneticCodeTape
Returns true if the cell already allocated space for the spawn.
Specified by:
isAllocated in interface GeneticCodeTape

isProliferationPossible

public boolean isProliferationPossible()
Checks whether the organism is able to spawn.
Specified by:
isProliferationPossible in interface GeneticCodeTape

isAllocationPossible

public boolean isAllocationPossible(int numberof_newcells)
Description copied from interface: GeneticCodeTape
The size must be in a predefined range, otherwise the allocation fails.
Specified by:
isAllocationPossible in interface GeneticCodeTape

divide

public GeneticCodeTape divide()
It divides the codetape.
Specified by:
divide in interface GeneticCodeTape

contains

public boolean contains(short instcode)
Returns true if the codetape contains the specified instruction.
Specified by:
contains in interface GeneticCodeTape
Parameters:
instcode - The searched instruction.

isMutated

public boolean isMutated(int position)
Answers the question: is the positionth instruction mutated?
Specified by:
isMutated in interface GeneticCodeTape

isCopied

public boolean isCopied(int position)
Description copied from interface: GeneticCodeTape
Answers the question: is the positionth instruction copied?
Specified by:
isCopied in interface GeneticCodeTape

isExecuted

public boolean isExecuted(int position)
Description copied from interface: GeneticCodeTape
Answers the question: is the positionth instruction executed?
Specified by:
isExecuted in interface GeneticCodeTape

clearExecutedFlag

public void clearExecutedFlag(int position)
Specified by:
clearExecutedFlag in interface GeneticCodeTape

mutate

public void mutate(int position)
Mutate the specified instruction.
Specified by:
mutate in interface GeneticCodeTape

insert

public void insert()
Inserts an instruction on a random position.
Specified by:
insert in interface GeneticCodeTape

delete

public void delete()
Removes an instruction from a random position.
Specified by:
delete in interface GeneticCodeTape

copy

public boolean copy(int source,
                    int destination)
Copies an instruction from source cell to destination cell. Returns true if the copy was succesfull.
Specified by:
copy in interface GeneticCodeTape

blockCopy

public boolean blockCopy(int source,
                         int destination,
                         int length)
Description copied from interface: GeneticCodeTape
Copies an instruction from source position to destination position. Returns true if the copy was succesfull.
Specified by:
blockCopy in interface GeneticCodeTape

calculateEffectiveLength

public int calculateEffectiveLength()
The effective length can be calculated by the number of executed instructions.
Specified by:
calculateEffectiveLength in interface GeneticCodeTape

getSize

public int getSize()
Returns the size of the codetape.
Specified by:
getSize in interface GeneticCodeTape

getGenome

public Genome getGenome()
Returns the genetic information from the codetape.
Specified by:
getGenome in interface GeneticCodeTape

getChildGenome

public Genome getChildGenome()
Returns the genetic information from the codetape.
Specified by:
getChildGenome in interface GeneticCodeTape

getRandomTape

public static GeneticCodeTape getRandomTape(int length)

toString

public java.lang.String toString()
Returns the string representation of the codetape. One instruction per line.
Overrides:
toString in class java.lang.Object

getNumberOfCopiedInstructionsInChild

private int getNumberOfCopiedInstructionsInChild()