Package io.github.nhtc2005.alns.core
Class Alns.Builder<S extends Solution<S>>
java.lang.Object
io.github.nhtc2005.alns.core.Alns.Builder<S>
- Type Parameters:
S- the solution type
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 Summary
Modifier and TypeMethodDescriptionaddDestroyOperator(DestroyOperator<S> destroyOperator) Appends a destroy operator nameddestroy-<index>; insertion order defines its index.addDestroyOperator(String name, DestroyOperator<S> destroyOperator) Appends a named destroy operator; insertion order defines its index.addRepairOperator(RepairOperator<S> repairOperator) Appends a repair operator namedrepair-<index>; insertion order defines its index.addRepairOperator(String name, RepairOperator<S> repairOperator) Appends a named repair operator; insertion order defines its index.build()Creates a solver and validates the selector's operator counts.collectStatistics(boolean collectStatistics) Enables or disables statistics collection.localSearch(LocalSearch<S> localSearch) Sets optional local search for feasible repaired solutions; disabled by default.onIteration(IterationCallback<S> callback) Sets the callback invoked after each completed iteration; disabled by default.operatorSelector(OperatorSelector<S> operatorSelector) Sets the operator selector, replacing the default uniform random selector.randomGenerator(RandomGenerator randomGenerator) Sets the required source of randomness.visitedSolutionTracker(VisitedSolutionTracker<S> visitedSolutionTracker) Sets the tracker used to identify accepted solution revisits.
-
Method Details
-
randomGenerator
Sets the required source of randomness.- Parameters:
randomGenerator- the random generator used by the search- Returns:
- this builder
- Throws:
NullPointerException- ifrandomGeneratoris null
-
addDestroyOperator
Appends a destroy operator nameddestroy-<index>; insertion order defines its index.- Parameters:
destroyOperator- the destroy operator to append- Returns:
- this builder
- Throws:
NullPointerException- ifdestroyOperatoris null
-
addDestroyOperator
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 namedestroyOperator- the destroy operator to append- Returns:
- this builder
- Throws:
NullPointerException- ifnameordestroyOperatoris null
-
addRepairOperator
Appends a repair operator namedrepair-<index>; insertion order defines its index.- Parameters:
repairOperator- the repair operator to append- Returns:
- this builder
- Throws:
NullPointerException- ifrepairOperatoris null
-
addRepairOperator
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 namerepairOperator- the repair operator to append- Returns:
- this builder
- Throws:
NullPointerException- ifnameorrepairOperatoris null
-
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- ifoperatorSelectoris null
-
collectStatistics
Enables or disables statistics collection.- Parameters:
collectStatistics- whether to retain full histories and outcome counts;falseby default- Returns:
- this builder
-
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- ifvisitedSolutionTrackeris null
-
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- iflocalSearchis null
-
onIteration
Sets the callback invoked after each completed iteration; disabled by default.- Parameters:
callback- the synchronous callback, shared across runs- Returns:
- this builder
- Throws:
NullPointerException- ifcallbackis null
-
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 configuredIllegalStateException- if either operator list is emptyIllegalArgumentException- if an operator name is blank or duplicated within its group, or the selector rejects the operator counts
-