DistributedEvolutionaryAlgorithmsFramework
Class Population

java.lang.Object
  extended by DistributedEvolutionaryAlgorithmsFramework.Population
All Implemented Interfaces:
java.lang.Comparable<Population>, java.lang.Iterable<Individual>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<Population>

public class Population
extends java.lang.Object
implements java.lang.Iterable<Individual>, org.apache.hadoop.io.WritableComparable<Population>

Population used in evolutionary algorithms


Nested Class Summary
static class Population.acceptImmigrantsMethod
          Determines how immigrating individuals are handled.
static class Population.expelEmigrantsMethod
          Determines how emigrating individuals are chosen.
 
Field Summary
 int dimensions
           
 
Constructor Summary
Population()
          Parameterless constructor
Population(java.util.ArrayList<Individual> population)
          Constructs Population with given Individuals
 
Method Summary
 void acceptImmigrants(Population immigrants, Population.acceptImmigrantsMethod method)
          Accepts immigrants into existing population.
 void add(Individual ind)
          Ads one Individual to population
 void clear()
          Clears Population by removing all Individuals
 Population clone()
           
 int compareTo(Population o)
           
 void drop(int i)
          Removes one Individual from Population with given index i
 double evaluateIndividual(Individual i)
           
 Individual get(int j)
           
 int getBestIndex()
          Get population index of the best Individual
static int getBestIndex(java.util.ArrayList<Individual> list)
          Get population index of the best Individual from ArrayList of Individuals.)
 Individual getBestIndividual()
           
 int getByIndex(int i)
          Get Individual by his population index
 Population getEmigrants(int nMigratingIndividuals, Population.expelEmigrantsMethod method)
          Expels immigrants from evolved population.
 int getKey()
           
 double getMaxRestriction(int i)
           
 boolean getMigratingFlag()
           
 double getMinRestriction(int i)
           
 java.util.ArrayList<Individual> getPopulation()
           
 java.util.Iterator<Individual> iterator()
           
 void randomize()
          Sets all Individuals to random values
 void readFields(java.io.DataInput in)
           
 void resetIndividualsPopulation()
          Set Individuals population to this Population.
 void set(int j, Individual ind)
          Sets one Individual with index j, rewriting the old one
 void setFitnessFunction(FitnessFunction ff)
          Sets fitness function of this Population which is later used to create Individuals and determine their fitness
 void setKey(int k)
          Each population has its unique key given by the framework at initialization by this function.
 void setMigratingFlag()
          Migrating flag marks if the population is used for evolution or for migration
 void setPopulation(java.util.ArrayList<Individual> individuals)
          Makes new Population from Individuals given in the individuals parameter
 int size()
           
 void sort()
          Sorts the population by fitness
 java.lang.String toString()
           
 void write(java.io.DataOutput out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dimensions

public int dimensions
Constructor Detail

Population

public Population(java.util.ArrayList<Individual> population)
Constructs Population with given Individuals

Parameters:
population - ArrayList of Individuals who will become the new Population

Population

public Population()
Parameterless constructor

Method Detail

getMinRestriction

public double getMinRestriction(int i)
Parameters:
i - Dimension from which the restriction is returned
Returns:
lower restriction of given dimension

getMaxRestriction

public double getMaxRestriction(int i)
Parameters:
i - Dimension from which the restriction is returned
Returns:
upper restriction of given dimension

randomize

public void randomize()
Sets all Individuals to random values


evaluateIndividual

public double evaluateIndividual(Individual i)
Parameters:
i - Individual to be evalueated
Returns:
fitness of the Individual

getPopulation

public java.util.ArrayList<Individual> getPopulation()
Returns:
ArrayList of Individuals from Population

setFitnessFunction

public void setFitnessFunction(FitnessFunction ff)
Sets fitness function of this Population which is later used to create Individuals and determine their fitness

Parameters:
ff - FitnessFunction extending class

resetIndividualsPopulation

public void resetIndividualsPopulation()
Set Individuals population to this Population. Needed after adding external Individuals.


setMigratingFlag

public void setMigratingFlag()
Migrating flag marks if the population is used for evolution or for migration


getMigratingFlag

public boolean getMigratingFlag()
Returns:
whether the population is used for migration

setKey

public void setKey(int k)
Each population has its unique key given by the framework at initialization by this function.

Parameters:
k - integer to set the key to.

getKey

public int getKey()
Returns:
the key (id) of the population

add

public void add(Individual ind)
Ads one Individual to population

Parameters:
ind - Individual to add

get

public Individual get(int j)
Parameters:
j - Index of Individual to return
Returns:
Individual with index j

set

public void set(int j,
                Individual ind)
Sets one Individual with index j, rewriting the old one

Parameters:
j - Index of new Individual
ind - Individual to be added

setPopulation

public void setPopulation(java.util.ArrayList<Individual> individuals)
Makes new Population from Individuals given in the individuals parameter

Parameters:
individuals - ArrayList of new Individuals

size

public int size()
Returns:
population size

drop

public void drop(int i)
Removes one Individual from Population with given index i

Parameters:
i - Index of removed Individual

clear

public void clear()
Clears Population by removing all Individuals


sort

public void sort()
Sorts the population by fitness


getBestIndex

public static int getBestIndex(java.util.ArrayList<Individual> list)
Get population index of the best Individual from ArrayList of Individuals.)

Parameters:
list - ArrayList of Individuals to search in.
Returns:
best Individual from given ArrayList

getBestIndividual

public Individual getBestIndividual()
Returns:
best individual of existing population.

acceptImmigrants

public void acceptImmigrants(Population immigrants,
                             Population.acceptImmigrantsMethod method)
Accepts immigrants into existing population.

Parameters:
immigrants - Immigrating Population
method - One of Population.acceptImmigrantsMethod (REPLACE_WORST, REPLACE_BEST, REPLACE_RANDOM, NO_REPLACE).
See Also:
Population.acceptImmigrantsMethod

getEmigrants

public Population getEmigrants(int nMigratingIndividuals,
                               Population.expelEmigrantsMethod method)
Expels immigrants from evolved population.

Parameters:
nMigratingIndividuals - Number of emigrants
method - One of Population.expelEmigrantsMethod (EXPEL_BEST, EXPEL_RANDOM).
See Also:
Population.expelEmigrantsMethod

getByIndex

public int getByIndex(int i)
Get Individual by his population index

Parameters:
i - Order of the Individual by fitness
Returns:
Index of Individual
See Also:
getBestIndex

clone

public Population clone()
Overrides:
clone in class java.lang.Object

iterator

public java.util.Iterator<Individual> iterator()
Specified by:
iterator in interface java.lang.Iterable<Individual>

write

public void write(java.io.DataOutput out)
           throws java.io.IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
java.io.IOException

readFields

public void readFields(java.io.DataInput in)
                throws java.io.IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
java.io.IOException

compareTo

public int compareTo(Population o)
Specified by:
compareTo in interface java.lang.Comparable<Population>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getBestIndex

public int getBestIndex()
Get population index of the best Individual

Returns: