/// <summary>
        ///   Visits the <paramref name="formula." />
        /// </summary>
        public override void VisitProbabilisticFormula(ProbabilitisticFormula formula)
        {
            _builder.Append("P { ");
            switch (formula.Comparator)
            {
            case ProbabilisticComparator.LowerThan:
                _builder.Append("< ");
                break;

            case ProbabilisticComparator.LowerEqual:
                _builder.Append("<= ");
                break;

            case ProbabilisticComparator.BiggerThan:
                _builder.Append("> ");
                break;

            case ProbabilisticComparator.BiggerEqual:
                _builder.Append(">= ");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            _builder.Append(formula.CompareToValue.ToString(CultureInfo.InvariantCulture));
            _builder.Append(" } [ ");
            Visit(formula.Operand);
            _builder.Append(" ]");
        }
Esempio n. 2
0
        internal override Probability CalculateProbability(Formula formulaToCheck)
        {
            var workaroundFormula = new ProbabilitisticFormula(formulaToCheck, ProbabilisticComparator.BiggerThan, 0.0);

            using (var fileResults = WriteFilesAndExecuteMrmc(workaroundFormula, true))
            {
                var resultEnumerator = File.ReadLines(fileResults.FilePath).GetEnumerator();

                var probability = 0.0;
                while (resultEnumerator.MoveNext())
                {
                    var result = resultEnumerator.Current;
                    if (!String.IsNullOrEmpty(result))
                    {
                        var parsed = MrmcProbabilityParser.Match(result);
                        if (parsed.Success)
                        {
                            var    state = Int32.Parse(parsed.Groups["state"].Value);
                            var    probabilityOfState = _initialStates[state];                          //index in mrmc is 1-based
                            double probabilityInState;
                            // Mrmc may return a probability in a state of PositiveInfinity. This is clearly undesired and might be because of a wrong probability matrix
                            if (parsed.Groups["probability"].Value == "inf")
                            {
                                probabilityInState = double.PositiveInfinity;
                            }
                            else
                            {
                                probabilityInState = Double.Parse(parsed.Groups["probability"].Value, CultureInfo.InvariantCulture);
                            }
                            probability += probabilityOfState * probabilityInState;
                        }
                        else
                        {
                            throw new Exception("Expected different output of MRMC");
                        }
                    }
                }
                return(new Probability(probability));
            }
        }
Esempio n. 3
0
 /// <summary>
 ///   Visits the <paramref name="formula." />
 /// </summary>
 public abstract void VisitProbabilisticFormula(ProbabilitisticFormula formula);
Esempio n. 4
0
 /// <summary>
 ///   Visits the <paramref name="formula." />
 /// </summary>
 public override void VisitProbabilisticFormula(ProbabilitisticFormula formula)
 {
     _containsInvalidOperators = true;
 }
 /// <summary>
 ///   Visits the <paramref name="formula." />
 /// </summary>
 public override void VisitProbabilisticFormula(ProbabilitisticFormula formula)
 {
     Visit(formula.Operand);
 }