physis.core.virtualmachine
Class SoupGeneticCodeTape

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

public class SoupGeneticCodeTape
extends java.lang.Object
implements GeneticCodeTape

All organisms share one large memory pool. This allows many interactions between them. (Tierra-like)


Field Summary
protected  int allocated_size
           
protected  boolean alreadyallocated
           
protected static byte[] attributes
          The attributes array for the memory pool.
protected  int child_loc
          The child's position.
protected  int child_size
          The child's size
private static InstructionSet instruction_set
           
protected  int loc
          The location of this codetape in the big pool.
protected static short[] pool
          This is the big memory pool.
protected  int size
          The size of the codetape.
 
Fields inherited from interface physis.core.virtualmachine.GeneticCodeTape
COPIED, EXECUTED, EXECUTED_OR_COPIED, MUTATED
 
Constructor Summary
(package private) SoupGeneticCodeTape(int loc_, int size_)
           
  SoupGeneticCodeTape(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 position to destination position.
 void delete()
          Removes an instruction from a random position.
 GeneticCodeTape divide()
          It divides the codetape.
 short fetchInst(int position)
          Simply returns the instruction or operand on the specified position.
 Genome getChildGenome()
          Returns the genetic information from the codetape.
protected  short getChildInstruction(int position)
           
 Genome getGenome()
          Returns the genetic information from the codetape.
 int getSize()
          Returns the absolute size of the codetape.(number of contained instructions)
 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 (are there enough copied instructions?).
 void mutate(int position)
          Mutate the specified instruction.
 short read(int position)
          It gives the instruction on the specified position.
 int searchBackward(int start, short code, int depth)
           
 int searchForward(int start, short code, int depth)
           
 void write(int position, short new_value)
          Sets the content of the tape on the specified position.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

instruction_set

private static InstructionSet instruction_set

pool

protected static short[] pool
This is the big memory pool. Only one could exist.

attributes

protected static byte[] attributes
The attributes array for the memory pool.

loc

protected int loc
The location of this codetape in the big pool. Pointer to the first instruction.

size

protected int size
The size of the codetape. The position of the last instruction: loc + size - 1.

allocated_size

protected int allocated_size

alreadyallocated

protected boolean alreadyallocated

child_loc

protected int child_loc
The child's position.

child_size

protected int child_size
The child's size
Constructor Detail

SoupGeneticCodeTape

public SoupGeneticCodeTape(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.

SoupGeneticCodeTape

SoupGeneticCodeTape(int loc_,
                    int size_)
Method Detail

read

public short read(int position)
It gives the instruction on the specified position. SIDE EFFECT!!! The executed flag is set!
Specified by:
read in interface CodeTape

fetchInst

public short fetchInst(int position)
Description copied from interface: GeneticCodeTape
Simply returns the instruction or operand on the specified position.
The position becomes EXECUTED.
This method isn't failsafe like read and write. The virtualmachine has to take care of the proper position. It provides only quick access for the executable part of the code.
Specified by:
fetchInst in interface GeneticCodeTape

write

public void write(int position,
                  short new_value)
Description copied from interface: CodeTape
Sets the content of the tape on the specified position. ALWAYS DOES SOMETHING! There shouldn't be any unhandled error situation!
Specified by:
write in interface CodeTape

clearExecutedFlag

public void clearExecutedFlag(int position)
Specified by:
clearExecutedFlag 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

allocate

public void allocate(int numberof_newcells)
Description copied from interface: GeneticCodeTape
It's a biological operator. This should happen before the cell division. (making room, preparating or something like that) CELL: It allocates instruction cells at the end of the codetape. One allocation may occur between divides. It also allocates the information arrays (iscopied...etc.) SOUP: Because of the one large memory pool (soup) there's no space allocation. In this case it's only the declaration of the size of the code block to be copied.
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()
Description copied from interface: GeneticCodeTape
Checks whether the organism is able to spawn (are there enough copied instructions?).
Specified by:
isProliferationPossible in interface GeneticCodeTape

divide

public GeneticCodeTape divide()
Description copied from interface: GeneticCodeTape
It divides the codetape. The Environment is responsible for palcing the child, the codetape only returns an other one.
Specified by:
divide in interface GeneticCodeTape

mutate

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

isMutated

public boolean isMutated(int position)
Description copied from interface: GeneticCodeTape
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

copy

public boolean copy(int source,
                    int destination)
Description copied from interface: GeneticCodeTape
Copies an instruction from source position to destination position. 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

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

getSize

public int getSize()
Description copied from interface: GeneticCodeTape
Returns the absolute size of the codetape.(number of contained instructions)
Specified by:
getSize in interface GeneticCodeTape

contains

public boolean contains(short instcode)
Description copied from interface: GeneticCodeTape
Returns true if the codetape contains the specified instruction.
Specified by:
contains in interface GeneticCodeTape
Following copied from interface: physis.core.virtualmachine.GeneticCodeTape
Parameters:
instcode - The searched instruction.

searchForward

public int searchForward(int start,
                         short code,
                         int depth)

searchBackward

public int searchBackward(int start,
                          short code,
                          int depth)

calculateEffectiveLength

public int calculateEffectiveLength()
The effective length can be calculated by the number of executed instructions.
Specified by:
calculateEffectiveLength 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

getChildInstruction

protected short getChildInstruction(int position)