internal override Probability CalculateMinimalProbability(Formula formulaToCheck)
        {
            var isFormulaReturningBoolVisitor = new IsFormulaReturningBoolValueVisitor();

            isFormulaReturningBoolVisitor.Visit(formulaToCheck);
            if (!isFormulaReturningBoolVisitor.IsFormulaReturningBoolValue)
            {
                throw new Exception("expected formula which returns a bool");
            }

            var transformationVisitor = new PrismTransformer();

            transformationVisitor.Visit(formulaToCheck);
            var formulaToCheckInnerString = transformationVisitor.TransformedFormula;
            var formulaToCheckString      = "Pmin=? [ " + formulaToCheckInnerString + "]";

            using (var fileProperties = new TemporaryFile("props"))
            {
                File.WriteAllText(fileProperties.FilePath, formulaToCheckString);

                var prismArguments = _filePrism.FilePath + " " + fileProperties.FilePath;

                var prismProcess       = new PrismProcess(_output);
                var quantitativeResult = prismProcess.ExecutePrismAndParseResult(prismArguments);

                return(new Probability(quantitativeResult.ResultingProbability));
            }
        }
Exemple #2
0
        internal override bool CalculateBoolean(Formula formulaToCheck)
        {
            var isFormulaReturningBoolValueVisitor = new IsFormulaReturningBoolValueVisitor();

            isFormulaReturningBoolValueVisitor.Visit(formulaToCheck);
            if (!isFormulaReturningBoolValueVisitor.IsFormulaReturningBoolValue)
            {
                throw new Exception("expected formula which returns true or false");
            }

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

                var satisfied = true;
                while (resultEnumerator.MoveNext())
                {
                    var result = resultEnumerator.Current;
                    if (!String.IsNullOrEmpty(result))
                    {
                        var parsed = MrmcFormulaParser.Match(result);
                        if (parsed.Success)
                        {
                            var state = Int32.Parse(parsed.Groups["state"].Value);
                            var probabilityOfState = _initialStates[state];
                            if (probabilityOfState > 0.0)
                            {
                                var isSatisfiedResult = parsed.Groups["satisfied"].Value.Equals("TRUE");
                                satisfied &= isSatisfiedResult;                                 // TODO: Check PCTL semantics: should formula be true for all initial states >0.0? Or should the initial probability be taken into account for the probability value of the outermost operator.
                            }
                        }
                        else
                        {
                            throw new Exception("Expected different output of MRMC");
                        }
                    }
                }
                return(satisfied);
            }
        }