Class GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators<T extends Copyable<T>>

java.lang.Object
org.cicirello.search.evo.GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators<T>
Type Parameters:
T - The type of object under optimization.
All Implemented Interfaces:
Splittable<TrackableSearch<T>>, Metaheuristic<T>, ReoptimizableMetaheuristic<T>, TrackableSearch<T>

public class GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators<T extends Copyable<T>> extends Object
This class implements an evolutionary algorithm (EA) with a generational model, where a population of children are formed by applying genetic operators to members of the parent population, and where the children replace the parents in the next generation. In this EA, utilizes both a crossover operator and a mutation operator, whose application is controlled by crossover and mutation rates, but such that the operators are mutually exclusive. That is, each child is the result of crossover, or mutation, or a simply copy of a parent, but never the result of both crossover and mutation.

The crossover, mutation, and selection operators are completely configurable by passing instances of classes that implement the CrossoverOperator, MutationOperator, and SelectionOperator classes to one of the constructors. The EA implemented by this class can also be configured to use elitism, if desired, such that a specified number of the best solutions in the population survive the generation unaltered.

The library also includes a class for the more common generational model, such that population members may undergo both crossover and mutation in the same generation (see the GenerationalEvolutionaryAlgorithm class) as well as a class for mutation-only generational EAs (see GenerationalMutationOnlyEvolutionaryAlgorithm).

  • Constructor Details

    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Double<T> f, SelectionOperator selection, int eliteCount, ProgressTracker<T> tracker)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type double, the FitnessFunction.Double interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      eliteCount - The number of elite population members. Pass 0 for no elitism. eliteCount must be less than n.
      tracker - A ProgressTracker.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      IllegalArgumentException - if eliteCount is greater than or equal to n.
      NullPointerException - if any of mutation, crossover, initializer, f, selection, or tracker are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Integer<T> f, SelectionOperator selection, int eliteCount, ProgressTracker<T> tracker)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type int, the FitnessFunction.Integer interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      eliteCount - The number of elite population members. Pass 0 for no elitism. eliteCount must be less than n.
      tracker - A ProgressTracker.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      IllegalArgumentException - if eliteCount is greater than or equal to n.
      NullPointerException - if any of mutation, crossover, initializer, f, selection, or tracker are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Double<T> f, SelectionOperator selection, ProgressTracker<T> tracker)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type double, the FitnessFunction.Double interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      tracker - A ProgressTracker.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      NullPointerException - if any of mutation, crossover, initializer, f, selection, or tracker are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Integer<T> f, SelectionOperator selection, ProgressTracker<T> tracker)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type int, the FitnessFunction.Integer interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      tracker - A ProgressTracker.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      NullPointerException - if any of mutation, crossover, initializer, f, selection, or tracker are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Double<T> f, SelectionOperator selection, int eliteCount)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type double, the FitnessFunction.Double interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      eliteCount - The number of elite population members. Pass 0 for no elitism. eliteCount must be less than n.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      IllegalArgumentException - if eliteCount is greater than or equal to n.
      NullPointerException - if any of mutation, crossover, initializer, f, or selection are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Integer<T> f, SelectionOperator selection, int eliteCount)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type int, the FitnessFunction.Integer interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      eliteCount - The number of elite population members. Pass 0 for no elitism. eliteCount must be less than n.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      IllegalArgumentException - if eliteCount is greater than or equal to n.
      NullPointerException - if any of mutation, crossover, initializer, f, or selection are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Double<T> f, SelectionOperator selection)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type double, the FitnessFunction.Double interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      NullPointerException - if any of mutation, crossover, initializer, f, or selection are null.
    • GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators

      public GenerationalEvolutionaryAlgorithmMutuallyExclusiveOperators(int n, MutationOperator<T> mutation, double mutationRate, CrossoverOperator<T> crossover, double crossoverRate, Initializer<T> initializer, FitnessFunction.Integer<T> f, SelectionOperator selection)
      Constructs and initializes the evolutionary algorithm for an EA utilizing both a crossover operator and a mutation operator, such that the genetic operators follow a mutually exclusive property where each population member is involved in at most one of those operations in a single generation. This constructor supports fitness functions with fitnesses of type int, the FitnessFunction.Integer interface.
      Parameters:
      n - The population size.
      mutation - The mutation operator.
      mutationRate - The probability that a member of the population is mutated once during a generation. Note that this is not a per-bit rate since this class is generalized to evolution of any Copyable object type. For BitVector optimization and traditional genetic algorithm interpretation of mutation rate, configure your mutation operator with the per-bit mutation rate, and then pass 1.0 for this parameter.
      crossover - The crossover operator.
      crossoverRate - The probability that a pair of parents undergo crossover.
      initializer - An initializer for generating random initial population members.
      f - The fitness function.
      selection - The selection operator.
      Throws:
      IllegalArgumentException - if n is less than 1.
      IllegalArgumentException - if either mutationRate or crossoverRate are less than 0.
      IllegalArgumentException - if mutationRate + crossoverRate > 1.0.
      NullPointerException - if any of mutation, crossover, initializer, f, or selection are null.
  • Method Details

    • split

      Description copied from interface: Splittable
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms. The state of the object that is returned may or may not be identical to that of the original. Thus, this is a distinct concept from the functionality of the Copyable interface. Classes that implement this interface must ensure that the object returned performs the same functionality, and that it does not share any state data that would be either unsafe or inefficient for concurrent access by multiple threads. The split method is allowed to simply return the this reference, provided that it is both safe and efficient for multiple threads to share a single copy of the Splittable object. The intention is to provide a multithreaded search with the capability to provide spawned threads with their own distinct search operators. Such multithreaded algorithms can call the split method for each thread it spawns to generate a functionally identical copy of the operator, but with independent state.
      Specified by:
      split in interface Metaheuristic<T extends Copyable<T>>
      Specified by:
      split in interface ReoptimizableMetaheuristic<T extends Copyable<T>>
      Specified by:
      split in interface Splittable<T extends Copyable<T>>
      Returns:
      A functionally identical copy of the object, or a reference to this if it is both safe and efficient for multiple threads to share a single instance of this Splittable object.
    • optimize

      public final SolutionCostPair<T> optimize(int numGenerations)
      Runs the evolutionary algorithm beginning from a randomly generated population. If this method is called multiple times, each call begins at a new randomly generated population.
      Specified by:
      optimize in interface Metaheuristic<T extends Copyable<T>>
      Parameters:
      numGenerations - The number of generations to run.
      Returns:
      The best solution found during this set of generations, which may or may not be the same as the solution contained in the ProgressTracker, which contains the best across all calls to optimize as well as ReoptimizableMetaheuristic.reoptimize(int). Returns null if the run did not execute, such as if the ProgressTracker already contains the theoretical best solution.
    • reoptimize

      public final SolutionCostPair<T> reoptimize(int numGenerations)
      Runs the evolutionary algorithm continuing from the final population from the most recent call to either Metaheuristic.optimize(int) or ReoptimizableMetaheuristic.reoptimize(int), or from a random population if this is the first call to either method.
      Specified by:
      reoptimize in interface ReoptimizableMetaheuristic<T extends Copyable<T>>
      Parameters:
      numGenerations - The number of generations to run.
      Returns:
      The best solution found during this set of generations, which may or may not be the same as the solution contained in the ProgressTracker, which contains the best across all calls to optimize as well as Metaheuristic.optimize(int). Returns null if the run did not execute, such as if the ProgressTracker already contains the theoretical best solution.
    • getProgressTracker

      public final ProgressTracker<T> getProgressTracker()
      Description copied from interface: TrackableSearch
      Gets the ProgressTracker object that is in use for tracking search progress. The object returned by this method contains the best solution found during the search (including across multiple concurrent runs if the search is multithreaded, or across multiple restarts if the run methods were called multiple times), as well as cost of that solution, among other information. See the ProgressTracker documentation for more information about the search data tracked by this object.
      Specified by:
      getProgressTracker in interface TrackableSearch<T extends Copyable<T>>
      Returns:
      the ProgressTracker in use by this metaheuristic.
    • setProgressTracker

      public final void setProgressTracker(ProgressTracker<T> tracker)
      Description copied from interface: TrackableSearch
      Sets the ProgressTracker object that is in use for tracking search progress. Any previously set ProgressTracker is replaced by this one.
      Specified by:
      setProgressTracker in interface TrackableSearch<T extends Copyable<T>>
      Parameters:
      tracker - The new ProgressTracker to set. The tracker must not be null. This method does nothing if tracker is null.
    • getProblem

      public final Problem<T> getProblem()
      Description copied from interface: TrackableSearch
      Gets a reference to the problem that this search is solving.
      Specified by:
      getProblem in interface TrackableSearch<T extends Copyable<T>>
      Returns:
      a reference to the problem.
    • getTotalRunLength

      public long getTotalRunLength()
      Gets the total run length in number of fitness evaluations. This is the total run length across all calls to Metaheuristic.optimize(int) and ReoptimizableMetaheuristic.reoptimize(int). This may differ from what may be expected based on run lengths. For example, the search terminates if it finds the theoretical best solution, and also immediately returns if a prior call found the theoretical best. In such cases, the total run length may be less than the requested run length.
      Specified by:
      getTotalRunLength in interface TrackableSearch<T extends Copyable<T>>
      Returns:
      The total number of generations completed across all calls to Metaheuristic.optimize(int) and ReoptimizableMetaheuristic.reoptimize(int).