File tree Expand file tree Collapse file tree
Alligator.Solver/Algorithms Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ namespace Alligator.Solver.Algorithms
44{
55 internal class SearchManager : ISearchManager
66 {
7+ private const int TimeBudgetCheckInterval = 1024 ;
8+
79 private readonly Stopwatch stopwatch = new ( ) ;
8- private readonly long timeLimitMs ;
10+ private readonly TimeSpan timeBudget ;
911 private int nodeCount ;
1012
1113 public int MaxDepth { get ; }
@@ -15,23 +17,23 @@ internal class SearchManager : ISearchManager
1517 public SearchManager ( int maxDepth , TimeSpan ? timeBudget = null )
1618 {
1719 MaxDepth = maxDepth ;
18- timeLimitMs = ( long ) ( timeBudget ? . TotalMilliseconds ?? 0 ) ;
20+ this . timeBudget = timeBudget ?? TimeSpan . Zero ;
1921 }
2022
2123 public void StartSearch ( )
2224 {
2325 nodeCount = 0 ;
2426 IsAborted = false ;
25- if ( timeLimitMs > 0 )
27+ if ( timeBudget > TimeSpan . Zero )
2628 {
2729 stopwatch . Restart ( ) ;
2830 }
2931 }
3032
3133 public void CheckTimeBudget ( )
3234 {
33- if ( timeLimitMs > 0 && ( ++ nodeCount & 0x3FF ) == 0
34- && stopwatch . ElapsedMilliseconds >= timeLimitMs )
35+ if ( timeBudget > TimeSpan . Zero && ++ nodeCount % TimeBudgetCheckInterval == 0
36+ && stopwatch . Elapsed >= timeBudget )
3537 {
3638 IsAborted = true ;
3739 }
You can’t perform that action at this time.
0 commit comments