Class OnePlusOneEvolutionaryAlgorithm<T extends Copyable<T>>

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

public class OnePlusOneEvolutionaryAlgorithm<T extends Copyable<T>> extends Object implements SingleSolutionMetaheuristic<T>
This class implements a (1+1)-EA. In a (1+1)-EA, the evolutionary algorithm has a population size of 1, in each cycle of the algorithm a single mutant is created from that single population member, forming a population of size 2, and finally the EA keeps the better of the two solutions. This is perhaps the simplest case of an EA. This class supports optimizing arbitrary structures, specified by the generic type parameter.
  • Constructor Details

    • OnePlusOneEvolutionaryAlgorithm

      public OnePlusOneEvolutionaryAlgorithm(OptimizationProblem<T> problem, UndoableMutationOperator<T> mutation, Initializer<T> initializer)
      Creates a OnePlusOneEvolutionaryAlgorithm instance for real-valued optimization problems. A ProgressTracker is created for you.
      Parameters:
      problem - An instance of an optimization problem to solve.
      mutation - A mutation operator supporting the undo operation.
      initializer - The source of random initial states.
      Throws:
      NullPointerException - if any of the parameters are null
    • OnePlusOneEvolutionaryAlgorithm

      public OnePlusOneEvolutionaryAlgorithm(IntegerCostOptimizationProblem<T> problem, UndoableMutationOperator<T> mutation, Initializer<T> initializer)
      Creates a OnePlusOneEvolutionaryAlgorithm instance for integer-valued optimization problems. A ProgressTracker is created for you.
      Parameters:
      problem - An instance of an optimization problem to solve.
      mutation - A mutation operator supporting the undo operation.
      initializer - The source of random initial states.
      Throws:
      NullPointerException - if any of the parameters are null
    • OnePlusOneEvolutionaryAlgorithm

      public OnePlusOneEvolutionaryAlgorithm(OptimizationProblem<T> problem, UndoableMutationOperator<T> mutation, Initializer<T> initializer, ProgressTracker<T> tracker)
      Creates a OnePlusOneEvolutionaryAlgorithm instance for real-valued optimization problems.
      Parameters:
      problem - An instance of an optimization problem to solve.
      mutation - A mutation operator supporting the undo operation.
      initializer - The source of random initial states.
      tracker - A ProgressTracker object, which is used to keep track of the best solution found during the run, the time when it was found, and other related data.
      Throws:
      NullPointerException - if any of the parameters are null
    • OnePlusOneEvolutionaryAlgorithm

      public OnePlusOneEvolutionaryAlgorithm(IntegerCostOptimizationProblem<T> problem, UndoableMutationOperator<T> mutation, Initializer<T> initializer, ProgressTracker<T> tracker)
      Creates a OnePlusOneEvolutionaryAlgorithm instance for integer-valued optimization problems.
      Parameters:
      problem - An instance of an optimization problem to solve.
      mutation - A mutation operator supporting the undo operation.
      initializer - The source of random initial states.
      tracker - A ProgressTracker object, which is used to keep track of the best solution found during the run, the time when it was found, and other related data.
      Throws:
      NullPointerException - if any of the parameters are null
  • Method Details

    • finalize

      protected final void finalize()
      Overrides:
      finalize in class Object
    • reoptimize

      public final SolutionCostPair<T> reoptimize(int maxEvals)
      Continues optimizing starting from the previous best found solution contained in the tracker object, rather than from a random one. If no prior run had been performed, then this method starts the run from a randomly generated solution.
      Specified by:
      reoptimize in interface ReoptimizableMetaheuristic<T extends Copyable<T>>
      Parameters:
      maxEvals - The maximum number of evaluations (i.e., iterations) to execute.
      Returns:
      the current solution at the end of this run and its cost, which may or may not be the best of run solution, and which may or may not be the same as the solution contained in this instance's ProgressTracker, which contains the best of all runs. Returns null if the run did not execute, such as if the ProgressTracker already contains the theoretical best solution.
    • optimize

      public final SolutionCostPair<T> optimize(int maxEvals)
      Runs the EA beginning at a random initial solution.
      Specified by:
      optimize in interface Metaheuristic<T extends Copyable<T>>
      Parameters:
      maxEvals - The maximum number of evaluations (i.e., iterations) to execute.
      Returns:
      the current solution at the end of this run and its cost, which may or may not be the best of run solution, and which may or may not be the same as the solution contained in this instance's ProgressTracker, which contains the best of all runs. Returns null if the run did not execute, such as if the ProgressTracker already contains the theoretical best solution.
    • optimize

      public final SolutionCostPair<T> optimize(int maxEvals, T start)
      Runs the EA beginning at a specified initial solution.
      Specified by:
      optimize in interface SingleSolutionMetaheuristic<T extends Copyable<T>>
      Parameters:
      maxEvals - The maximum number of evaluations (i.e., iterations) to execute.
      start - The desired starting solution.
      Returns:
      the current solution at the end of this run and its cost, which may or may not be the best of run solution, and which may or may not be the same as the solution contained in this instance's ProgressTracker, which contains the best of all runs. Returns null if the run did not execute, such as if the ProgressTracker already contains the theoretical best solution.
    • 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.
    • 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.
    • 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.
    • getTotalRunLength

      public long getTotalRunLength()
      Gets the total number of evaluations (iterations) performed by this EA object. This is the total number of such evaluations across all calls to the optimize and reoptimize methods. This may differ from the combined number of maxEvals passed as a parameter to those methods. For example, those methods terminate if they find the theoretical best solution, and also immediately return if a prior call found the theoretical best. In such cases, the total run length may be less than the requested maxEvals.
      Specified by:
      getTotalRunLength in interface TrackableSearch<T extends Copyable<T>>
      Returns:
      the total number of evaluations