s373.dna
Class DNA

java.lang.Object
  extended by s373.dna.DNA

public class DNA
extends Object


Field Summary
 float[] dna
           
 int num
           
 
Constructor Summary
DNA()
          DNA() empty constructor returns one DNA object with one Gene.
DNA(DNA d)
          DNA(DNA d) constructs one DNA object with contents of DNA d.
DNA(DNA d, float dev)
          DNA(DNA d) constructs one DNA object with contents of DNA d +- random(dev).
DNA(float[] data)
          DNA(float data[]) constructs one DNA object with contents of data.
DNA(int num)
          DNA(int num) returns one DNA object with num Genes.
 
Method Summary
 float difference(DNA dnatarget)
          return the absolute difference value to another DNA
 float[] differenceDNA(DNA dnatarget)
          return the absolute difference gene array to another DNA
 float differenceGene(int gene, DNA dnatarget)
          return the absolute difference gene to another DNA's gene.
 float fitness(DNA dnatarget)
          evaluate the fitness of this DNA regarding a dnatarget.
 int getBoundsMode()
          get DNA boundsMode
 float[] getDna()
          Get dna float array
 float getGene(int n)
          get Gene value index n
 int getMateMode()
          get DNA mateMode
 int getNum()
          return number of genes in DNA
 DNA mate(DNA another)
          mate this DNA with other DNA according to its mateMode.
 DNA mate(DNA another, float param)
          mate this DNA with other DNA according to its mateMode with param.
 DNA mutate(float a)
          mutate DNA with probability a.
 DNA mutate(float a, float b)
          mutate DNA with probability a and deviation b.
 DNA mutateGene(int gene, float dev)
          mutate gene
 void print()
           
 void printDna()
           
 float random(float max)
          return a random number up to max
 float random(float min, float max)
          return a random number between min and max.
 DNA setBoundsMode(int boundsMode)
          set DNA boundsMode
 DNA setDna(DNA d)
           
 DNA setDna(float[] data)
           
 DNA setGene(int n, float val)
          set Gene index n with value val
 DNA setMateMode(int mateMode)
          set DNA mateMode
 DNA setNum(int n)
          set num genes
 DNA setRandomDNA()
          set Random vals on all genes
 int size()
          return number of genes in DNA
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dna

public float[] dna

num

public int num
Constructor Detail

DNA

public DNA()
DNA() empty constructor returns one DNA object with one Gene.


DNA

public DNA(int num)
DNA(int num) returns one DNA object with num Genes.

Parameters:
num -

DNA

public DNA(float[] data)
DNA(float data[]) constructs one DNA object with contents of data.

Parameters:
num -

DNA

public DNA(DNA d)
DNA(DNA d) constructs one DNA object with contents of DNA d.

Parameters:
d -

DNA

public DNA(DNA d,
           float dev)
DNA(DNA d) constructs one DNA object with contents of DNA d +- random(dev).

Parameters:
d, - dev
Method Detail

setNum

public DNA setNum(int n)
set num genes

Parameters:
n -
Returns:

getNum

public int getNum()
return number of genes in DNA

Returns:
num

size

public int size()
return number of genes in DNA

Returns:
num

setDna

public DNA setDna(DNA d)
Parameters:
dna -
Returns:

setDna

public DNA setDna(float[] data)
Parameters:
data -
Returns:

getDna

public float[] getDna()
Get dna float array

Returns:
dna float[]

getGene

public float getGene(int n)
get Gene value index n

Parameters:
n -
Returns:

setGene

public DNA setGene(int n,
                   float val)
set Gene index n with value val

Parameters:
n -
val -
Returns:

setRandomDNA

public DNA setRandomDNA()
set Random vals on all genes

Returns:

mutate

public DNA mutate(float a)
mutate DNA with probability a. each gene is tested for probability, if true, its value is randomized.

Parameters:
a -
Returns:

mutate

public DNA mutate(float a,
                  float b)
mutate DNA with probability a and deviation b. each gene is tested for probability, if true, its value is deviated b amount.

Parameters:
a -
b -
Returns:

mate

public DNA mate(DNA another)
mate this DNA with other DNA according to its mateMode.

Parameters:
another -
Returns:

mate

public DNA mate(DNA another,
                float param)
mate this DNA with other DNA according to its mateMode with param.

Parameters:
another -
param -
Returns:

mutateGene

public DNA mutateGene(int gene,
                      float dev)
mutate gene

Parameters:
gene -
dev -
Returns:
this

difference

public float difference(DNA dnatarget)
return the absolute difference value to another DNA

Parameters:
dnatarget -
Returns:

differenceDNA

public float[] differenceDNA(DNA dnatarget)
return the absolute difference gene array to another DNA

Parameters:
dnatarget -
Returns:
float[]

differenceGene

public float differenceGene(int gene,
                            DNA dnatarget)
return the absolute difference gene to another DNA's gene.

Parameters:
gene -
dnatarget -
Returns:

fitness

public float fitness(DNA dnatarget)
evaluate the fitness of this DNA regarding a dnatarget.

Parameters:
dnatarget -
Returns:

print

public void print()

printDna

public void printDna()

toString

public String toString()
Overrides:
toString in class Object

setMateMode

public DNA setMateMode(int mateMode)
set DNA mateMode

Parameters:
mateMode -
Returns:

getMateMode

public int getMateMode()
get DNA mateMode

Returns:

setBoundsMode

public DNA setBoundsMode(int boundsMode)
set DNA boundsMode

Parameters:
boundsMode -
Returns:

getBoundsMode

public int getBoundsMode()
get DNA boundsMode

Returns:

random

public float random(float max)
return a random number up to max

Parameters:
max -
Returns:

random

public float random(float min,
                    float max)
return a random number between min and max.

Parameters:
min -
max -
Returns:


Processing library dna by Andre Sier. (C) 2010