Class SearchStatistics

java.lang.Object
org.ddolib.common.solver.stat.SearchStatistics
Direct Known Subclasses:
AstarStats, DdoStats

public abstract class SearchStatistics extends Object
Class representing the statistics of a search process in a solver.

This class tracks various metrics such as runtime, number of iterations, incumbent value, and optimality gap. It is designed to be immutable-like, where update methods return a new instance with the updated value.

It represents the search statistics of a solver. Subclasses override the update methods to return their specific type via covariant return types.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double
    Best lower bound on the optimal value proved so far (the problems are minimized).
    protected long
    Current time of the search (in milliseconds).
    protected int
    Maximum size reached by the search frontier.
    protected double
    Best optimality gap reached so far.
    protected double
    Value of the best solution found so far (incumbent).
    protected int
    Iteration during which the last gap improvement was found.
    protected int
    Iteration during which the last improvement was found.
    protected long
    Time at which the last improvement was found (in milliseconds).
    protected int
    Number of nodes pruned because their state is dominated by the state of another node.
    protected long
    Number of nodes expanded so far (nodes whose successors were computed).
    protected int
    Number of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.
    protected long
    Number of nodes generated so far (successors computed, before any pruning).
    protected int
    Total number of iterations performed.
    protected double
    Value of the previous incumbent found.
    protected double
    Relative improvement of the incumbent value.
    protected final long
    Start time of the search (in milliseconds).
    protected SearchStatus
    Current status of the search.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SearchStatistics(long startTime, double initValue)
    Constructs a new SearchStatistics instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    addNbDominancePruning(int nbPruning)
    Creates and returns a copy of this statistics instance with additional nodes pruned by the dominance, for instance those pruned during the compilation of a decision diagram.
    Creates and returns a copy of this statistics instance with additional nodes pruned by the fast lower bound, for instance those pruned during the compilation of a decision diagram.
    addNodeCounts(long nbExpanded, long nbGenerated)
    Returns a new SearchStatistics instance with the given numbers of expanded and generated nodes added to the current ones.
    double
    Returns the best lower bound on the optimal value proved so far (all the problems are minimized).
    Creates and returns a copy of this statistics instance.
    protected abstract SearchStatistics
    Creates a new instance of the specific subclass with initial values.
    long
    Returns the current time recorded in these statistics.
    int
    Returns the maximum size reached by the search frontier during the process.
    double
    gap()
    Returns the current optimality gap.
    Creates and returns a copy of this statistics instance with one more node pruned by the dominance.
    Creates and returns a copy of this statistics instance with one more node pruned by the fast lower bound.
    Returns a new SearchStatistics instance with the iteration count incremented by one.
    double
    Returns the value of the best solution found so far (incumbent).
    int
    Returns the iteration number during which the last gap improvement was found.
    int
    Returns the iteration number during which the last improvement was found.
    long
    Returns the time at which the last improvement was found.
    int
    Returns the number of nodes pruned because their state is dominated by the state of another node.
    long
    Returns the number of nodes expanded so far: the nodes whose successors were computed.
    int
    Returns the number of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.
    long
    Returns the number of nodes generated so far: one per successor computed when a node is expanded (one per transition applied), before any pruning by the bound, the dominance or a duplicate.
    int
    Returns the total number of iterations performed by the search.
    double
    Returns the value of the previous incumbent found before the current one.
    double
    Returns the relative improvement of the last incumbent update in percent.
    long
    Returns the total runtime of the search.
    Returns the current status of the search.
     
    updateBestBound(double bound)
    Returns a new SearchStatistics instance with an updated best bound.
    updateFrontierMaxSize(int frontierSize)
    Returns a new SearchStatistics instance with an updated maximum frontier size.
    updateGap(double gap)
    Returns a new SearchStatistics instance with an updated optimality gap.
    updateIncumbent(double incumbent, double gap)
    Returns a new SearchStatistics instance with an updated incumbent value and gap.
    updateNodeCounts(long nbExpanded, long nbGenerated)
    Returns a new SearchStatistics instance with the given numbers of expanded and generated nodes (totals since the beginning of the search).
    Returns a new SearchStatistics instance with an updated search status.
    updateTime(long time)
    Returns a new SearchStatistics instance with an updated current time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _startTime

      protected final long _startTime
      Start time of the search (in milliseconds).
    • _lastTimeOfImprovement

      protected long _lastTimeOfImprovement
      Time at which the last improvement was found (in milliseconds).
    • _currentTime

      protected long _currentTime
      Current time of the search (in milliseconds).
    • _status

      protected SearchStatus _status
      Current status of the search.
    • _nbIterations

      protected int _nbIterations
      Total number of iterations performed.
    • _lastIterationOfImprovement

      protected int _lastIterationOfImprovement
      Iteration during which the last improvement was found.
    • _incumbent

      protected double _incumbent
      Value of the best solution found so far (incumbent).
    • _prevIncumbent

      protected double _prevIncumbent
      Value of the previous incumbent found.
    • _gap

      protected double _gap
      Best optimality gap reached so far.
    • _bestBound

      protected double _bestBound
      Best lower bound on the optimal value proved so far (the problems are minimized).
    • _nbExpandedNodes

      protected long _nbExpandedNodes
      Number of nodes expanded so far (nodes whose successors were computed).
    • _nbGeneratedNodes

      protected long _nbGeneratedNodes
      Number of nodes generated so far (successors computed, before any pruning).
    • _frontierMaxSize

      protected int _frontierMaxSize
      Maximum size reached by the search frontier.
    • _relativeImprovement

      protected double _relativeImprovement
      Relative improvement of the incumbent value.
    • _lastIterationOfGapImprovement

      protected int _lastIterationOfGapImprovement
      Iteration during which the last gap improvement was found.
    • _nbFastLowerBoundPruning

      protected int _nbFastLowerBoundPruning
      Number of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.
    • _nbDominancePruning

      protected int _nbDominancePruning
      Number of nodes pruned because their state is dominated by the state of another node.
  • Constructor Details

    • SearchStatistics

      public SearchStatistics(long startTime, double initValue)
      Constructs a new SearchStatistics instance.
      Parameters:
      startTime - the start time of the search (in milliseconds)
      initValue - the initial value for the incumbent
  • Method Details

    • createSpecificInstance

      protected abstract SearchStatistics createSpecificInstance()
      Creates a new instance of the specific subclass with initial values. This is used by the copy method to maintain the correct type.
      Returns:
      a new instance of the specific subclass
    • lastTimeOfImprovement

      public long lastTimeOfImprovement()
      Returns the time at which the last improvement was found.
      Returns:
      the last time of improvement (in milliseconds)
    • runtime

      public long runtime()
      Returns the total runtime of the search.
      Returns:
      the runtime (in milliseconds)
    • currentTime

      public long currentTime()
      Returns the current time recorded in these statistics.
      Returns:
      the current time (in milliseconds)
    • nbIterations

      public int nbIterations()
      Returns the total number of iterations performed by the search.
      Returns:
      the number of iterations
    • lastIterationOfImprovement

      public int lastIterationOfImprovement()
      Returns the iteration number during which the last improvement was found.
      Returns:
      the last iteration of improvement
    • lastIterationOfGapImprovement

      public int lastIterationOfGapImprovement()
      Returns the iteration number during which the last gap improvement was found.
      Returns:
      the last iteration of gap improvement
    • gap

      public double gap()
      Returns the current optimality gap.
      Returns:
      the gap (percentage)
    • nbExpandedNodes

      public long nbExpandedNodes()
      Returns the number of nodes expanded so far: the nodes whose successors were computed. For A*, AWA*, ACS and DFS, a node removed from the open list but then discarded (dominated, already closed or pruned by the bound) is not expanded. For the DD-based solvers (DDO, LNS, exact), it is the number of DD nodes whose children were generated, over all the compiled DDs (restricted and relaxed).

      With nbGeneratedNodes(), it allows to compare the search effort of different solvers, for instance with the expanded and generated counts of DIDP.

      Returns:
      the number of expanded nodes
    • nbGeneratedNodes

      public long nbGeneratedNodes()
      Returns the number of nodes generated so far: one per successor computed when a node is expanded (one per transition applied), before any pruning by the bound, the dominance or a duplicate. For the DD-based solvers, a transition leading to an existing node of the next layer is also counted. The root is not counted.
      Returns:
      the number of generated nodes
    • bestBound

      public double bestBound()
      Returns the best lower bound on the optimal value proved so far (all the problems are minimized). It is known even when the search is stopped before the end, for instance by a time limit, and does not require an incumbent.
      Returns:
      the best lower bound on the optimal value
    • incumbent

      public double incumbent()
      Returns the value of the best solution found so far (incumbent).
      Returns:
      the incumbent value
    • prevIncumbent

      public double prevIncumbent()
      Returns the value of the previous incumbent found before the current one.
      Returns:
      the previous incumbent value
    • status

      public SearchStatus status()
      Returns the current status of the search.
      Returns:
      the SearchStatus
    • frontierMaxSize

      public int frontierMaxSize()
      Returns the maximum size reached by the search frontier during the process.
      Returns:
      the maximum frontier size
    • relativeImprovement

      public double relativeImprovement()
      Returns the relative improvement of the last incumbent update in percent.
      Returns:
      the relative improvement in percent
    • nbFastLowerBoundPruning

      public int nbFastLowerBoundPruning()
      Returns the number of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.
      Returns:
      the number of nodes pruned by the fast lower bound
    • nbDominancePruning

      public int nbDominancePruning()
      Returns the number of nodes pruned because their state is dominated by the state of another node.
      Returns:
      the number of nodes pruned by the dominance
    • copy

      public SearchStatistics copy()
      Creates and returns a copy of this statistics instance.
      Returns:
      a copy of the current statistics
    • updateIncumbent

      public SearchStatistics updateIncumbent(double incumbent, double gap)
      Returns a new SearchStatistics instance with an updated incumbent value and gap.
      Parameters:
      incumbent - the new incumbent value
      gap - the new optimality gap
      Returns:
      a new instance with updated incumbent and gap
    • updateStatus

      public SearchStatistics updateStatus(SearchStatus status)
      Returns a new SearchStatistics instance with an updated search status.
      Parameters:
      status - the new SearchStatus
      Returns:
      a new instance with the updated status
    • incrementNbIter

      public SearchStatistics incrementNbIter()
      Returns a new SearchStatistics instance with the iteration count incremented by one.
      Returns:
      a new instance with incremented iterations
    • updateFrontierMaxSize

      public SearchStatistics updateFrontierMaxSize(int frontierSize)
      Returns a new SearchStatistics instance with an updated maximum frontier size.
      Parameters:
      frontierSize - the current frontier size to potentially update the maximum
      Returns:
      a new instance with the updated maximum frontier size
    • updateGap

      public SearchStatistics updateGap(double gap)
      Returns a new SearchStatistics instance with an updated optimality gap.
      Parameters:
      gap - the new gap value
      Returns:
      a new instance with the updated gap
    • updateBestBound

      public SearchStatistics updateBestBound(double bound)
      Returns a new SearchStatistics instance with an updated best bound. Any valid lower bound on the optimal value can be given: the best one seen so far is kept.
      Parameters:
      bound - a lower bound on the optimal value
      Returns:
      a new instance with the updated best bound
    • updateNodeCounts

      public SearchStatistics updateNodeCounts(long nbExpanded, long nbGenerated)
      Returns a new SearchStatistics instance with the given numbers of expanded and generated nodes (totals since the beginning of the search).
      Parameters:
      nbExpanded - the number of expanded nodes
      nbGenerated - the number of generated nodes
      Returns:
      a new instance with the updated node counts
    • addNodeCounts

      public SearchStatistics addNodeCounts(long nbExpanded, long nbGenerated)
      Returns a new SearchStatistics instance with the given numbers of expanded and generated nodes added to the current ones.
      Parameters:
      nbExpanded - the number of expanded nodes to add
      nbGenerated - the number of generated nodes to add
      Returns:
      a new instance with the updated node counts
    • updateTime

      public SearchStatistics updateTime(long time)
      Returns a new SearchStatistics instance with an updated current time.
      Parameters:
      time - the current time (in milliseconds)
      Returns:
      a new instance with the updated time
    • incrementNbFastLowerBoundPruning

      public SearchStatistics incrementNbFastLowerBoundPruning()
      Creates and returns a copy of this statistics instance with one more node pruned by the fast lower bound.
      Returns:
      a new instance with the incremented number of fast lower bound prunings
    • incrementNbDominancePruning

      public SearchStatistics incrementNbDominancePruning()
      Creates and returns a copy of this statistics instance with one more node pruned by the dominance.
      Returns:
      a new instance with the incremented number of dominance prunings
    • addNbFastLowerBoundPruning

      public SearchStatistics addNbFastLowerBoundPruning(int nbPruning)
      Creates and returns a copy of this statistics instance with additional nodes pruned by the fast lower bound, for instance those pruned during the compilation of a decision diagram.
      Parameters:
      nbPruning - the number of nodes pruned by the fast lower bound to add
      Returns:
      a new instance with the updated number of fast lower bound prunings
    • addNbDominancePruning

      public SearchStatistics addNbDominancePruning(int nbPruning)
      Creates and returns a copy of this statistics instance with additional nodes pruned by the dominance, for instance those pruned during the compilation of a decision diagram.
      Parameters:
      nbPruning - the number of nodes pruned by the dominance to add
      Returns:
      a new instance with the updated number of dominance prunings
    • toString

      public String toString()
      Overrides:
      toString in class Object