Class CrossoverPermutationOnePoint

  • All Implemented Interfaces:
    org.opt4j.core.optimizer.Operator<org.opt4j.core.genotype.PermutationGenotype<?>>, Crossover<org.opt4j.core.genotype.PermutationGenotype<?>>, CrossoverPermutation
    Direct Known Subclasses:
    CrossoverPermutationDefault

    public class CrossoverPermutationOnePoint
    extends java.lang.Object
    implements CrossoverPermutation

    Crossover for the PermutationGenotype.

    This operator takes sublist of the first permutation from the beginning to a random cut point and fills the remaining elements from the second permutation.

    Given two permutations
    1 2 3 4 5 6 7 8 and 8 7 6 5 4 3 2 1.
    This results, for instance, in
    1 2 3 4 5 8 7 6 or 1 2 8 7 6 5 4 3.

    Additionally, a rotation value defines if the initial permutation are randomly rotated. With the rotation possible results would be
    4 5 6 8 7 3 2 1 and 7 8 1 2 4 3 6 5.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Random random  
      protected boolean rotation  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Pair<org.opt4j.core.genotype.PermutationGenotype<?>> crossover​(org.opt4j.core.genotype.PermutationGenotype<?> p1, org.opt4j.core.genotype.PermutationGenotype<?> p2)
      Performs a crossover for two Genotype parents.
      protected void crossoverFill​(org.opt4j.core.genotype.PermutationGenotype<?> p1, org.opt4j.core.genotype.PermutationGenotype<?> p2, org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o1, org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o2, java.util.Set<java.lang.Object> elements1, java.util.Set<java.lang.Object> elements2)
      Helper function for crossover() to fill and rotate after the cut point.
      protected void crossoverToCutpoint​(org.opt4j.core.genotype.PermutationGenotype<?> p1, org.opt4j.core.genotype.PermutationGenotype<?> p2, org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o1, org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o2, java.util.Set<java.lang.Object> elements1, java.util.Set<java.lang.Object> elements2)
      Helper function for crossover() to crossover and rotate up to the coined cut point.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • random

        protected final java.util.Random random
      • rotation

        protected final boolean rotation
    • Constructor Detail

      • CrossoverPermutationOnePoint

        @Inject
        public CrossoverPermutationOnePoint​(org.opt4j.core.common.random.Rand random,
                                            boolean rotation)
        Parameters:
        random - the random number generator
        rotation - use rotation
    • Method Detail

      • crossover

        public Pair<org.opt4j.core.genotype.PermutationGenotype<?>> crossover​(org.opt4j.core.genotype.PermutationGenotype<?> p1,
                                                                              org.opt4j.core.genotype.PermutationGenotype<?> p2)
        Description copied from interface: Crossover
        Performs a crossover for two Genotype parents. The resulting pair of Genotype offspring is returned.
        Specified by:
        crossover in interface Crossover<org.opt4j.core.genotype.PermutationGenotype<?>>
        Parameters:
        p1 - The first parent genotype for the crossover
        p2 - The second parents genotype for the crossover
        Returns:
        The resulting pair of offspring genotypes
      • crossoverToCutpoint

        protected void crossoverToCutpoint​(org.opt4j.core.genotype.PermutationGenotype<?> p1,
                                           org.opt4j.core.genotype.PermutationGenotype<?> p2,
                                           org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o1,
                                           org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o2,
                                           java.util.Set<java.lang.Object> elements1,
                                           java.util.Set<java.lang.Object> elements2)
        Helper function for crossover() to crossover and rotate up to the coined cut point.
        Parameters:
        p1 - parent one
        p2 - parent two
        o1 - child one
        o2 - child two
        elements1 - elements of genotype child one
        elements2 - elements of genotype child two
      • crossoverFill

        protected void crossoverFill​(org.opt4j.core.genotype.PermutationGenotype<?> p1,
                                     org.opt4j.core.genotype.PermutationGenotype<?> p2,
                                     org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o1,
                                     org.opt4j.core.genotype.PermutationGenotype<java.lang.Object> o2,
                                     java.util.Set<java.lang.Object> elements1,
                                     java.util.Set<java.lang.Object> elements2)
        Helper function for crossover() to fill and rotate after the cut point.
        Parameters:
        p1 - parent one
        p2 - parent two
        o1 - child one
        o2 - child two
        elements1 - elements of genotype child one
        elements2 - elements of genotype child two