public abstract class Fitness<C extends Chromosome>
extends java.lang.Object
implements java.lang.Cloneable
Socring of individuals is obtained by implementing the abstract method evaluate
.
The class supports multi-objective optimizazion, so that a vector of scores can be associated to each individual.
Flags have to be given at construction. Each flag should be true if the related objective is to maximize, otherwise false.
Sorting is performed according to objectives, so that better individuals come first. In order to keep sorting efficient, there are
four modes, namely PARTIAL
, HIERACHICAL
, DOMINANCE
, and CROWDING
.
In PARTIAL
mode, sorting is perfomed using only the first objective.
HIERARCHICAL
mode considers objectives in sequence.
DOMINANCE
is used to sort individuals according to dominance.
CROWDING
sorts elements by dominance first, and by crowding distance after, as suggested by Deb for NSGA2.
Cloning is necessary for multithreading.
Modifier and Type | Class and Description |
---|---|
static class |
Fitness.SortingMode
Sorting modes
|
Constructor and Description |
---|
Fitness(boolean... bis)
Creates a new fitness where the number of objectives is derived by the
lenght of array given as argument.
|
Fitness(int m,
boolean maximize)
Creates a new fitness with the defined number of objectives imposing all
to maximize or minimize solutions.
|
Modifier and Type | Method and Description |
---|---|
void |
adjust(Population<C> pop,
Individual<C>[] elite)
Adjust the evaluation after elistim is applied.
|
Fitness<C> |
clone() |
static int |
dominance(Individual<?> i1,
Individual<?> i2,
boolean... bis)
Returns a positive, negative or zero value according to dominance relation between individuals i1 and i2, given the objective flag array.
|
int |
dominance(Individual<C> i1,
Individual<C> i2)
Returns a positive, negative or zero value according to dominance relation between individuals i1 and i2
|
static boolean |
dominates(Individual<?> i1,
Individual<?> i2,
boolean... bis)
Checks if individuals i1 dominates i2.
|
boolean |
dominates(Individual<C> i1,
Individual<C> i2)
Checks if individuals i1 dominates i2.
|
protected Fitness<C> |
duplicate()
Builds a copy instance.
|
abstract void |
evaluate(Individual<C> individual)
Evaluates a single
Individual . |
boolean[] |
getBiggerIsBetter()
Returns the objective flag array.
|
int |
getNumOfObjectives()
Returns the number of objectives
|
void |
init(Individual<C> ind)
Initializes the
Individual given as parameter by resetting its scores. |
void |
init(Population<C> pop)
Initializes the
Population given as parameter by resetting the
scores of all individuals. |
void |
partialsort(java.util.List<Individual<C>> list,
int dim)
Sorts the list of
Individual given as argument. |
static <K extends Chromosome> |
partialsort(java.util.List<Individual<K>> list,
int dim,
boolean bib)
Sorts the list of
Individual given as argument. |
void |
prepare(Population<C> pop)
Prepares the evaluation.
|
Fitness.SortingMode |
setSortingMode(Fitness.SortingMode sortingMode)
Sets the
Fitness.SortingMode of Population
|
void |
sort(Fitness.SortingMode mode,
java.util.List<Individual<C>> list)
Sorts the list of individuals given as argument using the
Fitness.SortingMode
given as argument
|
static <K extends Chromosome> |
sort(Fitness.SortingMode sortingMode,
java.util.List<Individual<K>> list,
boolean... bis)
Sorts the list given as argument using the
Fitness.SortingMode
and the array given as arguments. |
void |
sort(Fitness.SortingMode mode,
Population<C> pop)
Sorts the
Population given as argument using the Fitness.SortingMode
given as argument
|
static <K extends Chromosome> |
sort(Fitness.SortingMode sortingMode,
Population<K> pop,
boolean... bis)
Sorts the
Population given as argument using the Fitness.SortingMode
and the array given as arguments. |
void |
sort(java.util.List<Individual<C>> list)
Sorts the list of individuals given as argument
|
static <K extends Chromosome> |
sort(java.util.List<Individual<K>> list,
boolean... bis)
Sorts the list given as argument using the array given as
argument.
|
void |
sort(Population<C> pop)
Sorts the
Population given as argument
|
static <K extends Chromosome> |
sort(Population<K> pop,
boolean... bis)
Sorts the
Population given as argument using the array given as
argument. |
public Fitness(int m, boolean maximize)
m
- numbers of objectivemaximize
- when true
the algorithm will find solution
with maximum score; false
otherwisepublic Fitness(boolean... bis)
bis
- a boolean array. When a cell contains a true
value the algorithm will find solution with maximum score;
false
otherwiseprotected Fitness<C> duplicate() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public abstract void evaluate(Individual<C> individual)
Individual
. This evaluation of individuals is
specifically related to the problem to solve.
individual
- the individual to be evaluatedpublic void prepare(Population<C> pop)
pop
- population to evaluate.public void adjust(Population<C> pop, Individual<C>[] elite)
pop
- population to evaluate.elite
- individuals entered because of elitismpublic void init(Individual<C> ind)
Individual
given as parameter by resetting its scores.
ind
- individual to be initializepublic void init(Population<C> pop)
Population
given as parameter by resetting the
scores of all individuals.
pop
- population to initializepublic final Fitness.SortingMode setSortingMode(Fitness.SortingMode sortingMode)
Fitness.SortingMode
of Population
sortingMode
- sorting modepublic final void sort(Population<C> pop)
Population
given as argument
pop
- population to be sortedpublic final void sort(Fitness.SortingMode mode, Population<C> pop)
Population
given as argument using the Fitness.SortingMode
given as argument
mode
- sorting modepop
- population to be sortedpublic final void sort(java.util.List<Individual<C>> list)
list
- list of individual to be sortedpublic final void sort(Fitness.SortingMode mode, java.util.List<Individual<C>> list)
Fitness.SortingMode
given as argument
mode
- sorting modelist
- list of individual to be sortedpublic static <K extends Chromosome> void sort(Population<K> pop, boolean... bis)
Population
given as argument using the array given as
argument. Each cell of array represent a flag for maximize or minimize
that objective
pop
- population to be sortedbis
- a boolean array. Each cell contains a true
if the corresponding score to be maximized; false
otherwisepublic static <K extends Chromosome> void sort(Fitness.SortingMode sortingMode, Population<K> pop, boolean... bis)
Population
given as argument using the Fitness.SortingMode
and the array given as arguments. Each cell of array represent a flag for
maximize or minimize that objective
sortingMode
- sorting modepop
- population to be sortedbis
- a boolean array. Each cell contains a true
if the corresponding score to be maximized; false
otherwisepublic static <K extends Chromosome> void sort(java.util.List<Individual<K>> list, boolean... bis)
pop
- population to be sortedbis
- a boolean array. Each cell contains a true
if the corresponding score to be maximized; false
otherwisepublic static <K extends Chromosome> void sort(Fitness.SortingMode sortingMode, java.util.List<Individual<K>> list, boolean... bis)
Fitness.SortingMode
and the array given as arguments. Each cell of array represent a flag for
maximize or minimize that objectivesortingMode
- sorting modepop
- population to be sortedbis
- a boolean array. Each cell contains a true
if the corresponding score to be maximized; false
otherwisepublic final void partialsort(java.util.List<Individual<C>> list, int dim)
Individual
given as argument. Individuals are
sorted by score in position dim
.list
- list to be ordereddim
- index score to sortpublic static <K extends Chromosome> void partialsort(java.util.List<Individual<K>> list, int dim, boolean bib)
Individual
given as argument. Individuals are
sorted by score in position dim
. Sort direction is set by
bib
K
- extends Chromosomelist
- list to be ordereddim
- index score to sortbib
- Sorting is ascending if bib
is
true
; sorting is descending if bib
is
false
public final int getNumOfObjectives()
public final boolean[] getBiggerIsBetter()
public final int dominance(Individual<C> i1, Individual<C> i2)
i1
- individuali2
- individualpublic boolean dominates(Individual<C> i1, Individual<C> i2)
i1
- individuali2
- individualpublic static int dominance(Individual<?> i1, Individual<?> i2, boolean... bis)
i1
- individuali2
- individualbis
- objective flag arraypublic static boolean dominates(Individual<?> i1, Individual<?> i2, boolean... bis)
i1
- individuali2
- individualbis
- objective flag array