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 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 operators
      repairOperatorCount - the positive number of repair operators
      scores - four finite non-negative scores in BEST, BETTER, ACCEPTED, REJECTED order; copied on construction
      decay - the finite weight retention factor in [0, 1]
      Throws:
      IllegalArgumentException - if any numeric parameter or score count is invalid
      NullPointerException - if scores is 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:
      validateOperatorCounts in interface OperatorSelector<S extends Solution<S>>
      Parameters:
      destroyOperatorCount - the positive number of configured destroy operators
      repairOperatorCount - the positive number of configured repair operators
      Throws:
      IllegalArgumentException - if either count differs from this selector's configured count
    • select

      public OperatorSelection select(OperatorSelectionContext<S> context)
      Description copied from interface: OperatorSelector
      Selects operator indices without modifying the solutions in the context.
      Specified by:
      select in interface OperatorSelector<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

      public void update(OperatorSelectionFeedback<S> feedback)
      Receives the outcome after each iteration to update selection state.

      The candidate solution must not be modified. The default implementation does nothing.

      Specified by:
      update in interface OperatorSelector<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:
      reset in interface OperatorSelector<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 in BEST, BETTER, ACCEPTED, REJECTED order.
      Returns:
      a copy of the scores in BEST, BETTER, ACCEPTED, REJECTED order
    • 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