org.jgap.impl
Class GreedyCrossover
- java.lang.Object
-
- org.jgap.BaseGeneticOperator
-
- org.jgap.impl.GreedyCrossover
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, GeneticOperator
public class GreedyCrossover extends BaseGeneticOperator
The Greedy Crossover is a specific type of crossover. It can only be is applied if- 1. All genes in the chromosome are different and
- 2. The set of genes for both chromosomes is identical and only their order in the chromosome can vary.
- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description GreedyCrossover()Default constructor for dynamic instantiation.GreedyCrossover(Configuration a_configuration)Using the given configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intcompareTo(java.lang.Object a_other)Compares the given GeneticOperator to this GeneticOperator.doubledistance(java.lang.Object a_from, java.lang.Object a_to)Compute the distance between "cities", indicated by these two given genes.intgetStartOffset()Gets a number of genes at the start of chromosome, that are excluded from the swapping.voidoperate(IChromosome a_firstMate, IChromosome a_secondMate)Performs a greedy crossover for the two given chromosoms.voidoperate(Population a_population, java.util.List a_candidateChromosomes)The operate method will be invoked on each of the genetic operators referenced by the current Configuration object during the evolution phase.voidsetStartOffset(int a_offset)Sets a number of genes at the start of chromosome, that are excluded from the swapping.-
Methods inherited from class org.jgap.BaseGeneticOperator
equals, getConfiguration
-
-
-
-
Constructor Detail
-
GreedyCrossover
public GreedyCrossover() throws InvalidConfigurationExceptionDefault constructor for dynamic instantiation.Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
- Throws:
InvalidConfigurationException- Since:
- 2.6, 3.0 (since 2.0 without a_configuration)
-
GreedyCrossover
public GreedyCrossover(Configuration a_configuration) throws InvalidConfigurationException
Using the given configuration.- Parameters:
a_configuration- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0 (since 2.6 without a_configuration)
-
-
Method Detail
-
distance
public double distance(java.lang.Object a_from, java.lang.Object a_to)Compute the distance between "cities", indicated by these two given genes. The default method expects the genes to be IntegerGene's and returns their absolute difference, that makes sense only for tests.- Parameters:
a_from- Objecta_to- Object- Returns:
- distance between the two given cities
-
operate
public void operate(Population a_population, java.util.List a_candidateChromosomes)
Description copied from interface:GeneticOperatorThe operate method will be invoked on each of the genetic operators referenced by the current Configuration object during the evolution phase. Operators are given an opportunity to run in the order that they are added to the Configuration. Implementations of this method may reference the population of Chromosomes as it was at the beginning of the evolutionary phase and/or they may instead reference the candidate Chromosomes, which are the results of prior genetic operators. In either case, only Chromosomes added to the list of candidate chromosomes will be considered for natural selection. The parameters a_population and a_candidateChromosomes may refer to the same list of chromosomes for performance issues. Thus would mean an in-place modification. In ealier JGAP versions it was suggested never modifying the input population. Please refer to implementations delivered with JGAP to get a picture of the way non-susceptible in-place modifications are possible. If wrongly done, ConcurrentModificationException could be risen when accessing the population by an iterator in a GeneticOperator. Or, if population.getChromosomes().size() was used inside a loop where chromosomes were added to the input population this could lead to an infinite loop in worst case.- Parameters:
a_population- the population of chromosomes from the current evolution prior to exposure to any genetic operators. Chromosomes in this array should not be modified. Please, notice, that the call in Genotype.evolve() to the implementations of GeneticOperator overgoes this due to performance issuesa_candidateChromosomes- the pool of chromosomes that have been selected for the next evolved population
-
operate
public void operate(IChromosome a_firstMate, IChromosome a_secondMate)
Performs a greedy crossover for the two given chromosoms.- Parameters:
a_firstMate- the first chromosome to crossover ona_secondMate- the second chromosome to crossover on- Throws:
java.lang.Error- if the gene set in the chromosomes is not identical- Since:
- 2.1
-
setStartOffset
public void setStartOffset(int a_offset)
Sets a number of genes at the start of chromosome, that are excluded from the swapping. In the Salesman task, the first city in the list should (where the salesman leaves from) probably should not change as it is part of the list. The default value is 1.- Parameters:
a_offset- the start offset to use
-
getStartOffset
public int getStartOffset()
Gets a number of genes at the start of chromosome, that are excluded from the swapping. In the Salesman task, the first city in the list should (where the salesman leaves from) probably should not change as it is part of the list. The default value is 1.- Returns:
- the start offset used
-
compareTo
public int compareTo(java.lang.Object a_other)
Compares the given GeneticOperator to this GeneticOperator.- Parameters:
a_other- the instance against which to compare this instance- Returns:
- a negative number if this instance is "less than" the given instance, zero if they are equal to each other, and a positive number if this is "greater than" the given instance
- Since:
- 2.6
-
-
DMelt 3.0 © DataMelt by jWork.ORG