T
- The class of chromosomes individuals are made of.public final class Population<T extends Chromosome> extends java.lang.Object implements java.lang.Iterable<Individual<T>>
Individual
s.
An important property of a population is its size, that is the number of individuals it contains.
The DEFAULT_SIZE
constant is used as default if the size is not specified.
Population.Statistics
collects statistics regarding the population.
Statistics can be accessed by the getStatistics()
method and updated by the
updateStatistics(jenes.population.Population.Statistics)
.
Individual
,
Population.Statistics
Modifier and Type | Class and Description |
---|---|
static interface |
Population.Filter
The interface provides a method to create filters on individuals
|
static class |
Population.Pareto<K extends Chromosome>
This class represents a Pareto front for a multi objective solution
|
static class |
Population.Statistics<T extends Chromosome>
The
Population.Statistics class is only responsible for storing statistics
about a population. |
Modifier and Type | Field and Description |
---|---|
static Population.Filter |
ALL
Filter that passes all individuals
|
static Population.Filter |
BEST
Filter that passes the best individuals
|
static int |
DEFAULT_SIZE
The default population size
|
static Population.Filter |
ILLEGALS
Filter that passes all illegals individuals
|
static Population.Filter |
LEGALS
Filter that passes all legals individuals
|
Constructor and Description |
---|
Population()
Constructs a new empty population
|
Population(Individual<T> sample)
Constructs a new population by cloning the individual sample.
|
Population(Individual<T> sample,
int size)
Constructs a new population by cloning the individual sample
and specifying the initial size.
|
Population(java.util.List<Individual<T>> individuals)
Constructs a new population with the specified list of individuals
|
Population(Population<T> population)
Constructs a new population from the specified one with the same size
|
Modifier and Type | Method and Description |
---|---|
void |
add(Individual<T> individual)
Adds an individual at the end of this population.
|
void |
add(Individual<T>[] individuals)
Adds multiple individuals at the end of this population.
|
void |
add(java.util.List<Individual<T>> individuals)
Adds the list of individuals at the end of this population.
|
void |
add(Population<T> pop)
Adds all the individuals contained by the specified population at this
population.
|
void |
clear()
Removes all the individuals from this population.
|
int |
getAge()
Returns the age of this population
|
java.util.List<Individual<T>> |
getAllLegalIndividuals()
Deprecated.
|
double[][] |
getAllScores()
Returns an array with all scores of all the individuals held by
this population.
|
static Pool<?> |
getDefaultPool()
Returns the default pool
|
Fitness<T> |
getEvaluatedBy()
Return the genetic algorithm that has evaluated this population.
|
Individual<T> |
getIndividual(int index)
Returns the individual at the specified position.
|
java.util.List<Individual<T>> |
getIndividuals()
Returns the (cloned) list of individuals
|
Population.Pareto |
getPareto()
Return
Population.Pareto of this population |
Pool<T> |
getPool()
Returns the
Pool of this population |
double[] |
getScores(int objIndex)
Returns an array with all scores for a specific objective of all the individuals held by
this population.
|
boolean[] |
getSortedBy()
Return the sort criteria
|
Population.Statistics |
getStatistics()
Returns a
Population.Statistics of this population |
Population.Statistics |
getStatistics(boolean collectable)
Returns a Statistics of this population
|
boolean |
hasLegals()
Checks if the population has legal individuals
|
void |
invalidate()
Invalidates the population by setting as not evaluated its individuals.
|
boolean |
isEmpty()
Tests if this population is empty.
|
boolean |
isSorted()
Check if the individuals order has been evaluated
|
java.util.Iterator<Individual<T>> |
iterator()
Returns an interator related the individuals of this population.
|
java.util.Iterator<Individual<T>> |
iterator(int speciem)
Returns a new
Iterator of Individual that belong to a specific speciem. |
java.util.Iterator<Individual<T>> |
iterator(Population.Filter filter)
|
Individual<T> |
remove(int index)
Removes the specified individual from this population.
|
Individual<T> |
replace(int index,
Individual<T> individual)
Replaces the individual at the specified position with the specified
individual.
|
void |
reset(java.util.List<Individual> list,
boolean sorted)
Reset the individuals belonging to this population
|
void |
resize(int size)
Resizes the current population.
|
void |
resizeAs(Population<T> population)
Resizes the current population.
|
void |
setAs(Population<T> pop)
Sets this population as the specified one.
|
static void |
setDefaultPool(Pool<?> pool)
Sets the default poll
|
void |
setEvaluatedBy(Fitness fitness)
Specify the fitness that has scored population
|
Individual<T> |
setIndividual(Individual<T> individual,
int index)
Deprecated.
|
void |
setIndividualAs(int k,
Individual<T> individual)
Sets the
Individual at the specified position equal
to the specified one
|
void |
setPool(Pool<T> pool)
Sets the
Pool for this population. |
void |
setSortingBy(boolean... bib)
Specify the bigger is better
|
int |
size()
Returns the population size.
|
void |
sort(boolean... bis)
Sorts the individuals of this population in descending order, from highest to lowest score.
|
void |
swap(Population<T> pop)
Swaps this population with the speficied one; the age and the individuals will be swapped
by this operation.
|
java.lang.String |
toCompleteString()
Returns a string complete representation of this population.
|
java.lang.String |
toString()
Returns a string representation of this population.
|
void |
trimToSize()
Trims the capacity of this Population instance to be the
list's current size.
|
void |
updateStatistics(Population.Statistics statistics)
Sets the specified statistics according to the statistics of this population
|
public static final int DEFAULT_SIZE
public static final Population.Filter ALL
public static final Population.Filter LEGALS
public static final Population.Filter ILLEGALS
public static final Population.Filter BEST
public Population()
public Population(Population<T> population)
population
- the population used as samplepublic Population(java.util.List<Individual<T>> individuals)
individuals
- the list to be used in the population creationpublic Population(Individual<T> sample)
sample
- the individual samplepublic Population(Individual<T> sample, int size)
sample
- the individual samplesize
- the length populationpublic boolean isSorted()
public final void setEvaluatedBy(Fitness fitness)
fitness
- public final void setSortingBy(boolean... bib)
bib
- public final Fitness<T> getEvaluatedBy()
public boolean[] getSortedBy()
public final Pool<T> getPool()
Pool
of this populationpublic final void setPool(Pool<T> pool)
Pool
for this population. Remove all individuals from old
pool and adds them to new poolpool
- the new pool for this populationpublic final java.util.Iterator<Individual<T>> iterator()
iterator
in interface java.lang.Iterable<Individual<T extends Chromosome>>
public final java.util.Iterator<Individual<T>> iterator(int speciem)
Iterator
of Individual
that belong to a specific speciem.speciem
- speciem of individualspublic final java.util.Iterator<Individual<T>> iterator(Population.Filter filter)
filter
- Filter objectpublic final int getAge()
public final void setAs(Population<T> pop)
pop
- the model populationpublic final void swap(Population<T> pop)
pop
- the other population with witch make the individuals swappublic final void add(Individual<T> individual)
individual
- the individual to add.public final void add(Individual<T>[] individuals)
individuals
- the individuals to be addedpublic final void add(java.util.List<Individual<T>> individuals)
individuals
- the list of individuals to addpublic final void add(Population<T> pop)
pop
- the population to add.public final void resize(int size)
size
- the population new sizepublic final void resizeAs(Population<T> population)
population
- the Population to get the size frompublic final Individual<T> remove(int index)
index
- the individual to remove.public final void clear()
public final void trimToSize()
public final void reset(java.util.List<Individual> list, boolean sorted)
list
- list of new individualssorted
- flag indicating if the new individuals are sortedpublic final void setIndividualAs(int k, Individual<T> individual)
Individual
at the specified position equal
to the specified one
k
- the position of the individual to be modifyindividual
- the Individual modelpublic final Individual<T> getIndividual(int index)
index
- the index of the desired individual.public final Individual<T> setIndividual(Individual<T> individual, int index)
individual
- index
- index of individual to replace.replace(int, jenes.population.Individual)
public final double[][] getAllScores()
public final double[] getScores(int objIndex)
objIndex
- index of objective0
@Deprecated public final java.util.List<Individual<T>> getAllLegalIndividuals()
public final boolean hasLegals()
public final boolean isEmpty()
true
if this population is empty; false
otherwise.public final int size()
public final Individual<T> replace(int index, Individual<T> individual)
index
- the position of the individual to replace.individual
- the replacing individual.public final java.lang.String toCompleteString()
public final java.lang.String toString()
toString
in class java.lang.Object
public final void sort(boolean... bis)
public final Population.Statistics getStatistics(boolean collectable)
public final Population.Statistics getStatistics()
Population.Statistics
of this populationpublic final Population.Pareto getPareto()
Population.Pareto
of this populationpublic final void updateStatistics(Population.Statistics statistics)
statistics
- the statistics to be setpublic final java.util.List<Individual<T>> getIndividuals()
public final void invalidate()
public static Pool<?> getDefaultPool()
public static void setDefaultPool(Pool<?> pool)
pool
- new pool