Class NoImprovement<S extends Solution<S>>

java.lang.Object
io.github.nhtc2005.alns.stopping.NoImprovement<S>
Type Parameters:
S - the solution type
All Implemented Interfaces:
StoppingCriterion<S>

public final class NoImprovement<S extends Solution<S>> extends Object implements StoppingCriterion<S>
Stops after a configured number of iterations without a strictly better best objective.

Only global-best improvements restart the limit; equal objectives and changes to the current solution do not. The first check establishes the baseline. This criterion retains only the best objective value and must not be shared by concurrent runs.

  • Constructor Summary

    Constructors
    Constructor
    Description
    NoImprovement(long maxIterations)
    Creates a criterion with a limit on iterations without improvement.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the completed iteration count at the last observed improvement or baseline; zero after reset.
    long
    Returns the configured iteration limit without improvement.
    void
    Clears the saved best objective and resets the last improvement iteration to zero.
    boolean
    Checks whether the search should stop, including before the first iteration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NoImprovement

      public NoImprovement(long maxIterations)
      Creates a criterion with a limit on iterations without improvement.
      Parameters:
      maxIterations - the positive number of completed iterations allowed without improvement
      Throws:
      IllegalArgumentException - if maxIterations is not positive
  • Method Details

    • shouldStop

      public boolean shouldStop(StoppingContext<S> context)
      Description copied from interface: StoppingCriterion
      Checks whether the search should stop, including before the first iteration.

      Implementations may update their own state but must not modify solutions in the context.

      Specified by:
      shouldStop in interface StoppingCriterion<S extends Solution<S>>
      Parameters:
      context - the non-null search context
      Returns:
      true to stop; false to begin another iteration
    • reset

      public void reset()
      Clears the saved best objective and resets the last improvement iteration to zero.
      Specified by:
      reset in interface StoppingCriterion<S extends Solution<S>>
    • getMaxIterations

      public long getMaxIterations()
      Returns the configured iteration limit without improvement.
      Returns:
      the configured iteration limit without improvement
    • getLastImprovementIteration

      public long getLastImprovementIteration()
      Returns the completed iteration count at the last observed improvement or baseline; zero after reset.
      Returns:
      the completed iteration count at the last observed improvement or baseline; zero after reset