public void Advance()
    {
        var r = _runningHypotheses.MayDequeue().ForceGetValue();

        if (r.State == null)
        {
            _unexploredHypotheses.MoveNext();
            var newHypothesis   = _unexploredHypotheses.Current;
            var unexploredPrior = r.Prior - newHypothesis.Prior;
            _runningHypotheses.Enqueue(newHypothesis);
            _runningHypotheses.Enqueue(new Hypothesis(unexploredPrior, null, 1));
            return;
        }

        var s2     = r.State.Advanced(100);
        var r2     = new Hypothesis(r.Prior, s2, r.MaxSeenElapsedSteps > s2.ElapsedSteps ? r.MaxSeenElapsedSteps : s2.ElapsedSteps);
        var output = r2.State.MayResult;

        if (output.HasValue)
        {
            _finishedHypotheses.Add(r2);
        }
        else if (!s2.IsStuckInALoop)
        {
            _runningHypotheses.Enqueue(r2);
        }
    }
Example #2
0
    public IEnumerator <T> GetEnumerator()
    {
        var clone = new AscendingPriorityQueue <T>(_comparer, _items);

        while (true)
        {
            var x = clone.MayDequeue();
            if (!x.HasValue)
            {
                yield break;
            }
            yield return(x.ForceGetValue());
        }
    }