Пример #1
0
        public void CreateFaultAwareMarkovChainAllFaults()
        {
            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.EnableStaticPruningOptimization = false;
            markovChainGenerator.AddFormulaToCheck(model.PossibleCollision);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #2
0
        public void CreateMarkovChainWithHazardRetraversal1()
        {
            var model = new DegradedModeModel();

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.AddFormulaToCheck(model.System.HazardActive);
            markovChainGenerator.Configuration.UseCompactStateStorage             = true;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = true;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();

            var retraversalMarkovChainGenerator = new MarkovChainFromMarkovChainGenerator(markovChain);

            retraversalMarkovChainGenerator.Configuration.SuccessorCapacity *= 2;
            retraversalMarkovChainGenerator.AddFormulaToCheck(model.System.HazardActive);
            retraversalMarkovChainGenerator.Configuration.UseCompactStateStorage             = true;
            retraversalMarkovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = true;
            retraversalMarkovChainGenerator.GenerateLabeledMarkovChain();
        }
        /// <summary>
        ///   Calculates the probability of formula.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="formula">The state formula to be checked.</param>
        /// <param name="terminateEarlyFormula">When terminateEarlyFormula is satisfied stop building the state space.</param>
        /// <param name="bound">The maximal number of steps. If stateFormula is satisfied the first time any step later than bound, this probability does not count into the end result.</param>
        public static ProbabilityRange CalculateProbabilityRangeOfFormulaBounded(ModelBase model, Formula formula, Formula terminateEarlyFormula, int bound)
        {
            ProbabilityRange probabilityRangeToReachState;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

            var nmdpGenerator = new NmdpFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = TraversalConfiguration
            };

            nmdpGenerator.AddFormulaToCheck(formula);
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess(terminateEarlyFormula);


            if (_convertNmdpToMdp)
            {
                var nmdpToMpd = new NmdpToMdp(nmdp);
                var mdp       = nmdpToMpd.MarkovDecisionProcess;
                using (var modelChecker = new BuiltinMdpModelChecker(mdp, System.Console.Out))
                {
                    probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(formula);
                }
            }
            else
            {
                using (var modelChecker = new BuiltinNmdpModelChecker(nmdp, System.Console.Out))
                {
                    probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(formula);
                }
            }
            return(probabilityRangeToReachState);
        }
Пример #4
0
        public void CalculateMdpFlattened()
        {
            var model = new DegradedModeModel();

            model.System.SignalDetector1.F1.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.BuildInMdpWithNewStates;
            markovChainGenerator.AddFormulaToCheck(model.System.HazardActive);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var nmdp = markovChainGenerator.GenerateNestedMarkovDecisionProcess();

            var nmdpToMpd = new NmdpToMdpByFlattening(nmdp);
        }
Пример #5
0
        public void CreateMarkovChainWithBothHazardsRetraversal2()
        {
            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.AddFormulaToCheck(new BoundedUnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Finally, 6));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Finally, 6));
            markovChainGenerator.Configuration.UseCompactStateStorage             = true;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            markovChainGenerator.Configuration.EnableEarlyTermination             = false;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();

            var retraversalMarkovChainGenerator = new MarkovChainFromMarkovChainGenerator(markovChain);

            retraversalMarkovChainGenerator.Configuration.SuccessorCapacity *= 2;
            retraversalMarkovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Finally, 6));
            retraversalMarkovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Finally, 6));
            retraversalMarkovChainGenerator.Configuration.UseCompactStateStorage             = true;
            retraversalMarkovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            retraversalMarkovChainGenerator.GenerateLabeledMarkovChain();
        }
Пример #6
0
        public void CreateFaultAwareMarkovChainAllFaults()
        {
            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.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.EnableEarlyTermination          = false;
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Finally, 6));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Finally, 6));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #7
0
        public void CreateMarkovChainWithHazardsRetraversal2()
        {
            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.AddFormulaToCheck(model.PossibleCollision);
            markovChainGenerator.Configuration.UseCompactStateStorage             = true;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();

            var retraversalMarkovChainGenerator = new MarkovChainFromMarkovChainGenerator(markovChain);

            retraversalMarkovChainGenerator.Configuration.SuccessorCapacity *= 2;
            retraversalMarkovChainGenerator.AddFormulaToCheck(model.PossibleCollision);
            retraversalMarkovChainGenerator.Configuration.UseCompactStateStorage             = true;
            retraversalMarkovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = false;
            retraversalMarkovChainGenerator.GenerateLabeledMarkovChain();
        }
Пример #8
0
        public void CalculateMdpFlattenedWithoutFaults()
        {
            var model = Model.CreateOriginal();

            model.VehicleSet.LeftHV.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(3300000L, 1000000000L);
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuildInMdpWithNewStates;
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var nmdp = markovChainGenerator.GenerateNestedMarkovDecisionProcess();

            var nmdpToMpd = new NmdpToMdpByFlattening(nmdp);
        }
Пример #9
0
        public void CalculateHazardSingleCoreAllFaultsWithOnce()
        {
            var model = new DegradedModeModel();

            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;
            var formula     = new ExecutableStateFormula(() => model.System.HazardActive);
            var onceFormula = new UnaryFormula(formula, UnaryOperator.Once);
            var onceFault1  = new UnaryFormula(new FaultFormula(model.System.SignalDetector1.F1), UnaryOperator.Once);

            markovChainGenerator.AddFormulaToCheck(onceFault1);
            var formulaToCheck = new BoundedUnaryFormula(new BinaryFormula(onceFault1, BinaryOperator.And, onceFormula), UnaryOperator.Finally, 50);

            markovChainGenerator.AddFormulaToCheck(formulaToCheck);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            markovChainGenerator.Configuration.CpuCount = Int32.MaxValue;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();


            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(formulaToCheck);
                Console.Write($"Probability of hazard: {result}");
            }
        }
Пример #10
0
        public void CalculateMdpFlattenedWithoutFaults()
        {
            var model = new Model();

            SetProbabilities(model);
            model.Channel.MessageDropped.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(3300000L, 1000000000L);
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuildInMdpWithNewStates;
            markovChainGenerator.AddFormulaToCheck(model.PossibleCollision);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var nmdp = markovChainGenerator.GenerateNestedMarkovDecisionProcess();

            var nmdpToMpd = new NmdpToMdpByFlattening(nmdp);
        }
Пример #11
0
        public void CalculateHazardSingleCoreAllFaults()
        {
            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.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.CpuCount = 1;
            var formulaToCheck = new BoundedUnaryFormula(model.PossibleCollision, UnaryOperator.Finally, 50);

            markovChainGenerator.AddFormulaToCheck(formulaToCheck);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();


            using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbability(formulaToCheck);
                Console.Write($"Probability of formulaToCheck: {result}");
            }
        }
Пример #12
0
        public void CalculateHazardSingleCoreAllFaults()
        {
            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);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #13
0
        public void CreateMarkovChainWithBothHazardsRetraversal1()
        {
            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.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));
            markovChainGenerator.Configuration.UseCompactStateStorage             = true;
            markovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = true;
            markovChainGenerator.Configuration.EnableEarlyTermination             = false;
            var markovChain = markovChainGenerator.GenerateLabeledMarkovChain();

            var retraversalMarkovChainGenerator = new MarkovChainFromMarkovChainGenerator(markovChain);

            retraversalMarkovChainGenerator.Configuration.SuccessorCapacity *= 2;
            retraversalMarkovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            retraversalMarkovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));
            retraversalMarkovChainGenerator.Configuration.UseCompactStateStorage             = true;
            retraversalMarkovChainGenerator.Configuration.UseAtomarPropositionsAsStateLabels = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            retraversalMarkovChainGenerator.GenerateLabeledMarkovChain();
        }
Пример #14
0
        public void CalculateMdpNewStatesConstant()
        {
            var model = new DeadReckoningModel();

            model.Component.FF.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.BuildInMdpWithNewStates;
            markovChainGenerator.AddFormulaToCheck(model.Component.Hazard);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var nmdp = markovChainGenerator.GenerateNestedMarkovDecisionProcess();

            var nmdpToMpd = new NmdpToMdpByNewStates(nmdp, markovChainGenerator.Configuration.DefaultTraceOutput, true);
        }
Пример #15
0
        public void CalculateLtmdpWithoutStaticPruning()
        {
            var model = new Model();

            SetProbabilities(model);
            model.Channel.MessageDropped.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(3300000L, 1000000000L);
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.AddFormulaToCheck(model.PossibleCollision);
            foreach (var fault in model.Faults)
            {
                var faultFormula = new FaultFormula(fault);
                markovChainGenerator.AddFormulaToCheck(faultFormula);
            }
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
        }
Пример #16
0
        public void CalculateMdpFlattenedWithoutFaults()
        {
            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.BuildInMdpWithNewStates;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.BloodNotCleanedAndDialyzingFinished, UnaryOperator.Finally, 6));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.IncomingBloodWasNotOk, UnaryOperator.Finally, 6));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            var nmdp = markovChainGenerator.GenerateNestedMarkovDecisionProcess();

            var nmdpToMpd = new NmdpToMdpByFlattening(nmdp);
        }
Пример #17
0
        public void CalculateLtmdpWithoutStaticPruning()
        {
            var model = Model.CreateOriginal();

            model.VehicleSet.LeftHV.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(3300000L, 1000000000L);
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));

            /*
             * foreach (var fault in model.Faults)
             * {
             *      var faultFormula = new FaultFormula(fault);
             *      markovChainGenerator.AddFormulaToCheck(faultFormula);
             * }
             */
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
        }
Пример #18
0
        protected bool CheckInvariant(Formula invariant, params IComponent[] components)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var logAction = (Action <string>)(message => Output.Log("{0}", message));

            analysisTestsVariant.CreateModelChecker(SuppressCounterExampleGeneration, logAction);

            var model = TestModel.InitializeModel(components);

            var useCheckInvariantsInsteadOfCheckInvariant = Arguments.Length > 1 && (bool)Arguments[1];

            if (useCheckInvariantsInsteadOfCheckInvariant)
            {
                var modelFromFormulasGenerator = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);
                var results = analysisTestsVariant.CheckInvariants(modelFromFormulasGenerator, invariant);
                CounterExample = results[0].CounterExample;
                return(results[0].FormulaHolds);
            }

            var modelGenerator = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, invariant);

            Result         = analysisTestsVariant.CheckInvariant(modelGenerator, invariant);
            CounterExample = Result.CounterExample;
            return(Result.FormulaHolds);
        }
        /// <summary>
        ///   Checks whether the <paramref name="invariants" /> hold in all states of the <paramref name="model" />. The appropriate
        ///   model checker is chosen automatically.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="invariants">The invariants that should be checked.</param>
        public static AnalysisResult <SafetySharpRuntimeModel>[] CheckInvariants(ModelBase model, params Formula[] invariants)
        {
            var createModel        = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);
            var qualitativeChecker = new QualitativeChecker <SafetySharpRuntimeModel> {
                Configuration = TraversalConfiguration
            };

            return(qualitativeChecker.CheckInvariants(createModel, invariants));
        }
Пример #20
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}");
            }
        }
Пример #21
0
        protected bool[] CheckInvariants(IComponent component, params Formula[] invariants)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var logAction = (Action <string>)(message => Output.Log("{0}", message));

            analysisTestsVariant.CreateModelChecker(SuppressCounterExampleGeneration, logAction);

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(TestModel.InitializeModel(component));

            var results = analysisTestsVariant.CheckInvariants(modelCreator, invariants);

            CounterExamples = results.Select(result => result.CounterExample).ToArray();
            return(results.Select(result => result.FormulaHolds).ToArray());
        }
Пример #22
0
        public void CreateMarkovChainWithHazards()
        {
            var model = new DeadReckoningModel();

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.AddFormulaToCheck(model.Component.Hazard);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #23
0
        public void CalculateLtmdpWithoutStaticPruningSingleCore()
        {
            var model = Model.CreateOriginal();

            model.VehicleSet.LeftHV.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.ModelCapacity      = new ModelCapacityByModelSize(3300000L, 1000000000L);
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = false;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            var collision  = new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50);
            var falseAlarm = new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50);

            markovChainGenerator.AddFormulaToCheck(collision);
            markovChainGenerator.AddFormulaToCheck(falseAlarm);

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

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

            using (var modelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, markovChainGenerator.Configuration.DefaultTraceOutput))
            {
                var result = modelChecker.CalculateProbabilityRange(falseAlarm);
                Console.Write($"Probability of falseAlarm: {result}");
            }
        }
Пример #24
0
        public void CreateMarkovChainWithHazards()
        {
            var model = new DegradedModeModel();

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.AddFormulaToCheck(model.System.HazardActive);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #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}");
            }
        }
Пример #26
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}");
            }
        }
Пример #27
0
        public void CreateMarkovChainWithFalseFormula()
        {
            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.AddFormulaToCheck(new ExecutableStateFormula(() => false));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Пример #28
0
        public void CalculateLtmdpWithoutFaultsWithPruning()
        {
            var model = new DeadReckoningModel();

            model.Component.FF.ProbabilityOfOccurrence = null;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.Configuration.EnableStaticPruningOptimization = true;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.AddFormulaToCheck(model.Component.Hazard);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
        }
        /// <summary>
        ///   Calculates the probability of formula.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="formula">The state formula to be checked.</param>
        /// <param name="terminateEarlyFormula">When terminateEarlyFormula is satisfied stop building the state space.</param>
        /// <param name="bound">The maximal number of steps. If stateFormula is satisfied the first time any step later than bound, this probability does not count into the end result.</param>
        public static Probability CalculateProbabilityOfFormulaBounded(ModelBase model, Formula formula, Formula terminateEarlyFormula, int bound)
        {
            Probability probability;

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

            var markovChainGenerator = new DtmcFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = TraversalConfiguration
            };

            markovChainGenerator.Configuration.SuccessorCapacity *= 2;
            markovChainGenerator.AddFormulaToCheck(formula);
            var markovChain = markovChainGenerator.GenerateMarkovChain(terminateEarlyFormula);

            using (var modelChecker = new BuiltinDtmcModelChecker(markovChain, System.Console.Out))
            {
                probability = modelChecker.CalculateProbability(formula);
            }
            return(probability);
        }
Пример #30
0
        public void CreateFaultAwareMarkovChainPositionDetectorMis()
        {
            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.AddFormulaToCheck(new FaultFormula(model.HeightControl.PreControl.PositionDetector.Misdetection));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.Collision, UnaryOperator.Finally, 50));
            markovChainGenerator.AddFormulaToCheck(new BoundedUnaryFormula(model.FalseAlarm, UnaryOperator.Finally, 50));
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateMarkovChain();
        }