Package io.github.nhtc2005.alns.stopping
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>
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 Summary
ConstructorsConstructorDescriptionMaxRuntime(Duration maxRuntime) Creates a criterion with a fixed runtime limit. -
Method Summary
Modifier and TypeMethodDescriptionReturns the configured runtime limit.booleanshouldStop(StoppingContext<S> context) 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, waitMethods inherited from interface io.github.nhtc2005.alns.stopping.StoppingCriterion
reset
-
Constructor Details
-
MaxRuntime
Creates a criterion with a fixed runtime limit.- Parameters:
maxRuntime- the positive maximum search duration, representable in nanoseconds- Throws:
NullPointerException- ifmaxRuntimeis nullIllegalArgumentException- if the duration is not positive or overflows nanoseconds
-
-
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
-
getMaxRuntime
Returns the configured runtime limit.- Returns:
- the configured runtime limit
-