Class AlnsStatistics

java.lang.Object
io.github.nhtc2005.alns.core.AlnsStatistics

public final class AlnsStatistics extends Object
Stores objective histories, iteration runtimes, and outcome counts from one ALNS search.

Enabled histories and runtimes contain an entry for the initial solution followed by one entry per completed iteration, so index k corresponds to iteration k; the initial runtime is zero. Data getters throw IllegalStateException when collection is disabled. Outcomes are counted independently of reward eligibility, and each operator in a selected pair receives the pair's outcome. Retaining full histories uses memory proportional to iteration count.

  • Method Details

    • isEnabled

      public boolean isEnabled()
      Returns whether statistics collection was enabled.
      Returns:
      whether statistics collection was enabled
    • getDestroyOperatorNames

      public List<String> getDestroyOperatorNames()
      Returns the destroy operator names; position i names destroy operator i.
      Returns:
      an unmodifiable list of destroy operator names
      Throws:
      IllegalStateException - if statistics collection is disabled
    • getRepairOperatorNames

      public List<String> getRepairOperatorNames()
      Returns the repair operator names; position i names repair operator i.
      Returns:
      an unmodifiable list of repair operator names
      Throws:
      IllegalStateException - if statistics collection is disabled
    • getCurrentObjectiveValues

      public List<Double> getCurrentObjectiveValues()
      Returns an unmodifiable snapshot of current objectives, including the initial value.
      Returns:
      an unmodifiable snapshot of current objectives, including the initial value
      Throws:
      IllegalStateException - if statistics collection is disabled
    • getBestObjectiveValues

      public List<Double> getBestObjectiveValues()
      Returns an unmodifiable snapshot of best objectives, including the initial value.
      Returns:
      an unmodifiable snapshot of best objectives, including the initial value
      Throws:
      IllegalStateException - if statistics collection is disabled
    • getIterationRuntimesNanos

      public List<Long> getIterationRuntimesNanos()
      Returns an unmodifiable snapshot of iteration runtimes in nanoseconds, including a zero entry for the initial solution.

      Timing includes selection, operators, local search, acceptance, tracking, and selector feedback, but excludes stopping checks, statistics collection, and iteration callbacks.

      Returns:
      an unmodifiable snapshot of iteration runtimes in nanoseconds
      Throws:
      IllegalStateException - if statistics collection is disabled
    • getDestroyOperatorCount

      public long getDestroyOperatorCount(int operatorIndex, SolutionStatus status)
      Returns how often a destroy operator participated in the specified outcome.
      Parameters:
      operatorIndex - the zero-based operator index
      status - the outcome to count
      Returns:
      the number of iterations with that operator and outcome
      Throws:
      IllegalStateException - if statistics collection is disabled
      IndexOutOfBoundsException - if the index is invalid
      NullPointerException - if status is null
    • getRepairOperatorCount

      public long getRepairOperatorCount(int operatorIndex, SolutionStatus status)
      Returns how often a repair operator participated in the specified outcome.
      Parameters:
      operatorIndex - the zero-based operator index
      status - the outcome to count
      Returns:
      the number of iterations with that operator and outcome
      Throws:
      IllegalStateException - if statistics collection is disabled
      IndexOutOfBoundsException - if the index is invalid
      NullPointerException - if status is null
    • getStatusCount

      public long getStatusCount(SolutionStatus status)
      Returns the total number of iterations with the specified outcome.
      Parameters:
      status - the outcome to count
      Returns:
      the outcome count
      Throws:
      IllegalStateException - if statistics collection is disabled
      NullPointerException - if status is null