public override int HandleChoice(int valueCount) { ++_choiceIndex; // If we have a preselected value that we should choose for the current path, return it var chosenValuesMaxIndex = _chosenValues.Count - 1; if (_choiceIndex <= chosenValuesMaxIndex) { return(_chosenValues[_choiceIndex].OptionIndex); } // We haven't encountered this choice before; store the value count and return the first value _valueCount.Push(valueCount); var newChosenValue = new LtmcChosenValue { OptionIndex = 0, Probability = GetProbabilityOfPreviousPath() / valueCount //placeholder value (for non deterministic choice) }; _chosenValues.Push(newChosenValue); return(0); }
public override int HandleChoice(int valueCount) { ++_choiceIndex; // If we have a preselected value that we should choose for the current path, return it var chosenValuesMaxIndex = _chosenValues.Count - 1; if (_choiceIndex <= chosenValuesMaxIndex) { return(_chosenValues[_choiceIndex].OptionIndex); } // We haven't encountered this choice before; store the value count and return the first value _valueCount.Push(valueCount); var oldContinuationId = _continuationId; _continuationId = _nextFreeContinuationId; var newChosenValue = new LtmdpChosenValue { OptionIndex = 0, ContinuationId = _continuationId, Probability = GetProbabilityOfPreviousPath() // no probability is changed for this choice }; _chosenValues.Push(newChosenValue); _nextFreeContinuationId = _nextFreeContinuationId + valueCount; LtmdpStepGraph.NonDeterministicSplit(oldContinuationId, _continuationId, _continuationId + valueCount - 1); return(0); }
public override int HandleChoice(int valueCount) { ++_choiceIndex; // If we have a preselected value that we should choose for the current path, return it if (_choiceIndex < _chosenValues.Count) { return(_chosenValues[_choiceIndex]); } // We haven't encountered this choice before; store the value count and return the first value _valueCount.Push(valueCount); _chosenValues.Push(0); return(0); }
public override int HandleChoice(int valueCount) { ++_choiceIndex; // If we have a preselected value that we should choose for the current path, return it var chosenValuesMaxIndex = _chosenValues.Count - 1; if (_choiceIndex <= chosenValuesMaxIndex) { return(_chosenValues[_choiceIndex].OptionIndex); } // We haven't encountered this choice before; store the value count and return the first value _valueCount.Push(valueCount); var oldContinuationId = _continuationId; _continuationId = _nextFreeContinuationId; var newChosenValue = new LtmdpChosenValue { OptionIndex = 0, ContinuationId = _continuationId, }; _chosenValues.Push(newChosenValue); _nextFreeContinuationId = _nextFreeContinuationId + valueCount; LtmdpStepGraph.NonDeterministicSplit(oldContinuationId, _continuationId, _continuationId + valueCount - 1); // set default values var defaultValue = 1.0; for (var i = 0; i < valueCount; i++) { LtmdpStepGraph.SetProbabilityOfContinuationId(_continuationId + i, defaultValue); } return(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 + 1) { _chosenValues.Push(chosenValue + 1); 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); }