lio.individuals
Class BitChain

java.lang.Object
  extended by lio.individuals.Individual
      extended by lio.individuals.BitChain
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class BitChain
extends Individual

This class implements those individuals coded with a chain of bits.


Field Summary
 
Fields inherited from class lio.individuals.Individual
evaluated, maxSize, size, value
 
Constructor Summary
BitChain(BitChain oldBitChain)
          Create a new instance of BitChain from another object
BitChain(int pSize)
          Creates a new instance (full of 0s) with the specified size.
BitChain(int[] pChain)
          Creates a new instance of BitChain from an array of integers.
 
Method Summary
 java.lang.Object clone()
          Clones an individual.
 int get(int pos)
          Returns the value stored in position pos.
 int[] getCopyOfElements()
          Returns a copy of the elements which form the individual.
 int[] getElements()
          Returns a reference to the elements which form the individual.
static BitChain[] intToIndividual(int[][] pSample)
          Static method which allows building an array of individuals from a matrix of integer.
 void set(int pos, int value)
          Fixes element value in this position.
 void setElements(int[] elements)
          Sets the elements of a individual from an array of integer.
 java.lang.String toString()
          String representation of the individual.
 
Methods inherited from class lio.individuals.Individual
change, compareTo, getMaxSize, getSize, isEvaluated, setMaxSize, setSize, setValue, value
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitChain

public BitChain(int[] pChain)
Creates a new instance of BitChain from an array of integers.

Parameters:
pChain - chain of bits that represents the individual.

BitChain

public BitChain(int pSize)
Creates a new instance (full of 0s) with the specified size.


BitChain

public BitChain(BitChain oldBitChain)
Create a new instance of BitChain from another object

Parameters:
oldBitChain - object from which values are taken
Method Detail

getCopyOfElements

public int[] getCopyOfElements()
Returns a copy of the elements which form the individual.

Returns:
A vector containing the elements of the individual.

getElements

public int[] getElements()
Returns a reference to the elements which form the individual.

Returns:
A vector containing the elements of the individual.

setElements

public void setElements(int[] elements)
Sets the elements of a individual from an array of integer.

Parameters:
elements - Array of integers that code the individual.

get

public int get(int pos)
Returns the value stored in position pos.

Parameters:
pos - Position whose value is required.
Returns:
Value in the position pos.

set

public void set(int pos,
                int value)
Fixes element value in this position.

Parameters:
pos - Position whose value must be changed.
value - for this position.

toString

public java.lang.String toString()
String representation of the individual.

Specified by:
toString in class Individual
Returns:
A string representing the individual.

clone

public java.lang.Object clone()
Description copied from class: Individual
Clones an individual. It allows to copy individuals instead of references.

Specified by:
clone in class Individual
Returns:
an object similar to this.

intToIndividual

public static BitChain[] intToIndividual(int[][] pSample)
Static method which allows building an array of individuals from a matrix of integer.

Parameters:
pSample - Two dimension matrix containing the values for the individuals.
Returns:
An array of BitChain each one of them built from one of the arrays.