Package io.github.nhtc2005.alns.stopping
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
ConstructorsConstructorDescriptionNoImprovement(long maxIterations) Creates a criterion with a limit on iterations without improvement. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the completed iteration count at the last observed improvement or baseline; zero after reset.longReturns the configured iteration limit without improvement.voidreset()Clears the saved best objective and resets the last improvement iteration to zero.booleanshouldStop(StoppingContext<S> context) Checks whether the search should stop, including before the first iteration.
-
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- ifmaxIterationsis not positive
-
-
Method Details
-
shouldStop
Description copied from interface:StoppingCriterionChecks 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:
shouldStopin interfaceStoppingCriterion<S extends Solution<S>>- Parameters:
context- the non-null search context- Returns:
trueto stop;falseto begin another iteration
-
reset
public void reset()Clears the saved best objective and resets the last improvement iteration to zero.- Specified by:
resetin interfaceStoppingCriterion<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
-