Class Alns.Builder<S extends Solution<S>>

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

public static final class Alns.Builder<S extends Solution<S>> extends Object
Configures a solver, using uniform random selection unless a selector is supplied.

A random generator and at least one operator of each kind are required. Built solvers share configured component instances; building does not clone their state.

  • Method Details

    • randomGenerator

      public Alns.Builder<S> randomGenerator(RandomGenerator randomGenerator)
      Sets the required source of randomness.
      Parameters:
      randomGenerator - the random generator used by the search
      Returns:
      this builder
      Throws:
      NullPointerException - if randomGenerator is null
    • addDestroyOperator

      public Alns.Builder<S> addDestroyOperator(DestroyOperator<S> destroyOperator)
      Appends a destroy operator named destroy-<index>; insertion order defines its index.
      Parameters:
      destroyOperator - the destroy operator to append
      Returns:
      this builder
      Throws:
      NullPointerException - if destroyOperator is null
    • addDestroyOperator

      public Alns.Builder<S> addDestroyOperator(String name, DestroyOperator<S> destroyOperator)
      Appends a named destroy operator; insertion order defines its index.

      Names are used in logs and statistics and must be non-blank and unique among destroy operators.

      Parameters:
      name - the operator name
      destroyOperator - the destroy operator to append
      Returns:
      this builder
      Throws:
      NullPointerException - if name or destroyOperator is null
    • addRepairOperator

      public Alns.Builder<S> addRepairOperator(RepairOperator<S> repairOperator)
      Appends a repair operator named repair-<index>; insertion order defines its index.
      Parameters:
      repairOperator - the repair operator to append
      Returns:
      this builder
      Throws:
      NullPointerException - if repairOperator is null
    • addRepairOperator

      public Alns.Builder<S> addRepairOperator(String name, RepairOperator<S> repairOperator)
      Appends a named repair operator; insertion order defines its index.

      Names are used in logs and statistics and must be non-blank and unique among repair operators.

      Parameters:
      name - the operator name
      repairOperator - the repair operator to append
      Returns:
      this builder
      Throws:
      NullPointerException - if name or repairOperator is null
    • operatorSelector

      public Alns.Builder<S> operatorSelector(OperatorSelector<S> operatorSelector)
      Sets the operator selector, replacing the default uniform random selector.
      Parameters:
      operatorSelector - the selector compatible with the configured operator counts
      Returns:
      this builder
      Throws:
      NullPointerException - if operatorSelector is null
    • collectStatistics

      public Alns.Builder<S> collectStatistics(boolean collectStatistics)
      Enables or disables statistics collection.
      Parameters:
      collectStatistics - whether to retain full histories and outcome counts; false by default
      Returns:
      this builder
    • visitedSolutionTracker

      public Alns.Builder<S> visitedSolutionTracker(VisitedSolutionTracker<S> visitedSolutionTracker)
      Sets the tracker used to identify accepted solution revisits.
      Parameters:
      visitedSolutionTracker - the tracker for reward eligibility; disabled by default
      Returns:
      this builder
      Throws:
      NullPointerException - if visitedSolutionTracker is null
    • localSearch

      public Alns.Builder<S> localSearch(LocalSearch<S> localSearch)
      Sets optional local search for feasible repaired solutions; disabled by default.
      Parameters:
      localSearch - the local search to apply before candidate evaluation
      Returns:
      this builder
      Throws:
      NullPointerException - if localSearch is null
    • onIteration

      public Alns.Builder<S> onIteration(IterationCallback<S> callback)
      Sets the callback invoked after each completed iteration; disabled by default.
      Parameters:
      callback - the synchronous callback, shared across runs
      Returns:
      this builder
      Throws:
      NullPointerException - if callback is null
    • build

      public Alns<S> build()
      Creates a solver and validates the selector's operator counts.
      Returns:
      a solver with copied operator lists and shared component instances
      Throws:
      NullPointerException - if no random generator was configured
      IllegalStateException - if either operator list is empty
      IllegalArgumentException - if an operator name is blank or duplicated within its group, or the selector rejects the operator counts