Package org.opt4j.operators.crossover
Class CrossoverPermutationOnePoint
- java.lang.Object
-
- org.opt4j.operators.crossover.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
and8 7 6 5 4 3 2 1
.
This results, for instance, in
1 2 3 4 5 8 7 6
or1 2 8 7 6 5 4 3
.Additionally, a
rotation
value defines if the initial permutation are randomly rotated. With therotation
possible results would be
4 5 6 8 7 3 2 1
and7 8 1 2 4 3 6 5
.
-
-
Constructor Summary
Constructors Constructor Description CrossoverPermutationOnePoint(org.opt4j.core.common.random.Rand random, boolean rotation)
Constructs a newCrossoverPermutationOnePoint
.
-
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 twoGenotype
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
-
Methods inherited from interface org.opt4j.operators.crossover.Crossover
getOperatorType
-
-
-
-
Constructor Detail
-
CrossoverPermutationOnePoint
@Inject public CrossoverPermutationOnePoint(org.opt4j.core.common.random.Rand random, boolean rotation)
Constructs a newCrossoverPermutationOnePoint
.- Parameters:
random
- the random number generatorrotation
- 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 twoGenotype
parents. The resulting pair ofGenotype
offspring is returned.
-
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 onep2
- parent twoo1
- child oneo2
- child twoelements1
- elements of genotype child oneelements2
- 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 onep2
- parent twoo1
- child oneo2
- child twoelements1
- elements of genotype child oneelements2
- elements of genotype child two
-
-