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}"); } }
public void Simulate() { var model = new ExampleModelBase(); var tc = SafetySharpModelChecker.TraversalConfiguration; tc.AllowFaultsOnInitialTransitions = false; tc.UseOptionProbabilitiesInSimulation = false; SafetySharpProbabilisticSimulator.Configuration = tc; var is3Formula = new ExecutableStateFormula(() => model.ModelComponent.Value == 3); var f1Formula = new FaultFormula(model.ModelComponent.F1); var loopRequestBugFormula = new ExecutableStateFormula(() => model.ModelComponent.LoopRequestBug); SafetySharpProbabilisticSimulator simulator = new SafetySharpProbabilisticSimulator(model, is3Formula, f1Formula, loopRequestBugFormula); for (var i = 0; i < 100; i++) { simulator.SimulateSteps(5); var noIs3 = simulator.GetCountOfSatisfiedOnTrace(is3Formula); var noF1 = simulator.GetCountOfSatisfiedOnTrace(f1Formula); var probabilityOfTrace = simulator.TraceProbability; Console.WriteLine($"No of Is3: {noIs3}"); Console.WriteLine($"No of f1 {noF1}: {noF1}"); Console.WriteLine($"Probability of trace: {probabilityOfTrace}"); Console.WriteLine(); } }
public void CalculateProbability() { var model = new ExampleModelBase(); var isHazardActive = new ExecutableStateFormula(() => model.ModelComponent.HazardActive, "HazardActive"); var tc = SafetySharpModelChecker.TraversalConfiguration; tc.WriteGraphvizModels = true; SafetySharpModelChecker.TraversalConfiguration = tc; var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, isHazardActive, 50); Console.Write($"Probability of hazard: {result}"); }
protected override void Check() { var intValue = 7; { var actual = ((Formula)false).Implies(intValue < 7); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Implication, new ExecutableStateFormula(() => intValue < 7)); Check(actual, expected); } { var actual = ((Formula)false).Implies(F(intValue < 7)); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Implication, new UnaryFormula(new ExecutableStateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } { var actual = false.Implies(intValue < 7); var expected = new ExecutableStateFormula(() => !false || intValue < 7); Check(actual, expected); } { var actual = false.Implies(F(intValue < 7)); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Implication, new UnaryFormula(new ExecutableStateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } true.Implies(true).ShouldBe(true); false.Implies(true).ShouldBe(true); true.Implies(false).ShouldBe(false); false.Implies(false).ShouldBe(true); }
protected override void Check() { var intValue = 7; { var actual = ((Formula)false).EquivalentTo(intValue < 7); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Equivalence, new ExecutableStateFormula(() => intValue < 7)); Check(actual, expected); } { var actual = ((Formula)false).EquivalentTo(F(intValue < 7)); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Equivalence, new UnaryFormula(new ExecutableStateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } { Formula actual = false.EquivalentTo(intValue < 7); var expected = new ExecutableStateFormula(() => (false && intValue < 7) || (true && intValue >= 7)); Check(actual, expected); } { var actual = false.EquivalentTo(F(intValue < 7)); var expected = new BinaryFormula( new ExecutableStateFormula(() => false), BinaryOperator.Equivalence, new UnaryFormula(new ExecutableStateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } true.EquivalentTo(true).ShouldBe(true); false.EquivalentTo(true).ShouldBe(false); true.EquivalentTo(false).ShouldBe(false); false.EquivalentTo(false).ShouldBe(true); }
public void CalculateProbability() { var model = new ExampleModelBase(); var isHazardActive = new ExecutableStateFormula(() => model.ModelComponent.HazardActive, "HazardActive"); var tc = SafetySharpModelChecker.TraversalConfiguration; tc.WriteGraphvizModels = true; tc.AllowFaultsOnInitialTransitions = false; tc.RetraversalNormalizations = RetraversalNormalizations.EmbedObserversIntoModel; SafetySharpModelChecker.TraversalConfiguration = tc; var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, isHazardActive, 50); Console.Write($"Probability of hazard: {result}"); }
public void CalculateProbability() { var model = new ExampleModelBase(); var tc = SafetySharpModelChecker.TraversalConfiguration; tc.WriteGraphvizModels = true; tc.AllowFaultsOnInitialTransitions = false; tc.UseAtomarPropositionsAsStateLabels = true; tc.UseCompactStateStorage = true; SafetySharpModelChecker.TraversalConfiguration = tc; var result = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, model.ModelComponent.Value == 3, 50); Console.Write($"Probability of hazard: {result}"); var is3Formula = new ExecutableStateFormula(() => model.ModelComponent.Value == 3); var loopRequestBug = new ExecutableStateFormula(() => model.ModelComponent.LoopRequestBug); var formula2OnceLoopRequestBug = new BinaryFormula(is3Formula, BinaryOperator.And, new UnaryFormula(loopRequestBug, UnaryOperator.Once)); var result2 = SafetySharpModelChecker.CalculateProbabilityToReachStateBounded(model, formula2OnceLoopRequestBug, 50); Console.WriteLine($"Probability of {formula2OnceLoopRequestBug}: {result2}"); }
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}"); } }
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}"); } }