Class AnyOfStoppingCriterion<S extends Solution<S>>

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

public final class AnyOfStoppingCriterion<S extends Solution<S>> extends Object implements StoppingCriterion<S>
Stops when any contained criterion requests termination.

Criteria are checked in list order, stopping at the first true result. Skipped criteria do not receive that check, but all criteria are reset before each solve.

  • Constructor Details

    • AnyOfStoppingCriterion

      public AnyOfStoppingCriterion(List<? extends StoppingCriterion<S>> criteria)
      Creates a criterion from a defensive copy of the supplied list.
      Parameters:
      criteria - the non-empty list of non-null criteria, in evaluation order
      Throws:
      NullPointerException - if the list or any element is null
      IllegalArgumentException - if the list is empty
  • 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()
      Resets every contained criterion, including those skipped by short-circuit evaluation.
      Specified by:
      reset in interface StoppingCriterion<S extends Solution<S>>
    • getCriteria

      public List<StoppingCriterion<S>> getCriteria()
      Returns the unmodifiable criteria list in evaluation order; criterion instances are shared.
      Returns:
      the unmodifiable criteria list in evaluation order; criterion instances are shared