Class AOptimizer<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>,​V extends java.lang.Comparable<V>>

  • Type Parameters:
    I - The type of input instances (problems) to be solved by the algorithm.
    O - The type of output that is obtained by running the algorithm on the input.
    V - The type performance values will have to compare different solutions.
    All Implemented Interfaces:
    java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>, java.util.concurrent.Callable<O>, java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>, org.api4.java.algorithm.IAlgorithm<I,​O>, org.api4.java.algorithm.IOptimizationAlgorithm<I,​O,​V>, org.api4.java.algorithm.ISolutionCandidateIterator<I,​O>, org.api4.java.common.control.ICancelable, org.api4.java.common.control.ILoggingCustomizable

    public abstract class AOptimizer<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>,​V extends java.lang.Comparable<V>>
    extends ASolutionCandidateIterator<I,​O>
    implements org.api4.java.algorithm.IOptimizationAlgorithm<I,​O,​V>
    The AOptimizer represents an algorithm that is meant to optimize for a single best solution. While it may observe multiple candidates for the best solution and report them via events when running, eventually it will return only the single best observed one.
    • Constructor Detail

      • AOptimizer

        public AOptimizer​(I input)
        C'tor taking only an input as a parameter.
        Parameters:
        input - The input of the algorithm.
      • AOptimizer

        protected AOptimizer​(IOwnerBasedAlgorithmConfig config,
                             I input)
        C'tor taking a configuration of the algorithm and an input for the algorithm as arguments.
        Parameters:
        config - The parameterization of the algorithm.
        input - The input to the algorithm (the problem to solve).
    • Method Detail

      • updateBestSeenSolution

        protected boolean updateBestSeenSolution​(O candidate)
        Updates the best seen solution if the new solution is better. Returns true iff the best seen solution has been updated.
        Parameters:
        candidate - A candidate for a new best seen solution. It is only updated iff the candidate performs better than the bestSeenSolution observed so far.
        Returns:
        Returns true iff the candidate is the best seen solution.
      • setBestSeenSolution

        protected boolean setBestSeenSolution​(O candidate)
        Sets the best seen solution regardless the currently best solution.
        Parameters:
        candidate -
        Returns:
        true iff the new solution has a higher score than the existing one
      • nextSolutionCandidate

        public O nextSolutionCandidate()
                                throws java.lang.InterruptedException,
                                       org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException,
                                       org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException,
                                       org.api4.java.algorithm.exceptions.AlgorithmException
        Specified by:
        nextSolutionCandidate in interface org.api4.java.algorithm.ISolutionCandidateIterator<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Overrides:
        nextSolutionCandidate in class ASolutionCandidateIterator<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Throws:
        java.lang.InterruptedException
        org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException
        org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException
        org.api4.java.algorithm.exceptions.AlgorithmException
      • nextSolutionCandidateEvent

        public org.api4.java.algorithm.events.result.ISolutionCandidateFoundEvent<O> nextSolutionCandidateEvent()
                                                                                                         throws java.lang.InterruptedException,
                                                                                                                org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException,
                                                                                                                org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException,
                                                                                                                org.api4.java.algorithm.exceptions.AlgorithmException
        Specified by:
        nextSolutionCandidateEvent in interface org.api4.java.algorithm.ISolutionCandidateIterator<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Overrides:
        nextSolutionCandidateEvent in class ASolutionCandidateIterator<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Throws:
        java.lang.InterruptedException
        org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException
        org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException
        org.api4.java.algorithm.exceptions.AlgorithmException
      • getBestScoreKnownToExist

        public V getBestScoreKnownToExist()
      • tellAboutBestScoreKnownToExist

        public void tellAboutBestScoreKnownToExist​(V bestScoreKnownToExist)
      • getBestSeenSolution

        public O getBestSeenSolution()
        Returns:
        The best seen solution, yet.
      • call

        public O call()
               throws java.lang.InterruptedException,
                      org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException,
                      org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException,
                      org.api4.java.algorithm.exceptions.AlgorithmException
        Specified by:
        call in interface java.util.concurrent.Callable<I>
        Specified by:
        call in interface org.api4.java.algorithm.IAlgorithm<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Overrides:
        call in class ASolutionCandidateIterator<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
        Throws:
        java.lang.InterruptedException
        org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException
        org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException
        org.api4.java.algorithm.exceptions.AlgorithmException
      • getLoggerName

        public java.lang.String getLoggerName()
        Specified by:
        getLoggerName in interface org.api4.java.common.control.ILoggingCustomizable
        Overrides:
        getLoggerName in class AAlgorithm<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
      • setLoggerName

        public void setLoggerName​(java.lang.String name)
        Specified by:
        setLoggerName in interface org.api4.java.common.control.ILoggingCustomizable
        Overrides:
        setLoggerName in class AAlgorithm<I,​O extends org.api4.java.common.attributedobjects.ScoredItem<V>>