protected override void Check() { var c = new C(); Probability probabilityOfInvariantViolation; Formula invariantViolated = c.ViolateInvariant; var finallyInvariantViolated = new UnaryFormula(invariantViolated, UnaryOperator.Finally); var markovChainGenerator = new SafetySharpMarkovChainFromExecutableModelGenerator(TestModel.InitializeModel(c)); markovChainGenerator.Configuration.ModelCapacity = ModelCapacityByMemorySize.Small; markovChainGenerator.Configuration.LtmcModelChecker = (ISSE.SafetyChecking.LtmcModelChecker)Arguments[0]; markovChainGenerator.AddFormulaToCheck(finallyInvariantViolated); var ltmc = markovChainGenerator.GenerateLabeledMarkovChain(); var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, ltmc, Output.TextWriterAdapter()); using (modelChecker) { probabilityOfInvariantViolation = modelChecker.CalculateProbability(finallyInvariantViolated); } // 1.0-(1.0-0.1)^10 = 0.6513215599 probabilityOfInvariantViolation.Is(0.6513215599, 0.00001).ShouldBe(true); }
private void CheckOnceWithAtormarOperand(AnalysisConfiguration configuration) { var m = new Model(); Probability probability; //var final9Formula = new UnaryFormula(Model.IsInState9, UnaryOperator.Finally); var once7Formula = new UnaryFormula(Model.IsInState7, 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 = configuration; markovChainGenerator.AddFormulaToCheck(final9Once7Formula); var ltmc = markovChainGenerator.GenerateLabeledMarkovChain(); var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter()); using (modelChecker) { probability = modelChecker.CalculateProbability(final9Once7Formula); } probability.Is(0.4 * 0.4 + 0.6, 0.00000001).ShouldBe(true); }
public void CalculateHazardSingleCoreAllFaults() { var model = new DeadReckoningModel(); 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.Component.Hazard); var formulaToCheck = new BoundedUnaryFormula(formula, UnaryOperator.Finally, 10); 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; 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}"); } }
/// <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> public static Probability CalculateProbabilityOfFormula(ModelBase model, Formula formula) { Probability probability; var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model); var markovChainGenerator = new MarkovChainFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel) { Configuration = TraversalConfiguration }; markovChainGenerator.Configuration.SuccessorCapacity *= 2; markovChainGenerator.AddFormulaToCheck(formula); markovChainGenerator.Configuration.UseCompactStateStorage = true; var markovChain = markovChainGenerator.GenerateLabeledMarkovChain(); using (var modelChecker = new ConfigurationDependentLtmcModelChecker(markovChainGenerator.Configuration, markovChain, TraversalConfiguration.DefaultTraceOutput)) { probability = modelChecker.CalculateProbability(formula); } System.GC.Collect(); return(probability); }