Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void CreateMarkovChainWithHazardsRetraversal2()
        {
            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 = false;
            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 = false;
            retraversalMarkovChainGenerator.GenerateLabeledMarkovChain();
        }
Ejemplo n.º 3
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}");
            }
        }
Ejemplo n.º 4
0
        public void CalculateHazardProbability()
        {
            var model  = new DegradedModeModel();
            var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);

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

            model.System.SignalDetector1.F1.ProbabilityOfOccurrence = new Probability(0.0);
            var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);

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

            SafetySharpModelChecker.TraversalConfiguration.EnableEarlyTermination = false;
            var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);

            SafetySharpModelChecker.TraversalConfiguration.EnableEarlyTermination = true;
            Console.Write($"Probability of hazard: {result}");
        }
Ejemplo n.º 7
0
        public void CalculateRangeHazardLtmdp()
        {
            var model = new DegradedModeModel();

            model.System.SignalDetector1.F1.ProbabilityOfOccurrence = null;

            SafetySharpModelChecker.TraversalConfiguration.EnableStaticPruningOptimization = true;
            var result = SafetySharpModelChecker.CalculateProbabilityRangeToReachStateBounded(model, model.System.HazardActive, 50);

            Console.Write($"Probability of hazard: {result}");
        }
Ejemplo n.º 8
0
        public void CalculateHazardProbability()
        {
            var tc = SafetySharpModelChecker.TraversalConfiguration;

            tc.WriteGraphvizModels                         = true;
            tc.EnableStaticPruningOptimization             = false;
            SafetySharpModelChecker.TraversalConfiguration = tc;

            var model  = new DegradedModeModel();
            var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);

            Console.WriteLine($"Probability of hazard in model: {result}");
        }
Ejemplo n.º 9
0
        public void CalculateHazardSingleCore()
        {
            var model = new DegradedModeModel();

            SafetySharpModelChecker.TraversalConfiguration.CpuCount = 1;
            SafetySharpModelChecker.TraversalConfiguration.EnableEarlyTermination          = false;
            SafetySharpModelChecker.TraversalConfiguration.EnableStaticPruningOptimization = false;
            var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);

            SafetySharpModelChecker.TraversalConfiguration.CpuCount = Int32.MaxValue;
            SafetySharpModelChecker.TraversalConfiguration.EnableEarlyTermination          = true;
            SafetySharpModelChecker.TraversalConfiguration.EnableStaticPruningOptimization = true;
            Console.Write($"Probability of hazard: {result}");
        }
Ejemplo n.º 10
0
        public void CalculateDcca()
        {
            var model = new DegradedModeModel();

            var analysis = new SafetySharpSafetyAnalysis {
                Backend = SafetyAnalysisBackend.FaultOptimizedOnTheFly, Heuristics = { new MaximalSafeSetHeuristic(model.Faults) }
            };
            var result = analysis.ComputeMinimalCriticalSets(model, model.System.HazardActive);
            //result.SaveCounterExamples("counter examples/height control/dcca/collision/original");

            var orderResult = SafetySharpOrderAnalysis.ComputeOrderRelationships(result);

            Console.WriteLine(orderResult);
        }
Ejemplo n.º 11
0
        public void CalculateHazardProbabilityGraph()
        {
            var model = new DegradedModeModel();

            var minValue = 0.0;
            var maxValue = 1.0;
            var steps    = 250;
            var stepSize = (maxValue - minValue) / (steps - 1);

            var sourceValues = new double[steps];
            var resultValues = new double[steps];

            for (var i = 0; i < steps; i++)
            {
                var currentValue = i * stepSize;
                sourceValues[i] = currentValue;
                model.System.SignalDetector1.F1.ProbabilityOfOccurrence = new Probability(currentValue);
                var currentResult = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.System.HazardActive, 50);
                GC.Collect();
                resultValues[i] = currentResult.Value;
            }

            var fileWriter = new StreamWriter("PrecisenessTradeoff/graph.csv", append: false);
            var csvWriter  = new CsvWriter(fileWriter);

            csvWriter.AddEntry("Step");
            for (var i = 0; i < steps; i++)
            {
                csvWriter.AddEntry(i);
            }
            csvWriter.NewLine();

            csvWriter.AddEntry("Pr(F1)");
            for (var i = 0; i < steps; i++)
            {
                csvWriter.AddEntry(sourceValues[i]);
            }
            csvWriter.NewLine();

            csvWriter.AddEntry("Pr(Hazard)");
            for (var i = 0; i < steps; i++)
            {
                csvWriter.AddEntry(resultValues[i]);
            }
            csvWriter.NewLine();
            fileWriter.Close();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        public void CalculateLtmdpWithoutFaultsWithPruning()
        {
            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 = true;
            markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
            markovChainGenerator.AddFormulaToCheck(model.System.HazardActive);
            markovChainGenerator.Configuration.UseCompactStateStorage = true;
            markovChainGenerator.Configuration.EnableEarlyTermination = false;
            var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
        }
Ejemplo n.º 14
0
        public void CreateFaultAwareMarkovChainAllFaults()
        {
            var model = new DegradedModeModel();

            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.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 markovChain = markovChainGenerator.GenerateMarkovChain();
        }
Ejemplo n.º 15
0
        public void CalculateLtmdpWithoutStaticPruningSingleCore()
        {
            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.BuiltInLtmdp;
            var formula        = new ExecutableStateFormula(() => model.System.HazardActive);
            var formulaToCheck = new BoundedUnaryFormula(formula, 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.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(formulaToCheck);
                Console.Write($"Probability of hazard: {result}");
            }
        }