public void Check()
        {
            var         m = new Model();
            Probability probabilityOfFinal100;
            Probability probabilityOfFinal200;

            var final100Formula = new BoundedUnaryFormula(Model.StateIs100, UnaryOperator.Finally, 5);
            var final200Formula = new BoundedUnaryFormula(Model.StateIs200, UnaryOperator.Finally, 5);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            nmdpGenerator.AddFormulaToCheck(final100Formula);
            nmdpGenerator.AddFormulaToCheck(final200Formula);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();

            nmdp.ExportToGv(Output.TextWriterAdapter());
            var typeOfModelChecker = typeof(BuiltinNmdpModelChecker);
            var modelChecker       = (BuiltinNmdpModelChecker)Activator.CreateInstance(typeOfModelChecker, nmdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal100 = modelChecker.CalculateMinimalProbability(final100Formula);
                probabilityOfFinal200 = modelChecker.CalculateMinimalProbability(final200Formula);
            }

            probabilityOfFinal100.Is(0.6 * 0.8, 0.000001).ShouldBe(true);
            probabilityOfFinal200.Is(0.4 + 0.6 * 0.2, 0.000001).ShouldBe(true);
        }
Пример #2
0
        public void CheckMdp()
        {
            var         m = new Model();
            Probability minProbabilityOfFinally2;
            Probability maxProbabilityOfFinally2;

            var finally2 = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            nmdpGenerator.AddFormulaToCheck(finally2);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();

            nmdp.ExportToGv(Output.TextWriterAdapter());
            Output.Log("");
            var nmdpToMpd = new NmdpToMdp(nmdp);
            var mdp       = nmdpToMpd.MarkovDecisionProcess;

            mdp.ExportToGv(Output.TextWriterAdapter());
            var typeOfModelChecker = typeof(BuiltinMdpModelChecker);
            var modelChecker       = (MdpModelChecker)Activator.CreateInstance(typeOfModelChecker, mdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinally2 = modelChecker.CalculateMinimalProbability(finally2);
                maxProbabilityOfFinally2 = modelChecker.CalculateMaximalProbability(finally2);
            }

            minProbabilityOfFinally2.Between(0.0, 0.0).ShouldBe(true);
            maxProbabilityOfFinally2.Between(1.0, 1.0).ShouldBe(true);
        }
        public void CheckNmdp()
        {
            var         m = new Model();
            Probability minProbabilityOfFinal2;
            Probability minProbabilityOfFinal3;
            Probability maxProbabilityOfFinal2;
            Probability maxProbabilityOfFinal3;

            var final2 = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var final3 = new UnaryFormula(new SimpleStateInRangeFormula(3), UnaryOperator.Finally);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            nmdpGenerator.AddFormulaToCheck(final2);
            nmdpGenerator.AddFormulaToCheck(final3);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();

            nmdp.ExportToGv(Output.TextWriterAdapter());
            var typeOfModelChecker = typeof(BuiltinNmdpModelChecker);
            var modelChecker       = (NmdpModelChecker)Activator.CreateInstance(typeOfModelChecker, nmdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal2 = modelChecker.CalculateMinimalProbability(final2);
                minProbabilityOfFinal3 = modelChecker.CalculateMinimalProbability(final3);
                maxProbabilityOfFinal2 = modelChecker.CalculateMaximalProbability(final2);
                maxProbabilityOfFinal3 = modelChecker.CalculateMaximalProbability(final3);
            }

            minProbabilityOfFinal2.Is(0.3, tolerance: 0.0001).ShouldBe(true);
            minProbabilityOfFinal3.Is(0.6, tolerance: 0.0001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(0.3, tolerance: 0.0001).ShouldBe(true);
            maxProbabilityOfFinal3.Is(0.6, tolerance: 0.0001).ShouldBe(true);
        }
        protected void CheckNmdp()
        {
            var         m = new Model();
            Probability minProbabilityOfFinal1;
            Probability maxProbabilityOfFinal1;

            var finally1 = new UnaryFormula(Model.StateIs1, UnaryOperator.Finally);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            nmdpGenerator.AddFormulaToCheck(finally1);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();
            var typeOfModelChecker = typeof(BuiltinNmdpModelChecker);
            var modelChecker       = (NmdpModelChecker)Activator.CreateInstance(typeOfModelChecker, nmdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal1 = modelChecker.CalculateMinimalProbability(finally1);
                maxProbabilityOfFinal1 = modelChecker.CalculateMaximalProbability(finally1);
            }

            minProbabilityOfFinal1.Is(0.65, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal1.Is(0.65, 0.000001).ShouldBe(true);
        }
Пример #5
0
        public void Check()
        {
            var         m = new SharedModels.SimpleExample2a();
            Probability minProbabilityOfFinal0;
            Probability minProbabilityOfFinal0Lt;
            Probability minProbabilityOfFinal1;
            Probability minProbabilityOfFinal2;
            Probability maxProbabilityOfFinal0;
            Probability maxProbabilityOfFinal0Lt;
            Probability maxProbabilityOfFinal1;
            Probability maxProbabilityOfFinal2;

            var final0Formula   = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs0, UnaryOperator.Finally, 4);
            var final0LtFormula =
                new BoundedUnaryFormula(
                    new BinaryFormula(SharedModels.SimpleExample2a.StateIs0, BinaryOperator.And, SharedModels.SimpleExample2a.LocalVarIsTrue),
                    UnaryOperator.Finally, 4);
            var final1Formula = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs1, UnaryOperator.Finally, 4);
            var final2Formula = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs2, UnaryOperator.Finally, 4);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.WriteGraphvizModels = true;
            nmdpGenerator.Configuration.DefaultTraceOutput  = Output.TextWriterAdapter();
            nmdpGenerator.Configuration.ModelCapacity       = ModelCapacityByMemorySize.Small;
            nmdpGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            nmdpGenerator.AddFormulaToCheck(final0Formula);
            nmdpGenerator.AddFormulaToCheck(final0LtFormula);
            nmdpGenerator.AddFormulaToCheck(final1Formula);
            nmdpGenerator.AddFormulaToCheck(final2Formula);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();
            var typeOfModelChecker = typeof(BuiltinNmdpModelChecker);
            var modelChecker       = (NmdpModelChecker)Activator.CreateInstance(typeOfModelChecker, nmdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal0   = modelChecker.CalculateMinimalProbability(final0Formula);
                minProbabilityOfFinal0Lt = modelChecker.CalculateMinimalProbability(final0LtFormula);
                minProbabilityOfFinal1   = modelChecker.CalculateMinimalProbability(final1Formula);
                minProbabilityOfFinal2   = modelChecker.CalculateMinimalProbability(final2Formula);
                maxProbabilityOfFinal0   = modelChecker.CalculateMaximalProbability(final0Formula);
                maxProbabilityOfFinal0Lt = modelChecker.CalculateMaximalProbability(final0LtFormula);
                maxProbabilityOfFinal1   = modelChecker.CalculateMaximalProbability(final1Formula);
                maxProbabilityOfFinal2   = modelChecker.CalculateMaximalProbability(final2Formula);
            }

            minProbabilityOfFinal0.Is(1.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal0Lt.Is(0.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal1.Is(0.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal2.Is(0.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal0.Is(1.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal0Lt.Is(1.0, 0.000001).ShouldBe(true);
            var maxProbabilityOf1And2Calculated = 1.0 - Math.Pow(0.6, 4);

            maxProbabilityOfFinal1.Is(maxProbabilityOf1And2Calculated, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(maxProbabilityOf1And2Calculated, 0.000001).ShouldBe(true);
        }