Class Alns<S extends Solution<S>>

java.lang.Object
io.github.nhtc2005.alns.core.Alns<S>
Type Parameters:
S - the solution type

public final class Alns<S extends Solution<S>> extends Object
Runs Adaptive Large Neighborhood Search with configurable operators and search policies.

The objective is minimized. Use builder() to configure the solver, then supply acceptance and stopping criteria to solve(S, io.github.nhtc2005.alns.acceptance.AcceptanceCriterion<S>, io.github.nhtc2005.alns.stopping.StoppingCriterion<S>). Instances share their configured components and random generator across calls and must not be used for concurrent searches.

  • Method Details

    • builder

      public static <S extends Solution<S>> Alns.Builder<S> builder()
      Returns a builder with statistics, visit tracking, local search, and callbacks disabled.
      Type Parameters:
      S - the solution type
      Returns:
      a new builder
    • solve

      public AlnsResult<S> solve(S initialSolution, AcceptanceCriterion<S> acceptanceCriterion, StoppingCriterion<S> stoppingCriterion)
      Searches from a feasible initial solution until the stopping criterion requests termination.

      Resets the selector, criteria, and tracker before each run, but does not reset the random generator or operators. The initial solution is copied, and statistics are created separately for each run. Acceptance is evaluated every iteration; infeasible candidates are rejected, while feasible new bests are accepted regardless of the acceptance decision. Iterations are numbered from one; iteration zero denotes the initial solution.

      If configured, local search runs directly on feasible repaired solutions before evaluation. Its result is checked again for feasibility and used by acceptance, tracking, feedback, and statistics. The iteration runtime includes local search. Local search is not reset between runs.

      Reward eligibility uses strict comparisons. New bests are always eligible; other accepted candidates are eligible only when their objective differs from the current solution and their key is new to the tracker. Ineligible feedback receives the rejected-outcome score. The tracker records the initial solution and accepted candidates; revisited candidates can still become current. Exceptions from user components propagate.

      If configured, the iteration callback runs synchronously after feedback and statistics. It runs even when statistics are disabled and is not reset between runs. Callback time counts toward total runtime, but not iteration statistics.

      Parameters:
      initialSolution - the non-null feasible initial solution with a finite objective
      acceptanceCriterion - the non-null acceptance policy
      stoppingCriterion - the non-null termination policy, checked before each iteration
      Returns:
      the best solution, completed iteration count, runtime, and statistics
      Throws:
      NullPointerException - if an argument, solution copy, operator result, or selection is null
      IllegalArgumentException - if the initial solution is infeasible or the initial or a feasible candidate objective is not finite
      IllegalStateException - if the selector returns an out-of-range operator index