Esempio n. 1
0
        public void Check()
        {
            var         m = new Model();
            Probability probabilityOfFinal100;
            Probability probabilityOfFinal200;

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

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(final100Formula);
            markovChainGenerator.AddFormulaToCheck(final200Formula);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

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

            probabilityOfFinal100.Is(0.6 * 0.8, 0.000001).ShouldBe(true);
            probabilityOfFinal200.Is(0.4 + 0.6 * 0.2, 0.000001).ShouldBe(true);
        }
        protected void Check()
        {
            var         m = new Model();
            Probability probabilityOfInvariantViolation;

            var finallyInvariantViolated = new UnaryFormula(Model.InvariantViolated, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(finallyInvariantViolated);
            var dtmc = markovChainGenerator.GenerateMarkovChain();

            dtmc.ExportToGv(Output.TextWriterAdapter());
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfInvariantViolation = modelChecker.CalculateProbability(finallyInvariantViolated);
            }

            // 1.0-(1.0-0.1)^11 = 0.68618940391
            probabilityOfInvariantViolation.Is(0.68618940391, 0.00001).ShouldBe(true);
        }
Esempio n. 3
0
        public void CheckTerminateEarly()
        {
            var         m = new Model();
            Probability probabilityOfFinally2;

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

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(finally2);
            var dtmc = markovChainGenerator.GenerateMarkovChain(stateIs2);

            dtmc.ExportToGv(Output.TextWriterAdapter());
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinally2 = modelChecker.CalculateProbability(finally2);
            }

            probabilityOfFinally2.Between(0.33, 0.34).ShouldBe(true);
        }
Esempio n. 4
0
        public void Check()
        {
            var         m = new Model();
            Probability probabilityOfFinal2;
            Probability probabilityOfFinal3;
            Probability probabilityOfFinal4;

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

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(final2);
            markovChainGenerator.AddFormulaToCheck(final3);
            markovChainGenerator.AddFormulaToCheck(final4);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal2 = modelChecker.CalculateProbability(final2);
                probabilityOfFinal3 = modelChecker.CalculateProbability(final3);
                probabilityOfFinal4 = modelChecker.CalculateProbability(final4);
            }

            probabilityOfFinal2.Is(1.0 / 3, tolerance: 0.0001).ShouldBe(true);
            probabilityOfFinal3.Is(1.0 / 3, tolerance: 0.0001).ShouldBe(true);
            probabilityOfFinal3.Is(1.0 / 3, tolerance: 0.0001).ShouldBe(true);
        }
        public void Check()
        {
            var         m = new Model();
            Probability probabilityOfStep11FrozenValue0AndInvariantViolated;
            Probability probabilityOfStep11FrozenValue1AndInvariantViolated;
            Probability probabilityOfStep11FrozenValue0AndInvariantNotViolated;
            Probability probabilityOfStep11FrozenValue1AndInvariantNotViolated;


            Formula formulaProbabilityOfStep11FrozenValue0AndInvariantViolated    = new BinaryFormula(new SimpleStateInRangeFormula(10), BinaryOperator.And, new SimpleLocalVarIsTrue(0));
            Formula formulaProbabilityOfStep11FrozenValue1AndInvariantViolated    = new BinaryFormula(new SimpleStateInRangeFormula(10 + 128), BinaryOperator.And, new SimpleLocalVarIsTrue(0));
            Formula formulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated = new BinaryFormula(new SimpleStateInRangeFormula(10), BinaryOperator.And, new UnaryFormula(new SimpleLocalVarIsTrue(0), UnaryOperator.Not));
            Formula formulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated = new BinaryFormula(new SimpleStateInRangeFormula(10 + 128), BinaryOperator.And, new UnaryFormula(new SimpleLocalVarIsTrue(0), UnaryOperator.Not));

            var finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantViolated    = new UnaryFormula(formulaProbabilityOfStep11FrozenValue0AndInvariantViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantViolated    = new UnaryFormula(formulaProbabilityOfStep11FrozenValue1AndInvariantViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated = new UnaryFormula(formulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated = new UnaryFormula(formulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated);
            var dtmc = markovChainGenerator.GenerateMarkovChain();

            dtmc.ExportToGv(Output.TextWriterAdapter());

            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter()); using (modelChecker)
            {
                probabilityOfStep11FrozenValue0AndInvariantViolated    = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantViolated);
                probabilityOfStep11FrozenValue1AndInvariantViolated    = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantViolated);
                probabilityOfStep11FrozenValue0AndInvariantNotViolated = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated);
                probabilityOfStep11FrozenValue1AndInvariantNotViolated = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated);
            }

            var probabilitiesSummedUp =
                probabilityOfStep11FrozenValue0AndInvariantViolated +
                probabilityOfStep11FrozenValue1AndInvariantViolated +
                probabilityOfStep11FrozenValue0AndInvariantNotViolated +
                probabilityOfStep11FrozenValue1AndInvariantNotViolated;

            probabilitiesSummedUp.Is(1.0, 0.000001).ShouldBe(true);
        }
        public void Check()
        {
            Probability probabilityOfFinal1;
            Probability probabilityOfFinal2;
            Probability probabilityOfFinal3;
            Probability probabilityOfFinal4;

            var m = new Model();

            var formula1 = new BinaryFormula(Model.FIs2, BinaryOperator.Or, Model.FIs3);
            var formula2 = Model.FIs1;
            var formula3 = new BinaryFormula(new BinaryFormula(Model.GIs0, BinaryOperator.Or, Model.GIs7), BinaryOperator.Or, Model.GIs8);
            var formula4 = Model.GIs7;

            var final1 = new UnaryFormula(formula1, UnaryOperator.Finally);
            var final2 = new UnaryFormula(formula2, UnaryOperator.Finally);
            var final3 = new UnaryFormula(formula3, UnaryOperator.Finally);
            var final4 = new UnaryFormula(formula4, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(final1);
            markovChainGenerator.AddFormulaToCheck(final2);
            markovChainGenerator.AddFormulaToCheck(final3);
            markovChainGenerator.AddFormulaToCheck(final4);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal1 = modelChecker.CalculateProbability(final1);
                probabilityOfFinal2 = modelChecker.CalculateProbability(final2);
                probabilityOfFinal3 = modelChecker.CalculateProbability(final3);
                probabilityOfFinal4 = modelChecker.CalculateProbability(final4);
            }

            probabilityOfFinal1.Is(0.0, tolerance: 0.0001).ShouldBe(true);
            probabilityOfFinal2.Is(1.0, tolerance: 0.0001).ShouldBe(true);
            probabilityOfFinal3.Is(1.0, tolerance: 0.0001).ShouldBe(true);
            probabilityOfFinal4.Is(0.8333333333, tolerance: 0.0001).ShouldBe(true);
        }
        public void Check()
        {
            var         m = new SharedModels.SimpleExample2a();
            Probability probabilityOfFinal0;
            Probability probabilityOfFinal0Lt;
            Probability probabilityOfFinal1;
            Probability probabilityOfFinal2;

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

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.WriteGraphvizModels = true;
            markovChainGenerator.Configuration.DefaultTraceOutput  = Output.TextWriterAdapter();
            markovChainGenerator.Configuration.ModelCapacity       = ModelCapacityByMemorySize.Small;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            markovChainGenerator.AddFormulaToCheck(final0Formula);
            markovChainGenerator.AddFormulaToCheck(final0LtFormula);
            markovChainGenerator.AddFormulaToCheck(final1Formula);
            markovChainGenerator.AddFormulaToCheck(final2Formula);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal0   = modelChecker.CalculateProbability(final0Formula);
                probabilityOfFinal0Lt = modelChecker.CalculateProbability(final0LtFormula);
                probabilityOfFinal1   = modelChecker.CalculateProbability(final1Formula);
                probabilityOfFinal2   = modelChecker.CalculateProbability(final2Formula);
            }

            probabilityOfFinal0.Is(1.0, 0.000001).ShouldBe(true);
            probabilityOfFinal0Lt.Is(0.55 / 3.0 * 4.0, 0.000001).ShouldBe(true);
            probabilityOfFinal1.Is(0.5, 0.000001).ShouldBe(true);
            probabilityOfFinal2.Is(0.5, 0.000001).ShouldBe(true);
        }
        public void Check()
        {
            var         m = new Model();
            Probability probabilityOfInvariantViolation;

            Formula invariantViolated        = new SimpleLocalVarIsTrue(0);
            var     finallyInvariantViolated = new UnaryFormula(invariantViolated, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.AddFormulaToCheck(finallyInvariantViolated);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfInvariantViolation = modelChecker.CalculateProbability(finallyInvariantViolated);
            }

            probabilityOfInvariantViolation.Is(0.01, 0.0001).ShouldBe(true);
        }