Class RouletteWheelOperatorSelector<S extends Solution<S>>
java.lang.Object
io.github.nhtc2005.alns.selection.RouletteWheelOperatorSelector<S>
- Type Parameters:
S- the solution type
- All Implemented Interfaces:
OperatorSelector<S>
public final class RouletteWheelOperatorSelector<S extends Solution<S>>
extends Object
implements OperatorSelector<S>
Selects destroy and repair operators independently in proportion to their weights.
For each operator group, \(P(i) = w_i / \sum_j w_j\). All weights start at 1; if all weights in a group are zero, selection is uniform. Feedback updates only the selected weights:
\[ w_i' = \theta w_i + (1 - \theta) s. \]
Here \(\theta\) is decay, and \(s\) is the outcome score, or the rejected-outcome
score scores[3] when reward is ineligible. Instances hold mutable weights and must not be
shared by concurrent runs.
-
Constructor Summary
ConstructorsConstructorDescriptionRouletteWheelOperatorSelector(int destroyOperatorCount, int repairOperatorCount, double[] scores, double decay) Creates a selector for fixed operator counts. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetDecay()Returns the configured weight retention factor.intReturns the configured number of destroy operators.double[]Returns a copy of destroy weights indexed by operator.intReturns the configured number of repair operators.double[]Returns a copy of repair weights indexed by operator.double[]Returns a copy of the scores inBEST,BETTER,ACCEPTED,REJECTEDorder.voidreset()Restores all operator weights to 1.select(OperatorSelectionContext<S> context) Selects operator indices without modifying the solutions in the context.voidupdate(OperatorSelectionFeedback<S> feedback) Receives the outcome after each iteration to update selection state.voidvalidateOperatorCounts(int destroyOperatorCount, int repairOperatorCount) Validates the operator counts when the solver is built.
-
Constructor Details
-
RouletteWheelOperatorSelector
public RouletteWheelOperatorSelector(int destroyOperatorCount, int repairOperatorCount, double[] scores, double decay) Creates a selector for fixed operator counts.- Parameters:
destroyOperatorCount- the positive number of destroy operatorsrepairOperatorCount- the positive number of repair operatorsscores- four finite non-negative scores inBEST,BETTER,ACCEPTED,REJECTEDorder; copied on constructiondecay- the finite weight retention factor in[0, 1]- Throws:
IllegalArgumentException- if any numeric parameter or score count is invalidNullPointerException- ifscoresis null
-
-
Method Details
-
validateOperatorCounts
public void validateOperatorCounts(int destroyOperatorCount, int repairOperatorCount) Validates the operator counts when the solver is built.Selectors with fixed counts must check that both counts match their configuration. The default implementation does nothing.
- Specified by:
validateOperatorCountsin interfaceOperatorSelector<S extends Solution<S>>- Parameters:
destroyOperatorCount- the positive number of configured destroy operatorsrepairOperatorCount- the positive number of configured repair operators- Throws:
IllegalArgumentException- if either count differs from this selector's configured count
-
select
Description copied from interface:OperatorSelectorSelects operator indices without modifying the solutions in the context.- Specified by:
selectin interfaceOperatorSelector<S extends Solution<S>>- Parameters:
context- the non-null search context- Returns:
- a non-null selection with zero-based indices within the configured operator lists
-
update
Receives the outcome after each iteration to update selection state.The candidate solution must not be modified. The default implementation does nothing.
- Specified by:
updatein interfaceOperatorSelector<S extends Solution<S>>- Parameters:
feedback- the non-null outcome and reward eligibility of the selected operator pair- Throws:
IndexOutOfBoundsException- if either selected operator index is out of range
-
reset
public void reset()Restores all operator weights to 1.- Specified by:
resetin interfaceOperatorSelector<S extends Solution<S>>
-
getDestroyOperatorCount
public int getDestroyOperatorCount()Returns the configured number of destroy operators.- Returns:
- the configured number of destroy operators
-
getRepairOperatorCount
public int getRepairOperatorCount()Returns the configured number of repair operators.- Returns:
- the configured number of repair operators
-
getScores
public double[] getScores()Returns a copy of the scores inBEST,BETTER,ACCEPTED,REJECTEDorder.- Returns:
- a copy of the scores in
BEST,BETTER,ACCEPTED,REJECTEDorder
-
getDecay
public double getDecay()Returns the configured weight retention factor.- Returns:
- the configured weight retention factor
-
getDestroyOperatorWeights
public double[] getDestroyOperatorWeights()Returns a copy of destroy weights indexed by operator.- Returns:
- a copy of destroy weights indexed by operator
-
getRepairOperatorWeights
public double[] getRepairOperatorWeights()Returns a copy of repair weights indexed by operator.- Returns:
- a copy of repair weights indexed by operator
-