org.vizzini.ai.geneticalgorithm
Class AbstractPopulation

java.lang.Object
  extended by org.vizzini.ai.geneticalgorithm.AbstractPopulation
All Implemented Interfaces:
IPopulation
Direct Known Subclasses:
DefaultPopulation

public abstract class AbstractPopulation
extends Object
implements IPopulation

Provides base functionality for a collection which holds IChromosome s.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Constructor Summary
AbstractPopulation(int capacity)
          Construct this object using the given parameter.
 
Method Summary
 void add(IChromosome chromosome)
          Add the given chromosome.
 void addAll(IPopulation population)
          Add all chromosomes from the given population to this.
 int capacity()
          Return the capacity of the population.
 void clearFitnesses()
          Clear the fitnesses of all members of the population.
 boolean contains(IChromosome chromosome)
          Return true if the given chromosome is a duplicate of one already in the population.
 boolean contains(IChromosome chromosome, int start, int end)
          Return true if the given chromosome is a duplicate of one already in the given range of the population.
 IChromosome first()
          Return the first chromosome.
 IChromosome get(int i)
          Return the chromosome at the given index.
 double getAverageFitness()
          Return the average fitness of all the chromosomes.
 int getMaxFitness()
           
 int getMinFitness()
           
 int getSumFitness()
          Return the sum of the chromosome's fitnesses.
 int indexOf(IChromosome chromosome)
          Return the index of the given chromosome.
 boolean isEmpty()
          Return true if this is empty.
 void resetAverageFitness()
          Reset the average fitness.
 void setFitnesses(int fitness)
          Set the fitnesses of all members of the population to the given value.
 void shuffle()
          Shuffle the chromosomes.
 int size()
          Return the current size of the population.
 void sort()
          Sort the chromosomes.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractPopulation

public AbstractPopulation(int capacity)
Construct this object using the given parameter.

Parameters:
capacity - Capacity of this population.
Since:
v0.3
Method Detail

add

public void add(IChromosome chromosome)
Add the given chromosome.

Specified by:
add in interface IPopulation
Parameters:
chromosome - Chromosome.
Since:
v0.3

addAll

public void addAll(IPopulation population)
Add all chromosomes from the given population to this.

Specified by:
addAll in interface IPopulation
Since:
v0.3

capacity

public int capacity()
Return the capacity of the population.

Specified by:
capacity in interface IPopulation
Since:
v0.3

clearFitnesses

public void clearFitnesses()
Clear the fitnesses of all members of the population.

Specified by:
clearFitnesses in interface IPopulation
Since:
v0.3

contains

public boolean contains(IChromosome chromosome)
Return true if the given chromosome is a duplicate of one already in the population.

Specified by:
contains in interface IPopulation
Parameters:
chromosome - Chromosome for which to search.
Since:
v0.3

contains

public boolean contains(IChromosome chromosome,
                        int start,
                        int end)
Return true if the given chromosome is a duplicate of one already in the given range of the population.

Specified by:
contains in interface IPopulation
Parameters:
chromosome - Chromosome for which to search.
start - Start index.
end - End index plus one.
Since:
v0.3

first

public IChromosome first()
Return the first chromosome.

Specified by:
first in interface IPopulation
Since:
v0.3

get

public IChromosome get(int i)
Return the chromosome at the given index.

Specified by:
get in interface IPopulation
Parameters:
i - Chromosome index.
Since:
v0.3

getAverageFitness

public double getAverageFitness()
Return the average fitness of all the chromosomes.

Specified by:
getAverageFitness in interface IPopulation
Since:
v0.3

getMaxFitness

public int getMaxFitness()
Specified by:
getMaxFitness in interface IPopulation
Returns:
Return maxFitness.
Since:
v0.3

getMinFitness

public int getMinFitness()
Specified by:
getMinFitness in interface IPopulation
Returns:
Return minFitness.
Since:
v0.3

getSumFitness

public int getSumFitness()
Return the sum of the chromosome's fitnesses.

Specified by:
getSumFitness in interface IPopulation
Since:
v0.3

indexOf

public int indexOf(IChromosome chromosome)
Return the index of the given chromosome.

Specified by:
indexOf in interface IPopulation
Since:
v0.3

isEmpty

public boolean isEmpty()
Return true if this is empty.

Specified by:
isEmpty in interface IPopulation
Since:
v0.3

resetAverageFitness

public void resetAverageFitness()
Reset the average fitness.

Specified by:
resetAverageFitness in interface IPopulation
Since:
v0.3

setFitnesses

public void setFitnesses(int fitness)
Set the fitnesses of all members of the population to the given value.

Specified by:
setFitnesses in interface IPopulation
Since:
v0.3

shuffle

public void shuffle()
Shuffle the chromosomes.

Specified by:
shuffle in interface IPopulation
Since:
v0.3

size

public int size()
Return the current size of the population.

Specified by:
size in interface IPopulation
Since:
v0.3

sort

public void sort()
Sort the chromosomes.

Specified by:
sort in interface IPopulation
Since:
v0.3

toString

public String toString()
Return a string representation of this object.

Specified by:
toString in interface IPopulation
Overrides:
toString in class Object
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02