Class SegmentedRouletteWheelOperatorSelector<S extends Solution<S>>

java.lang.Object
io.github.nhtc2005.alns.selection.SegmentedRouletteWheelOperatorSelector<S>
Type Parameters:
S - the solution type
All Implemented Interfaces:
OperatorSelector<S>

public final class SegmentedRouletteWheelOperatorSelector<S extends Solution<S>> extends Object implements OperatorSelector<S>
Selects operators by weight and updates selected operators' weights after each fixed-length feedback segment.

Destroy and repair selection is independent, with \(P(i) = w_i / \sum_j w_j\) in each group. Weights start at 1; an all-zero group uses uniform selection. At a segment boundary:

\[ w_i' = \theta w_i + (1 - \theta) \frac{\Sigma_i}{n_i}. \]

Here \(\theta\) is decay, and \(\Sigma_i\) is the sum of scores credited to operator \(i\) in that segment, and \(n_i\) is its selection count. Ineligible feedback contributes the rejected-outcome score scores[3], counts as a selection, and advances the segment. Operators with no selections retain their weights. Segment scores and selection counts are cleared after updating. Instances hold mutable state and must not be shared by concurrent runs.

  • Constructor Details

    • SegmentedRouletteWheelOperatorSelector

      public SegmentedRouletteWheelOperatorSelector(int destroyOperatorCount, int repairOperatorCount, double[] scores, double decay, long segmentLength)
      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]
      segmentLength - the positive number of feedback updates per segment
      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
      ArithmeticException - if accumulated segment scores would become non-finite
    • reset

      public void reset()
      Restores all weights to 1 and clears segment scores, selection counts, and the segment counter.
      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
    • getSegmentLength

      public long getSegmentLength()
      Returns the number of feedback updates per segment.
      Returns:
      the number of feedback updates per segment
    • getIterationsInSegment

      public long getIterationsInSegment()
      Returns the number of feedback updates in the incomplete segment.
      Returns:
      the number of feedback updates in the incomplete segment
    • 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
    • getDestroyOperatorSegmentScores

      public double[] getDestroyOperatorSegmentScores()
      Returns a copy of accumulated destroy scores in the incomplete segment.
      Returns:
      a copy of accumulated destroy scores in the incomplete segment
    • getRepairOperatorSegmentScores

      public double[] getRepairOperatorSegmentScores()
      Returns a copy of accumulated repair scores in the incomplete segment.
      Returns:
      a copy of accumulated repair scores in the incomplete segment