Ejemplo n.º 1
0
        public void Check()
        {
            var         m = new Model();
            Probability probabilityOfFinal1;
            Probability probabilityOfFinal2;
            Probability probabilityOfFinal3;

            var final1Formula = new UnaryFormula(new SimpleStateInRangeFormula(1), UnaryOperator.Finally);
            var final2Formula = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var final3Formula = new UnaryFormula(new SimpleStateInRangeFormula(3), UnaryOperator.Finally);

            var markovChainGenerator = new SimpleDtmcFromExecutableModelGenerator(m);

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

            using (modelChecker)
            {
                probabilityOfFinal1 = modelChecker.CalculateProbability(final1Formula);
                probabilityOfFinal2 = modelChecker.CalculateProbability(final2Formula);
                probabilityOfFinal3 = modelChecker.CalculateProbability(final3Formula);
            }

            probabilityOfFinal1.Is(1.0, 0.000001).ShouldBe(true);
            probabilityOfFinal2.Is(1.0, 0.000001).ShouldBe(true);
            probabilityOfFinal3.Is(1.0, 0.000001).ShouldBe(true);
        }
		/// <summary>
		///   Visits the <paramref name="formula" />.
		/// </summary>
		public override void VisitUnaryFormula(UnaryFormula formula)
		{
			switch (formula.Operator)
			{
				case UnaryOperator.Next:
				case UnaryOperator.Finally:
				case UnaryOperator.Globally:
					throw new InvalidOperationException($"Path Operator only allowed in Path Formulas.");
					break;
				case UnaryOperator.Not:
					_builder.Append("(");
					_builder.Append(" ! ");
					Visit(formula.Operand);
					_builder.Append(")");
					break;
				case UnaryOperator.All:
					VisitForAllPathFormula(formula.Operand);
					break;
				case UnaryOperator.Exists:
					VisitExistsPathFormula(formula.Operand);
					break;
				default:
					Assert.NotReached($"Unknown or unsupported unary operator '{formula.Operator}'.");
					break;
			}
		}
        public void StepwiseProbablityOfLabel2ForExample4()
        {
            var example = new Example4();
            var dtmc    = example.MarkovChain;

            var results = new List <Probability>();

            using (var prismChecker = new BuiltinDtmcModelChecker(dtmc, Output.TextWriterAdapter()))
            {
                for (var i = 0; i <= 10; i++)
                {
                    var boundedStepi       = new BoundedUnaryFormula(MarkovChainExample.Label2Formula, UnaryOperator.Finally, i);
                    var resultBoundedStepi = prismChecker.CalculateProbability(boundedStepi);
                    Output.Log($"Result {i}:\t{resultBoundedStepi}");
                    results.Add(resultBoundedStepi);
                }

                var boundedStep200       = new BoundedUnaryFormula(MarkovChainExample.Label2Formula, UnaryOperator.Finally, 200);
                var resultBoundedStep200 = prismChecker.CalculateProbability(boundedStep200);
                Output.Log($"Result {200}:\t{resultBoundedStep200}");

                var inf       = new UnaryFormula(MarkovChainExample.Label2Formula, UnaryOperator.Finally);
                var resultInf = prismChecker.CalculateProbability(inf);
                Output.Log($"Result inf:\t{resultInf}");
            }
        }
Ejemplo n.º 4
0
        public void CheckWithEarlyTermination()
        {
            var         m = new Model();
            Probability probabilityOfFinally3;

            var stateIs3 = new SimpleStateInRangeFormula(3);
            var finally3 = new UnaryFormula(stateIs3, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity          = ModelCapacityByMemorySize.Small;
            markovChainGenerator.Configuration.EnableEarlyTermination = true;
            markovChainGenerator.AddFormulaToCheck(finally3);
            var dtmc = markovChainGenerator.GenerateMarkovChain();

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

            using (modelChecker)
            {
                probabilityOfFinally3 = modelChecker.CalculateProbability(finally3);
            }
            Assert.Equal(5, dtmc.States);
            Assert.Equal(5, dtmc.Transitions);
            probabilityOfFinally3.Between(0.66, 0.67).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);
        }
Ejemplo n.º 6
0
		/// <summary>
		///   Visits the <paramref name="formula." />
		/// </summary>
		public override void VisitUnaryFormula(UnaryFormula formula)
		{
			if (formula.Operator == UnaryOperator.Not)
				Visit(formula.Operand);
			else
				_containsInvalidOperators = true;
		}
        public void CheckOnceWithNonAtomarOperand()
        {
            var         m = new Model();
            Probability probability;

            var once7MoreComplex   = new BinaryFormula(Model.IsInState7, BinaryOperator.And, Model.IsInState7);
            var once7Formula       = new UnaryFormula(once7MoreComplex, UnaryOperator.Once);
            var is9Once7Formula    = new BinaryFormula(Model.IsInState9, BinaryOperator.And, once7Formula);
            var final9Once7Formula = new UnaryFormula(is9Once7Formula, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = true;
            markovChainGenerator.Configuration.DefaultTraceOutput     = Output.TextWriterAdapter();
            markovChainGenerator.Configuration.WriteGraphvizModels    = true;
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = true;
            markovChainGenerator.AddFormulaToCheck(final9Once7Formula);
            var dtmc = markovChainGenerator.GenerateMarkovChain();
            var typeOfModelChecker = typeof(BuiltinDtmcModelChecker);
            var modelChecker       = (DtmcModelChecker)Activator.CreateInstance(typeOfModelChecker, dtmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probability = modelChecker.CalculateProbability(final9Once7Formula);
            }

            probability.Is(0.4 * 0.4 + 0.6, 0.00000001).ShouldBe(true);
        }
Ejemplo n.º 8
0
        public void CheckNmdp()
        {
            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());
            var typeOfModelChecker = typeof(BuiltinNmdpModelChecker);
            var modelChecker       = (NmdpModelChecker)Activator.CreateInstance(typeOfModelChecker, nmdp, 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);
        }
Ejemplo n.º 9
0
		/// <summary>
		///   Visits the <paramref name="formula" />.
		/// </summary>
		public override void VisitUnaryFormula(UnaryFormula formula)
		{
			_builder.Append("(");

			switch (formula.Operator)
			{
				case UnaryOperator.Next:
					_builder.Append(" X ");
					break;
				case UnaryOperator.Finally:
					_builder.Append(" <> ");
					break;
				case UnaryOperator.Globally:
					_builder.Append(" [] ");
					break;
				case UnaryOperator.Not:
					_builder.Append(" ! ");
					break;
				default:
					Assert.NotReached($"Unknown or unsupported unary operator '{formula.Operator}'.");
					break;
			}

			Visit(formula.Operand);
			_builder.Append(")");
		}
Ejemplo n.º 10
0
		/// <summary>
		///   Visits the <paramref name="formula." />
		/// </summary>
		public override void VisitUnaryFormula(UnaryFormula formula)
		{
			if (formula.Operator == UnaryOperator.All || formula.Operator == UnaryOperator.Exists)
				_containsInvalidOperators = true;
			else
				Visit(formula.Operand);
		}
Ejemplo n.º 11
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel> createAnalysisModelFunc = () =>
                                                           new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, 0, configuration);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker(createAnalysisModel, configuration, invariant);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel <TExecutableModel> > createAnalysisModelFunc = () =>
                                                                               new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, _stateHeaderBytes, configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator <TExecutableModel>(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker <TExecutableModel>(createAnalysisModel, OnOutputWritten, configuration, invariant);
        }
Ejemplo n.º 13
0
 /// <summary>
 ///   Visits the <paramref name="formula." />
 /// </summary>
 public override void VisitUnaryFormula(UnaryFormula formula)
 {
     if (formula.Operator == UnaryOperator.All || formula.Operator == UnaryOperator.Exists)
     {
         _containsInvalidOperators = true;
     }
     else
     {
         Visit(formula.Operand);
     }
 }
        public void ProbabilityToReach_Label1(MarkovChainExample example)
        {
            var dtmc = example.MarkovChain;

            var finallyLabel1 = new UnaryFormula(MarkovChainExample.Label1Formula, UnaryOperator.Finally);

            using (var checker = new ExternalDtmcModelCheckerMrmc(dtmc, Output.TextWriterAdapter()))
            {
                var result = checker.CalculateProbability(finallyLabel1);
                result.Is(example.ProbabilityFinallyLabel1, 0.0001).ShouldBe(true);
            }
        }
Ejemplo n.º 15
0
        public void MinimalProbabilityToReach_Label1(MarkovDecisionProcessExample example)
        {
            var mdp = example.Mdp;

            var finallyLabel1 = new UnaryFormula(MarkovDecisionProcessExample.Label1Formula, UnaryOperator.Finally);

            using (var prismChecker = new ExternalMdpModelCheckerPrism(mdp, Output.TextWriterAdapter()))
            {
                var result = prismChecker.CalculateMinimalProbability(finallyLabel1);
                result.Is(example.MinimalProbabilityFinallyLabel1, 0.0001).ShouldBe(true);
            }
        }
Ejemplo n.º 16
0
		/// <summary>
		///   Visits the <paramref name="formula." />
		/// </summary>
		public override void VisitUnaryFormula(UnaryFormula formula)
		{
			switch (formula.Operator)
			{
				case UnaryOperator.Not:
					Visit(formula.Operand);
					_expression = Expression.Not(_expression);
					break;
				default:
					throw new InvalidOperationException("Only state formulas can be evaluated.");
			}
		}
Ejemplo n.º 17
0
        /// <summary>
        ///   Visits the <paramref name="formula." />
        /// </summary>
        public override void VisitUnaryFormula(UnaryFormula formula)
        {
            switch (formula.Operator)
            {
            case UnaryOperator.Not:
                Visit(formula.Operand);
                _expression = Expression.Not(_expression);
                break;

            default:
                throw new InvalidOperationException("Only state formulas can be evaluated.");
            }
        }
Ejemplo n.º 18
0
        private void CheckUnbounded(AnalysisConfiguration configuration)
        {
            var         m = new SharedModels.SimpleExample2a();
            Probability minProbabilityOfFinal0;
            Probability minProbabilityOfFinal0Lt;
            Probability minProbabilityOfFinal1;
            Probability minProbabilityOfFinal2;
            Probability maxProbabilityOfFinal0;
            Probability maxProbabilityOfFinal0Lt;
            Probability maxProbabilityOfFinal1;
            Probability maxProbabilityOfFinal2;

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

            var mdpGenerator = new SimpleMarkovDecisionProcessFromExecutableModelGenerator(m);

            mdpGenerator.Configuration = configuration;
            mdpGenerator.AddFormulaToCheck(final0Formula);
            mdpGenerator.AddFormulaToCheck(final0LtFormula);
            mdpGenerator.AddFormulaToCheck(final1Formula);
            mdpGenerator.AddFormulaToCheck(final2Formula);
            var mdp          = mdpGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
            var modelChecker = new ConfigurationDependentLtmdpModelChecker(configuration, mdp, 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);
            maxProbabilityOfFinal1.Is(1.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(1.0, 0.000001).ShouldBe(true);
        }
Ejemplo n.º 19
0
        public void Parametric()
        {
            Formula invariant = new LustrePressureBelowThreshold();
            Formula hazard    = new UnaryFormula(invariant, UnaryOperator.Not);

            LustrePressureBelowThreshold.threshold = 60;
            var faultK1 = new PermanentFault()
            {
                Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6)
            };
            var faultK2 = new PermanentFault()
            {
                Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6)
            };
            var faultSensor = new PermanentFault()
            {
                Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5)
            };
            var faults = new[] { faultK1, faultK2, faultSensor };

            var parameter = new QuantitativeParametricAnalysisParameter
            {
                StateFormula = hazard,
                Bound        = null,
                From         = 3.0E-7,
                To           = 3.0E-5,
                Steps        = 25,
            };

            using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varyK1.csv"), append: false))
            {
                parameter.UpdateParameterInModel = value => { faultK1.ProbabilityOfOccurrence = new Probability(value); };
                var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
                result.ToCsv(fileWriter);
            }

            using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varyK2.csv"), append: false))
            {
                parameter.UpdateParameterInModel = value => { faultK2.ProbabilityOfOccurrence = new Probability(value); };
                var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
                result.ToCsv(fileWriter);
            }

            using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varySensor.csv"), append: false))
            {
                parameter.UpdateParameterInModel = value => { faultSensor.ProbabilityOfOccurrence = new Probability(value); };
                var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
                result.ToCsv(fileWriter);
            }
        }
        public void TankRupture()
        {
            Formula invariant = new LustrePressureBelowThreshold();
            Formula hazard    = new UnaryFormula(invariant, UnaryOperator.Not);

            LustrePressureBelowThreshold.threshold = 60;
            var faults = new List <Fault>
            {
                new TransientFault()
                {
                    Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6)
                },
                new PermanentFault()
                {
                    Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6)
                },
                new PermanentFault()
                {
                    Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = null
                },
                new PermanentFault()
                {
                    Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5)
                },
                new PermanentFault()
                {
                    Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5)
                }
            };

            var createModel = LustreExecutableModel.CreateExecutedModelFromFormulasCreator(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults.ToArray());

            var markovChainGenerator = new MarkovDecisionProcessFromExecutableModelGenerator <LustreExecutableModel>(createModel);

            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(10000, 1000000);
            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = true;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.AddFormulaToCheck(hazard);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();

            var ltmcModelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, Console.Out);
            var finallyHazard    = new BoundedUnaryFormula(hazard, UnaryOperator.Finally, 200);
            var result           = ltmcModelChecker.CalculateProbabilityRange(finallyHazard);

            Console.Write($"Probability of hazard: {result}");
        }
Ejemplo n.º 21
0
        public void CalculateHazardSingleCoreAllFaultsWithOnce()
        {
            var model = new Model();

            SetProbabilities(model);

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

            var markovChainGenerator = new MarkovChainFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = SafetySharpModelChecker.TraversalConfiguration
            };

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.CpuCount           = 1;
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.EnableEarlyTermination          = false;
            var onceUnsuccessful  = new UnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Once);
            var onceContamination = new UnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Once);
            var onceFault1        = new UnaryFormula(new FaultFormula(model.HdMachine.Dialyzer.DialyzerMembraneRupturesFault), UnaryOperator.Once);

            markovChainGenerator.AddFormulaToCheck(onceFault1);
            foreach (var fault in model.Faults.Where(fault => fault != model.HdMachine.Dialyzer.DialyzerMembraneRupturesFault))
            {
                var faultFormula = new UnaryFormula(new FaultFormula(fault), UnaryOperator.Once);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }

            var finallyUnsuccessful  = new BoundedUnaryFormula(new BinaryFormula(onceFault1, BinaryOperator.And, onceUnsuccessful), UnaryOperator.Finally, 6);
            var finallyContamination = new BoundedUnaryFormula(new BinaryFormula(onceFault1, BinaryOperator.And, onceContamination), UnaryOperator.Finally, 6);

            markovChainGenerator.AddFormulaToCheck(finallyUnsuccessful);
            markovChainGenerator.AddFormulaToCheck(finallyContamination);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();


            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(finallyUnsuccessful);
                Console.Write($"Probability of unsuccessful: {result}");
            }

            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(finallyContamination);
                Console.Write($"Probability of contamination: {result}");
            }
        }
        public void Check()
        {
            var m             = new Model();
            var formulaNotTwo = new UnaryFormula(Model.StateIsTwo, UnaryOperator.Not);
            var checker       = new SimpleQualitativeChecker(m, formulaNotTwo)
            {
                Configuration = AnalysisConfiguration.Default
            };

            checker.Configuration.ModelCapacity      = ModelCapacityByMemorySize.Small;
            checker.Configuration.DefaultTraceOutput = Output.TextWriterAdapter();

            var result = checker.CheckInvariant(formulaNotTwo);

            result.FormulaHolds.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);
        }
        protected override void Check()
        {
            var         c = new C();
            Probability probabilityOfStep11FrozenValue2AndInvariantViolated;
            Probability probabilityOfStep11FrozenValue3AndInvariantViolated;
            Probability probabilityOfStep11FrozenValue2AndInvariantNotViolated;
            Probability probabilityOfStep11FrozenValue3AndInvariantNotViolated;


            Formula formulaProbabilityOfStep11FrozenValue2AndInvariantViolated    = c._timestep == 11 && c._frozenValue == 2 && c.ViolateInvariant;
            Formula formulaProbabilityOfStep11FrozenValue3AndInvariantViolated    = c._timestep == 11 && c._frozenValue == 3 && c.ViolateInvariant;
            Formula formulaProbabilityOfStep11FrozenValue2AndInvariantNotViolated = c._timestep == 11 && c._frozenValue == 2 && !c.ViolateInvariant;
            Formula formulaProbabilityOfStep11FrozenValue3AndInvariantNotViolated = c._timestep == 11 && c._frozenValue == 3 && !c.ViolateInvariant;

            var finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantViolated    = new UnaryFormula(formulaProbabilityOfStep11FrozenValue2AndInvariantViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantViolated    = new UnaryFormula(formulaProbabilityOfStep11FrozenValue3AndInvariantViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantNotViolated = new UnaryFormula(formulaProbabilityOfStep11FrozenValue2AndInvariantNotViolated, UnaryOperator.Finally);
            var finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantNotViolated = new UnaryFormula(formulaProbabilityOfStep11FrozenValue3AndInvariantNotViolated, UnaryOperator.Finally);

            var markovChainGenerator = new SafetySharpMarkovChainFromExecutableModelGenerator(TestModel.InitializeModel(c));

            markovChainGenerator.Configuration.ModelCapacity    = ModelCapacityByMemorySize.Small;
            markovChainGenerator.Configuration.LtmcModelChecker = (ISSE.SafetyChecking.LtmcModelChecker)Arguments[0];
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantNotViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantNotViolated);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, ltmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfStep11FrozenValue2AndInvariantViolated    = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantViolated);
                probabilityOfStep11FrozenValue3AndInvariantViolated    = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantViolated);
                probabilityOfStep11FrozenValue2AndInvariantNotViolated = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue2AndInvariantNotViolated);
                probabilityOfStep11FrozenValue3AndInvariantNotViolated = modelChecker.CalculateProbability(finallyFormulaProbabilityOfStep11FrozenValue3AndInvariantNotViolated);
            }

            var probabilitiesSummedUp =
                probabilityOfStep11FrozenValue2AndInvariantViolated +
                probabilityOfStep11FrozenValue3AndInvariantViolated +
                probabilityOfStep11FrozenValue2AndInvariantNotViolated +
                probabilityOfStep11FrozenValue3AndInvariantNotViolated;

            probabilitiesSummedUp.Is(1.0, 0.000001).ShouldBe(true);
        }
Ejemplo n.º 25
0
        public void CalculateLtmdpWithoutStaticPruningSingleCore()
        {
            var model = new Model();

            SetProbabilities(model);
            model.HdMachine.Dialyzer.DialyzerMembraneRupturesFault.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

            var markovChainGenerator = new MarkovDecisionProcessFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = SafetySharpModelChecker.TraversalConfiguration
            };

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker      = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var unsuccessful  = new UnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Finally);
            var contamination = new UnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Finally);

            markovChainGenerator.AddFormulaToCheck(unsuccessful);
            markovChainGenerator.AddFormulaToCheck(contamination);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.CpuCount = 1;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();


            using (var modelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbabilityRange(unsuccessful);
                Console.Write($"Probability of unsuccessful: {result}");
            }

            using (var modelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbabilityRange(contamination);
                Console.Write($"Probability of contamination: {result}");
            }
        }
Ejemplo n.º 26
0
        public void CheckMdp()
        {
            var         m = new Model();
            Probability minProbabilityOfFinal1;
            Probability minProbabilityOfFinal2;
            Probability minProbabilityOfFinal3;
            Probability maxProbabilityOfFinal1;
            Probability maxProbabilityOfFinal2;
            Probability maxProbabilityOfFinal3;

            var final1Formula = new UnaryFormula(new SimpleStateInRangeFormula(1), UnaryOperator.Finally);
            var final2Formula = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var final3Formula = new UnaryFormula(new SimpleStateInRangeFormula(3), UnaryOperator.Finally);

            var nmdpGenerator = new SimpleNmdpFromExecutableModelGenerator(m);

            nmdpGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small;
            nmdpGenerator.AddFormulaToCheck(final1Formula);
            nmdpGenerator.AddFormulaToCheck(final2Formula);
            nmdpGenerator.AddFormulaToCheck(final3Formula);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess();

            nmdp.ExportToGv(Output.TextWriterAdapter());
            var nmdpToMpd          = new NmdpToMdp(nmdp);
            var mdp                = nmdpToMpd.MarkovDecisionProcess;
            var typeOfModelChecker = typeof(BuiltinMdpModelChecker);
            var modelChecker       = (MdpModelChecker)Activator.CreateInstance(typeOfModelChecker, mdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal1 = modelChecker.CalculateMinimalProbability(final1Formula);
                minProbabilityOfFinal2 = modelChecker.CalculateMinimalProbability(final2Formula);
                minProbabilityOfFinal3 = modelChecker.CalculateMinimalProbability(final3Formula);
                maxProbabilityOfFinal1 = modelChecker.CalculateMaximalProbability(final1Formula);
                maxProbabilityOfFinal2 = modelChecker.CalculateMaximalProbability(final2Formula);
                maxProbabilityOfFinal3 = modelChecker.CalculateMaximalProbability(final3Formula);
            }

            minProbabilityOfFinal1.Is(1.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal2.Is(0.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal3.Is(0.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal1.Is(1.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(1.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal3.Is(1.0, 0.000001).ShouldBe(true);
        }
Ejemplo n.º 27
0
        public void CalculateHazardSingleCoreWithOncePositionDetectorMis()
        {
            var model = Model.CreateOriginal();

            SetProbabilities(model);

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

            var markovChainGenerator = new MarkovChainFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = SafetySharpModelChecker.TraversalConfiguration
            };

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.CpuCount      = 1;
            markovChainGenerator.Configuration.ModelCapacity = new ModelCapacityByModelSize(3300000L, 1000000000L);
            var onceFault1 = new UnaryFormula(new FaultFormula(model.HeightControl.PreControl.PositionDetector.Misdetection), UnaryOperator.Once);

            markovChainGenerator.AddFormulaToCheck(onceFault1);
            var onceCollision     = new UnaryFormula(model.Collision, UnaryOperator.Once);
            var onceFalseAlarm    = new UnaryFormula(model.FalseAlarm, UnaryOperator.Once);
            var finallyCollision  = new BoundedUnaryFormula(new BinaryFormula(onceFault1, BinaryOperator.And, onceCollision), UnaryOperator.Finally, 50);
            var finallyFalseAlarm = new BoundedUnaryFormula(new BinaryFormula(onceFault1, BinaryOperator.And, onceFalseAlarm), UnaryOperator.Finally, 50);

            markovChainGenerator.AddFormulaToCheck(finallyCollision);
            markovChainGenerator.AddFormulaToCheck(finallyFalseAlarm);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var ltmc        = markovChainGenerator.GenerateLabeledMarkovChain();
            var markovChain = markovChainGenerator.GenerateMarkovChain();

            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, ltmc, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(finallyCollision);
                Console.Write($"Probability of collision: {result}");
            }

            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, ltmc, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(finallyFalseAlarm);
                Console.Write($"Probability of falseAlarm: {result}");
            }
        }
        private void Check(AnalysisConfiguration configuration)
        {
            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 SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue0AndInvariantNotViolated);
            markovChainGenerator.AddFormulaToCheck(finallyFormulaProbabilityOfStep11FrozenValue1AndInvariantNotViolated);

            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter());
            {
                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()
        {
            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()
        {
            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);
        }
Ejemplo n.º 31
0
        private void Check(AnalysisConfiguration configuration)
        {
            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 SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(final1);
            markovChainGenerator.AddFormulaToCheck(final2);
            markovChainGenerator.AddFormulaToCheck(final3);
            markovChainGenerator.AddFormulaToCheck(final4);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, 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);
        }
Ejemplo n.º 32
0
        protected override void Check()
        {
            {
                var actual   = !(X(true));
                var expected = new UnaryFormula(
                    new UnaryFormula(new ExecutableStateFormula(() => true), UnaryOperator.Next),
                    UnaryOperator.Not);

                Check(actual, expected);
            }

            {
                var actual   = !X(true);
                var expected = new UnaryFormula(
                    new UnaryFormula(new ExecutableStateFormula(() => true), UnaryOperator.Next),
                    UnaryOperator.Not);

                Check(actual, expected);
            }
        }
Ejemplo n.º 33
0
        public Sequent Apply(Sequent sequent)
        {
            UnaryFormula implicationFormula = (UnaryFormula)sequent.LeftHandSide.Formulas.Where(
                x => x is UnaryFormula formula && formula.Connective == UnaryConnective.Negation
                ).FirstOrDefault();

            if (implicationFormula == null)
            {
                return(null);
            }

            sequent.LeftHandSide.Formulas.Remove(implicationFormula);

            var formula = implicationFormula.Formula.Clone();

            sequent.RightHandSide.Formulas.Add(formula);
            sequent.Justification = "R5 (" + sequent.Name + ")";

            return(sequent);
        }
Ejemplo n.º 34
0
        public void TankRupture()
        {
            Formula invariant = new LustrePressureBelowThreshold();
            Formula hazard    = new UnaryFormula(invariant, UnaryOperator.Not);

            LustrePressureBelowThreshold.threshold = 60;
            var faults = new List <Fault>
            {
                new TransientFault()
                {
                    Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6)
                },
                new PermanentFault()
                {
                    Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6)
                },
                new PermanentFault()
                {
                    Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6)
                },
                new PermanentFault()
                {
                    Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5)
                },
                new PermanentFault()
                {
                    Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5)
                }
            };
            var modelChecker = new LustreMarkovChainFromExecutableModelGenerator(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults);

            modelChecker.AddFormulaToCheck(hazard);
            modelChecker.Configuration.UseCompactStateStorage = true;
            var lmc = modelChecker.GenerateLabeledMarkovChain();

            var ltmcModelChecker = new BuiltinLtmcModelChecker(lmc, Console.Out);
            var finallyHazard    = new BoundedUnaryFormula(hazard, UnaryOperator.Finally, 200);
            var result           = ltmcModelChecker.CalculateProbability(finallyHazard);

            Console.Write($"Probability of hazard: {result}");
        }
Ejemplo n.º 35
0
        private Probability Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability probabilityOfInvariantViolation;

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

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(finallyInvariantViolated);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter());

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

            return(probabilityOfInvariantViolation);
        }
Ejemplo n.º 36
0
		/// <summary>
		///     Visits an element of type <see cref="UnaryFormula" />.
		/// </summary>
		/// <param name="formula">The <see cref="UnaryFormula" /> instance that should be visited.</param>
		protected internal virtual void VisitUnaryFormula(UnaryFormula formula)
		{
			DefaultVisit(formula);
		}
Ejemplo n.º 37
0
		/// <summary>
		///     Visits an element of type <see cref="UnaryFormula" />.
		/// </summary>
		/// <param name="formula">The <see cref="UnaryFormula" /> instance that should be visited.</param>
		protected internal override void VisitUnaryFormula(UnaryFormula formula)
		{
			Visit(formula.Operand);
		}
Ejemplo n.º 38
0
		/// <summary>
		///   Visits the <paramref name="formula." />
		/// </summary>
		public abstract void VisitUnaryFormula(UnaryFormula formula);