public override bool PrepareNextPath()
        {
            if (_choiceIndex != _valueCount.Count - 1)
            {
                throw new NondeterminismException();
            }

            // Reset the choice counter as each path starts from the beginning
            _choiceIndex = -1;

            // If this is the first path of the state, we definitely have to enumerate it
            if (_firstPath)
            {
                _firstPath = false;
                return(true);
            }

            // Let's go through the entire stack to determine what we have to do next
            while (_chosenValues.Count > 0)
            {
                // Remove the value we've chosen last -- we've already chosen it, so we're done with it
                var chosenValue = _chosenValues.Remove();

                // If we have at least one other value to choose, let's do that next
                if (_valueCount.Peek() > chosenValue.OptionIndex + 1)
                {
                    var previousProbability = GetProbabilityUntilIndex(_valueCount.Count - 2);
                    var valueCount          = _valueCount.Peek();

                    var newChosenValue =
                        new LtmcChosenValue
                    {
                        OptionIndex = chosenValue.OptionIndex + 1,
                        Probability = previousProbability / valueCount                                 //placeholder value (for non deterministic choice)
                    };
                    _chosenValues.Push(newChosenValue);
                    return(true);
                }

                // Otherwise, we've chosen all values of the last choice, so we're done with it
                _valueCount.Remove();
            }

            // If we reach this point, we know that we've chosen all values of all choices, so there are no further paths
            return(false);
        }
Ejemplo n.º 2
0
        public override bool PrepareNextPath()
        {
            if (_choiceIndex != _valueCount.Count - 1)
            {
                throw new NondeterminismException();
            }

            // Reset the choice counter as each path starts from the beginning
            _choiceIndex = -1;

            // If this is the first path of the state, we definitely have to enumerate it
            if (_firstPath)
            {
                _firstPath = false;
                return(true);
            }

            // Let's go through the entire stack to determine what we have to do next
            while (_chosenValues.Count > 0)
            {
                // Remove the value we've chosen last -- we've already chosen it, so we're done with it
                var chosenValue = _chosenValues.Remove();

                // If we have at least one other value to choose, let's do that next
                if (_valueCount.Peek() > chosenValue.OptionIndex + 1)
                {
                    _continuationId = chosenValue.ContinuationId + 1;

                    var newChosenValue =
                        new LtmdpChosenValue
                    {
                        OptionIndex    = chosenValue.OptionIndex + 1,
                        ContinuationId = _continuationId,
                    };
                    _chosenValues.Push(newChosenValue);
                    return(true);
                }

                // Otherwise, we've chosen all values of the last choice, so we're done with it
                _valueCount.Remove();
            }

            AssertThatDatastructureIsIntact();

            // If we reach this point, we know that we've chosen all values of all choices, so there are no further paths
            return(false);
        }