Class MaxRuntime<S extends Solution<S>>

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

public final class MaxRuntime<S extends Solution<S>> extends Object implements StoppingCriterion<S>
Stops when elapsed search time reaches the configured duration.

The limit is checked between iterations and does not interrupt a running operator, so actual runtime may exceed it.

  • Constructor Details

    • MaxRuntime

      public MaxRuntime(Duration maxRuntime)
      Creates a criterion with a fixed runtime limit.
      Parameters:
      maxRuntime - the positive maximum search duration, representable in nanoseconds
      Throws:
      NullPointerException - if maxRuntime is null
      IllegalArgumentException - if the duration is not positive or overflows nanoseconds
  • 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
    • getMaxRuntime

      public Duration getMaxRuntime()
      Returns the configured runtime limit.
      Returns:
      the configured runtime limit