com.groovyj.jgprog
Class Individual

java.lang.Object
  |
  +--com.groovyj.jgprog.Individual
All Implemented Interfaces:
java.io.Serializable

public class Individual
extends java.lang.Object
implements java.io.Serializable

Represents a single individual.

Copyright (c) 2000 Robert Baruch. This code is released under the GNU General Public License (GPL).

Version:
$Id: Individual.java,v 1.4 2000/10/12 15:22:55 groovyjava Exp $
Author:
Robert Baruch (jgprog@sourceforge.net)
See Also:
Serialized Form

Constructor Summary
Individual(int numChromosomes)
          Constructs an empty individual with a number of chromosomes.
 
Method Summary
static Individual dupChromosome(Individual i1)
          Causes a chromosome to duplicate itself in a new individual.
 boolean execute_boolean(int chromosomeNum)
          Executes the given chromosome as a boolean function.
 double execute_double(int chromosomeNum)
          Executes the given chromosome as a double function.
 float execute_float(int chromosomeNum)
          Executes the given chromosome as a float function.
 int execute_int(int chromosomeNum)
          Executes the given chromosome as an integer function.
 long execute_long(int chromosomeNum)
          Executes the given chromosome as a long function.
 java.lang.Object execute_object(int chromosomeNum)
          Executes the given chromosome as an object function.
 void execute_void(int chromosomeNum)
          Executes the given chromosome which returns nothing.
 void full(int depth, Type[] types, Type[][] argTypes, Function[][] nodeSets)
          Initializes all chromosomes in this individual using the full method.
 Chromosome getChromosome(int num)
          Gets the given chromosome.
 float getFitness()
          Gets the adjusted fitness of this individual.
 int getSequence()
           
 void grow(int depth, Type[] types, Type[][] argTypes, Function[][] nodeSets)
          Initializes all chromosomes in this individual using the grow method.
 void setFitness(float f)
          Sets the adjusted fitness of this individual.
 java.lang.String toString()
          Returns a string representing this individual.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Individual

public Individual(int numChromosomes)
Constructs an empty individual with a number of chromosomes.

Parameters:
numChromosomes - the number of chromosomes this individual has
Since:
1.0
Method Detail

getChromosome

public Chromosome getChromosome(int num)
Gets the given chromosome.

Parameters:
num - the chromosome number, 0 to number of chromosomes-1
Returns:
the chromosome
Since:
1.0

grow

public void grow(int depth,
                 Type[] types,
                 Type[][] argTypes,
                 Function[][] nodeSets)
Initializes all chromosomes in this individual using the grow method.

Parameters:
types - the type of each chromosome, must be an array of the same length as the number of chromosomes
argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome.
nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes. Note that it is not necessary to include the arguments of a chromosome as terminals in the chromosome's node set. This is done automatically for you.
Since:
1.0

full

public void full(int depth,
                 Type[] types,
                 Type[][] argTypes,
                 Function[][] nodeSets)
Initializes all chromosomes in this individual using the full method.

Parameters:
types - the type of each chromosome, must be an array of the same length as the number of chromosomes
argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome.
nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes. Note that it is not necessary to include the arguments of a chromosome as terminals in the chromosome's node set. This is done automatically for you.
Since:
1.0

dupChromosome

public static Individual dupChromosome(Individual i1)
Causes a chromosome to duplicate itself in a new individual. If duplicating a chromosome would cause the maximum number of chromosomes to be exceeded, the individual returned will be the same as the original.

Parameters:
i1 - the individual in which to duplicate the chromosome
Returns:
the new individual with a duplicated chromosome

execute_boolean

public boolean execute_boolean(int chromosomeNum)
Executes the given chromosome as a boolean function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the boolean return value
Since:
1.0

execute_void

public void execute_void(int chromosomeNum)
Executes the given chromosome which returns nothing.
Parameters:
chromosomeNum - the chromosome to execute
Since:
1.0

execute_int

public int execute_int(int chromosomeNum)
Executes the given chromosome as an integer function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the integer return value
Since:
1.0

execute_object

public java.lang.Object execute_object(int chromosomeNum)
Executes the given chromosome as an object function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the object return value
Since:
1.0

execute_long

public long execute_long(int chromosomeNum)
Executes the given chromosome as a long function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the long return value
Since:
1.0

execute_float

public float execute_float(int chromosomeNum)
Executes the given chromosome as a float function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the float return value
Since:
1.0

execute_double

public double execute_double(int chromosomeNum)
Executes the given chromosome as a double function.
Parameters:
chromosomeNum - the chromosome to execute
Returns:
the boolean double value
Since:
1.0

getFitness

public float getFitness()
Gets the adjusted fitness of this individual. The fitness must have already been evaluated by a World.
Returns:
the adjusted fitness
Since:
1.0

setFitness

public void setFitness(float f)
Sets the adjusted fitness of this individual.
Parameters:
f - the adjusted fitness
Since:
1.0

toString

public java.lang.String toString()
Returns a string representing this individual. The format of the string is a set of lines, each line representing one chromosome. The format of each line is [chromosomeNum] (string representation of the chromosome).
Overrides:
toString in class java.lang.Object
Returns:
the string representing this individual
Since:
1.0

getSequence

public int getSequence()