Package org.ddolib.common.solver.stat
Class SearchStatistics
java.lang.Object
org.ddolib.common.solver.stat.SearchStatistics
- Direct Known Subclasses:
AstarStats,DdoStats
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
FieldsModifier and TypeFieldDescriptionprotected doubleBest lower bound on the optimal value proved so far (the problems are minimized).protected longCurrent time of the search (in milliseconds).protected intMaximum size reached by the search frontier.protected doubleBest optimality gap reached so far.protected doubleValue of the best solution found so far (incumbent).protected intIteration during which the last gap improvement was found.protected intIteration during which the last improvement was found.protected longTime at which the last improvement was found (in milliseconds).protected intNumber of nodes pruned because their state is dominated by the state of another node.protected longNumber of nodes expanded so far (nodes whose successors were computed).protected intNumber of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.protected longNumber of nodes generated so far (successors computed, before any pruning).protected intTotal number of iterations performed.protected doubleValue of the previous incumbent found.protected doubleRelative improvement of the incumbent value.protected final longStart time of the search (in milliseconds).protected SearchStatusCurrent status of the search. -
Constructor Summary
ConstructorsConstructorDescriptionSearchStatistics(long startTime, double initValue) Constructs a new SearchStatistics instance. -
Method Summary
Modifier and TypeMethodDescriptionaddNbDominancePruning(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.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.addNodeCounts(long nbExpanded, long nbGenerated) Returns a new SearchStatistics instance with the given numbers of expanded and generated nodes added to the current ones.doubleReturns the best lower bound on the optimal value proved so far (all the problems are minimized).copy()Creates and returns a copy of this statistics instance.protected abstract SearchStatisticsCreates a new instance of the specific subclass with initial values.longReturns the current time recorded in these statistics.intReturns the maximum size reached by the search frontier during the process.doublegap()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.doubleReturns the value of the best solution found so far (incumbent).intReturns the iteration number during which the last gap improvement was found.intReturns the iteration number during which the last improvement was found.longReturns the time at which the last improvement was found.intReturns the number of nodes pruned because their state is dominated by the state of another node.longReturns the number of nodes expanded so far: the nodes whose successors were computed.intReturns the number of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far.longReturns 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.intReturns the total number of iterations performed by the search.doubleReturns the value of the previous incumbent found before the current one.doubleReturns the relative improvement of the last incumbent update in percent.longruntime()Returns the total runtime of the search.status()Returns the current status of the search.toString()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).updateStatus(SearchStatus status) Returns a new SearchStatistics instance with an updated search status.updateTime(long time) Returns a new SearchStatistics instance with an updated current time.
-
Field Details
-
_startTime
protected final long _startTimeStart time of the search (in milliseconds). -
_lastTimeOfImprovement
protected long _lastTimeOfImprovementTime at which the last improvement was found (in milliseconds). -
_currentTime
protected long _currentTimeCurrent time of the search (in milliseconds). -
_status
Current status of the search. -
_nbIterations
protected int _nbIterationsTotal number of iterations performed. -
_lastIterationOfImprovement
protected int _lastIterationOfImprovementIteration during which the last improvement was found. -
_incumbent
protected double _incumbentValue of the best solution found so far (incumbent). -
_prevIncumbent
protected double _prevIncumbentValue of the previous incumbent found. -
_gap
protected double _gapBest optimality gap reached so far. -
_bestBound
protected double _bestBoundBest lower bound on the optimal value proved so far (the problems are minimized). -
_nbExpandedNodes
protected long _nbExpandedNodesNumber of nodes expanded so far (nodes whose successors were computed). -
_nbGeneratedNodes
protected long _nbGeneratedNodesNumber of nodes generated so far (successors computed, before any pruning). -
_frontierMaxSize
protected int _frontierMaxSizeMaximum size reached by the search frontier. -
_relativeImprovement
protected double _relativeImprovementRelative improvement of the incumbent value. -
_lastIterationOfGapImprovement
protected int _lastIterationOfGapImprovementIteration during which the last gap improvement was found. -
_nbFastLowerBoundPruning
protected int _nbFastLowerBoundPruningNumber of nodes pruned because their fast lower bound shows that they cannot improve the best solution found so far. -
_nbDominancePruning
protected int _nbDominancePruningNumber 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
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 theexpandedandgeneratedcounts 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.- When the search is
SearchStatus.OPTIMAL, it is the incumbent value. - When the problem is
SearchStatus.UNSAT, it isDouble.POSITIVE_INFINITY. - When no bound is known, it is
Double.NEGATIVE_INFINITY.
- Returns:
- the best lower bound on the optimal value
- When the search is
-
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
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
Creates and returns a copy of this statistics instance.- Returns:
- a copy of the current statistics
-
updateIncumbent
Returns a new SearchStatistics instance with an updated incumbent value and gap.- Parameters:
incumbent- the new incumbent valuegap- the new optimality gap- Returns:
- a new instance with updated incumbent and gap
-
updateStatus
Returns a new SearchStatistics instance with an updated search status.- Parameters:
status- the newSearchStatus- Returns:
- a new instance with the updated status
-
incrementNbIter
Returns a new SearchStatistics instance with the iteration count incremented by one.- Returns:
- a new instance with incremented iterations
-
updateFrontierMaxSize
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
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
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
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 nodesnbGenerated- the number of generated nodes- Returns:
- a new instance with the updated node counts
-
addNodeCounts
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 addnbGenerated- the number of generated nodes to add- Returns:
- a new instance with the updated node counts
-
updateTime
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
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
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
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
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
-