Documentation of 'org.jgap.impl.GreedyCrossover' Java class
GreedyCrossover
org.jgap.impl

Class 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.
    After the GreedyCrossover, these two conditions always remain true, so it can be applied again and again. The algorithm throws an assertion error if the two initial chromosomes does not satisfy these conditions. Greedy crossover can be best explained in the terms of the Traveling Salesman Problem: The algorithm selects the first city of one parent, compares the cities leaving that city in both parents, and chooses the closer one to extend the tour. If one city has already appeared in the tour, we choose the other city. If both cities have already appeared, we randomly select a non-selected city. See J. Grefenstette, R. Gopal, R. Rosmaita, and D. Gucht. Genetic algorithms for the traveling salesman problem. In Proceedings of the Second International Conference on Genetic Algorithms. Lawrence Eribaum Associates, Mahwah, NJ, 1985. and also Sushil J. Louis & Gong Li}
    Since:
    2.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int compareTo(java.lang.Object a_other)
      Compares the given GeneticOperator to this GeneticOperator.
      double distance(java.lang.Object a_from, java.lang.Object a_to)
      Compute the distance between "cities", indicated by these two given genes.
      int getStartOffset()
      Gets a number of genes at the start of chromosome, that are excluded from the swapping.
      void operate(IChromosome a_firstMate, IChromosome a_secondMate)
      Performs a greedy crossover for the two given chromosoms.
      void operate(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.
      void setStartOffset(int a_offset)
      Sets a number of genes at the start of chromosome, that are excluded from the swapping.
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 - Object
        a_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: GeneticOperator
        The 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 issues
        a_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 on
        a_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

You see the box below because you did not login.