public abstract class GeneticAlgorithm<T extends Chromosome> extends Object implements SearchAlgorithm, Serializable
| Modifier and Type | Field and Description |
|---|---|
protected Archive<T> |
archive |
protected Set<BloatControlFunction> |
bloatControl
Bloat control, to avoid too long chromosomes
|
protected ChromosomeFactory<T> |
chromosomeFactory
Generator for initial population
|
protected CrossOverFunction |
crossoverFunction
CrossOver function
|
protected int |
currentIteration
Age of the population
|
protected List<FitnessFunction<T>> |
fitnessFunctions
Fitness function to rank individuals
|
protected Set<SearchListener> |
listeners
Listeners
|
protected LocalSearchObjective<T> |
localObjective
Local search might need a different local objective
|
protected double |
localSearchProbability |
protected List<T> |
population
Current population
|
protected PopulationLimit |
populationLimit
The population limit decides when an iteration is done
|
protected SelectionFunction<T> |
selectionFunction
Selection function to select parents
|
protected Set<StoppingCondition> |
stoppingConditions
List of conditions on which to end the search
|
| Constructor and Description |
|---|
GeneticAlgorithm(ChromosomeFactory<T> factory)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBloatControl(BloatControlFunction bloat_control)
Set new bloat control function
|
void |
addFitnessFunction(FitnessFunction<T> function)
Add new fitness function (i.e., for new mutation)
|
void |
addFitnessFunctions(List<FitnessFunction<T>> functions) |
void |
addListener(SearchListener listener)
Add a new search listener
|
void |
addStoppingCondition(StoppingCondition condition)
addStoppingCondition
|
protected void |
applyLocalSearch()
Apply local search, starting from the best individual and continue
applying it to all individuals until the local search budget is used up.
|
protected void |
calculateFitnessAndSortPopulation()
Calculate fitness for all individuals
|
void |
clearPopulation()
Delete all current individuals
|
protected void |
disableFirstSecondaryCriterion() |
protected List<T> |
elitism()
Copy best individuals
|
protected void |
enableFirstSecondaryCriterion() |
protected abstract void |
evolve()
Generate one new generation
|
protected void |
generateInitialPopulation(int population_size)
Fills the population at first with recycled chromosomes - for more
information see recycleChromosomes() and ChromosomeRecycler - and after
that, the population is filled with random chromosomes.
|
protected void |
generateRandomPopulation(int population_size)
Generate random population of given size
|
abstract void |
generateSolution()
Generate solution
|
int |
getAge()
Get number of iterations
|
T |
getBestIndividual()
Return the individual with the highest fitChromosomeess
|
List<T> |
getBestIndividuals()
Return the individual(s) with the highest fitChromosomeess
|
String |
getBudgetString()
getBudgetString
|
FitnessFunction<T> |
getFitnessFunction()
Get currently used fitness function
|
List<FitnessFunction<T>> |
getFitnessFunctions()
Get all used fitness function
|
int |
getNumberOfFitnessFunctions() |
List<T> |
getPopulation()
Accessor for population Chromosome *
|
int |
getPopulationSize()
getPopulationSize
|
SelectionFunction<T> |
getSelectionFunction()
Get currently used fitness function
|
Set<StoppingCondition> |
getStoppingConditions() |
abstract void |
initializePopulation()
Set up initial population
|
protected boolean |
isBetterOrEqual(Chromosome chromosome1,
Chromosome chromosome2)
Returns true if the
chromosome1 is better or equal than
chromosome2 according to the compound fitness function. |
boolean |
isFinished()
Determine whether any of the stopping conditions hold
|
boolean |
isNextPopulationFull(List<T> nextGeneration)
Determine if the next generation has reached its size limit
|
boolean |
isTooLong(Chromosome chromosome)
Check whether individual is suitable according to bloat control functions
|
protected void |
notifyEvaluation(Chromosome chromosome)
Notify all search listeners of fitness evaluation
|
protected void |
notifyIteration()
Notify all search listeners of iteration
|
protected void |
notifyMutation(Chromosome chromosome)
Notify all search listeners of a mutation
|
protected void |
notifySearchFinished()
Notify all search listeners of search end
|
protected void |
notifySearchStarted()
Notify all search listeners of search start
|
void |
printBudget()
Prints out all information regarding this GAs stopping conditions
So far only used for testing purposes in TestSuiteGenerator
|
protected List<Chromosome> |
randomism()
Create random individuals
|
void |
removeListener(SearchListener listener)
Remove a search listener
|
void |
removeStoppingCondition(StoppingCondition condition)
removeStoppingCondition
|
void |
resetStoppingConditions()
resetStoppingConditions
|
void |
setArchive(Archive<T> archive) |
void |
setBloatControl(BloatControlFunction bloat_control)
Set new bloat control function
|
void |
setChromosomeFactory(ChromosomeFactory<T> factory)
Set a new factory method
|
void |
setCrossOverFunction(CrossOverFunction crossover)
Set a new xover function
|
void |
setPopulationLimit(PopulationLimit limit)
Set a new population limit function
|
void |
setSelectionFunction(SelectionFunction<T> function)
Set new fitness function (i.e., for new mutation)
|
void |
setStoppingCondition(StoppingCondition condition)
setStoppingCondition
|
void |
setStoppingConditionLimit(int value)
setStoppingConditionLimit
|
protected boolean |
shouldApplyLocalSearch()
Local search is only applied every X generations
|
protected void |
sortPopulation()
Sort the population by fitness
WARN: used only with singular objective algorithms, multi-objective
algorithms should implement their own 'sort'
|
protected void |
starveByFitness(int limit)
This method can be used to kick out the worst chromosomes in the current
population until the given limit is reached again.
|
protected void |
starveRandomly(int limit)
This method can be used to kick out random chromosomes in the current
population until the given limit is reached again.
|
protected void |
starveToLimit(int limit)
This method can be used to kick out chromosomes when the population is
possibly overcrowded
Depending on the Property "starve_by_fitness" chromosome are either
kicked out randomly or according to their fitness
|
String |
toString() |
protected void |
updateBestIndividualFromArchive() |
protected void |
updateFitnessFunctionsAndValues()
update archive fitness functions
|
protected void |
updateProbability(boolean improvement) |
protected void |
updateSecondaryCriterion(int starvationCounter)
enable and disable secondary criteria according to the strategy defined
in the Properties file.
|
void |
writeIndividuals(List<T> individuals)
Write to a file all fitness values of each individuals.
|
protected List<FitnessFunction<T extends Chromosome>> fitnessFunctions
protected SelectionFunction<T extends Chromosome> selectionFunction
protected CrossOverFunction crossoverFunction
protected List<T extends Chromosome> population
protected ChromosomeFactory<T extends Chromosome> chromosomeFactory
protected transient Set<SearchListener> listeners
protected transient Set<StoppingCondition> stoppingConditions
protected Set<BloatControlFunction> bloatControl
protected LocalSearchObjective<T extends Chromosome> localObjective
protected PopulationLimit populationLimit
protected int currentIteration
protected double localSearchProbability
protected transient Archive<T extends Chromosome> archive
public GeneticAlgorithm(ChromosomeFactory<T> factory)
factory - a ChromosomeFactory object.protected abstract void evolve()
protected boolean shouldApplyLocalSearch()
protected void disableFirstSecondaryCriterion()
protected void enableFirstSecondaryCriterion()
protected void updateSecondaryCriterion(int starvationCounter)
starvationCounter - protected void applyLocalSearch()
protected void updateProbability(boolean improvement)
public abstract void initializePopulation()
public abstract void generateSolution()
generateSolution in interface SearchAlgorithmprotected void generateInitialPopulation(int population_size)
population_size - a int.protected void starveToLimit(int limit)
limit - a int.protected void starveRandomly(int limit)
limit - a int.protected void starveByFitness(int limit)
limit - a int.protected void generateRandomPopulation(int population_size)
population_size - a int.public void clearPopulation()
public void addFitnessFunction(FitnessFunction<T> function)
function - a FitnessFunction object.public void addFitnessFunctions(List<FitnessFunction<T>> functions)
public FitnessFunction<T> getFitnessFunction()
FitnessFunction object.public List<FitnessFunction<T>> getFitnessFunctions()
FitnessFunction object.public int getNumberOfFitnessFunctions()
public void setSelectionFunction(SelectionFunction<T> function)
function - a
SelectionFunction
object.public SelectionFunction<T> getSelectionFunction()
SelectionFunction
object.public void setBloatControl(BloatControlFunction bloat_control)
bloat_control - a BloatControlFunction
object.public void addBloatControl(BloatControlFunction bloat_control)
bloat_control - a BloatControlFunction
object.public boolean isTooLong(Chromosome chromosome)
chromosome - a Chromosome object.public int getAge()
protected void calculateFitnessAndSortPopulation()
public int getPopulationSize()
getPopulationSize
protected List<Chromosome> randomism()
List object.protected void updateFitnessFunctionsAndValues()
public T getBestIndividual()
Chromosome object.public List<T> getBestIndividuals()
Chromosome object(s).public void writeIndividuals(List<T> individuals)
solutions - a list of Chromosome object(s).public void setChromosomeFactory(ChromosomeFactory<T> factory)
factory - a ChromosomeFactory object.public void setCrossOverFunction(CrossOverFunction crossover)
crossover - a
CrossOverFunction
object.public void addListener(SearchListener listener)
listener - a SearchListener
object.public void removeListener(SearchListener listener)
listener - a SearchListener
object.protected void notifySearchStarted()
protected void notifySearchFinished()
protected void notifyIteration()
protected void notifyEvaluation(Chromosome chromosome)
chromosome - a Chromosome object.protected void notifyMutation(Chromosome chromosome)
chromosome - a Chromosome object.protected void sortPopulation()
public List<T> getPopulation()
List object.public boolean isNextPopulationFull(List<T> nextGeneration)
nextGeneration - a List object.public void setPopulationLimit(PopulationLimit limit)
limit - a PopulationLimit
object.public boolean isFinished()
public void addStoppingCondition(StoppingCondition condition)
addStoppingCondition
condition - a StoppingCondition
object.public Set<StoppingCondition> getStoppingConditions()
public void setStoppingCondition(StoppingCondition condition)
setStoppingCondition
condition - a StoppingCondition
object.public void removeStoppingCondition(StoppingCondition condition)
removeStoppingCondition
condition - a StoppingCondition
object.public void resetStoppingConditions()
resetStoppingConditions
public void setStoppingConditionLimit(int value)
setStoppingConditionLimit
value - a int.protected void updateBestIndividualFromArchive()
protected boolean isBetterOrEqual(Chromosome chromosome1, Chromosome chromosome2)
chromosome1 is better or equal than
chromosome2 according to the compound fitness function.chromosome1 - a Chromosome object.chromosome2 - a Chromosome object.public void printBudget()
Copyright © 2010–2017 EvoSuite. All rights reserved.