コード例 #1
0
        public void Parametric(Model model, string name)
        {
            SetProbabilities(model);
            var parameter = new QuantitativeParametricAnalysisParameter
            {
                StateFormula           = model.IncomingBloodWasNotOk,
                Bound                  = null,
                From                   = 0.001,
                To                     = 0.1,
                Steps                  = 25,
                UpdateParameterInModel = value => { model.HdMachine.DialyzingFluidDeliverySystem.WaterPreparation.WaterHeaterDefect.ProbabilityOfOccurrence = new Probability(value); }
            };
            var result = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            var fileWriterContamination = new StreamWriter($"{name}contamination.csv", append: false);

            result.ToCsv(fileWriterContamination);
            fileWriterContamination.Close();

            parameter.StateFormula = model.BloodNotCleanedAndDialyzingFinished;
            result = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            var fileWriterUnsuccessful = new StreamWriter($"{name}unsuccessful.csv", append: false);

            result.ToCsv(fileWriterUnsuccessful);
            fileWriterUnsuccessful.Close();
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public void Parametric()
        {
            var tc = SafetySharpModelChecker.TraversalConfiguration;

            tc.LtmcModelChecker = LtmcModelChecker.BuiltInLtmc;
            //tc.UseAtomarPropositionsAsStateLabels = false;
            SafetySharpModelChecker.TraversalConfiguration = tc;

            var model = new Model();

            model.Channel.MessageDropped.ProbabilityOfOccurrence = new Probability(0.0001);
            model.CrossingController.Motor.BarrierMotorStuck.ProbabilityOfOccurrence             = new Probability(0.001);
            model.CrossingController.Sensor.BarrierSensorFailure.ProbabilityOfOccurrence         = new Probability(0.00003);
            model.CrossingController.TrainSensor.ErroneousTrainDetection.ProbabilityOfOccurrence = new Probability(0.0002);
            model.TrainController.Brakes.BrakesFailure.ProbabilityOfOccurrence            = new Probability(0.00002);
            model.TrainController.Odometer.OdometerPositionOffset.ProbabilityOfOccurrence = new Probability(0.02);
            model.TrainController.Odometer.OdometerSpeedOffset.ProbabilityOfOccurrence    = new Probability(0.02);

            Action <double> updateParameterBsInModel = value =>
            {
                model.CrossingController.Sensor.BarrierSensorFailure.ProbabilityOfOccurrence = new Probability(value);
            };

            Action <double> updateParameterOpInModel = value =>
            {
                model.TrainController.Odometer.OdometerPositionOffset.ProbabilityOfOccurrence = new Probability(value);
            };

            var parameter = new QuantitativeParametricAnalysisParameter
            {
                StateFormula           = model.PossibleCollision,
                Bound                  = 50,
                From                   = 0.000001,
                To                     = 0.01,
                Steps                  = 25,
                UpdateParameterInModel = updateParameterBsInModel
            };

            var result     = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            var fileWriter = new StreamWriter("ParametricBsPossibleCollision.csv", append: false);

            result.ToCsv(fileWriter);
            fileWriter.Close();

            parameter.UpdateParameterInModel = updateParameterOpInModel;
            result     = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            fileWriter = new StreamWriter("ParametricOpPossibleCollision.csv", append: false);
            result.ToCsv(fileWriter);
            fileWriter.Close();
        }
コード例 #4
0
        public void ParametricLbInOriginalDesign()
        {
            var model = Model.CreateOriginal();

            SetProbabilities(model);

            Action <double> updateParameterInModel = value =>
            {
                foreach (var detector in model.Components.OfType <LightBarrier>())
                {
                    detector.FalseDetection.ProbabilityOfOccurrence = new Probability(value);
                }
            };

            var parameter = new QuantitativeParametricAnalysisParameter
            {
                StateFormula           = model.Collision,
                Bound                  = 50,
                From                   = 0.000001,
                To                     = 0.01,
                Steps                  = 25,
                UpdateParameterInModel = updateParameterInModel
            };

            var result     = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            var fileWriter = new StreamWriter("ParametricLbCollision.csv", append: false);

            result.ToCsv(fileWriter);
            fileWriter.Close();

            parameter.StateFormula = model.FalseAlarm;
            result     = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            fileWriter = new StreamWriter("ParametricLbFalseAlarm.csv", append: false);
            result.ToCsv(fileWriter);
            fileWriter.Close();

            parameter.StateFormula = model.PreventedCollision;
            result     = SafetySharpModelChecker.ConductQuantitativeParametricAnalysis(model, parameter);
            fileWriter = new StreamWriter("ParametricLbPreventedCollision.csv", append: false);
            result.ToCsv(fileWriter);
            fileWriter.Close();
        }
コード例 #5
0
        /// <summary>
        ///   Conduct a quantitative analysis where parameters may vary
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="parameter">The parameters of the parametric analysis.</param>
        public static QuantitativeParametricAnalysisResults ConductQuantitativeParametricAnalysis(string ocFileName, string mainNode, IEnumerable <Fault> faults, QuantitativeParametricAnalysisParameter parameter)
        {
            var stepSize = (parameter.To - parameter.From) / (parameter.Steps - 1);

            var sourceValues = new double[parameter.Steps];
            var resultValues = new double[parameter.Steps];

            var faultsFlat = faults.ToArray();

            for (var i = 0; i < parameter.Steps; i++)
            {
                var currentValue = i * stepSize;
                sourceValues[i] = currentValue;
                parameter.UpdateParameterInModel(currentValue);

                double currentResult;
                if (parameter.Bound.HasValue)
                {
                    currentResult = CalculateProbabilityToReachStateBounded(ocFileName, mainNode, faultsFlat, parameter.StateFormula, parameter.Bound.Value).Value;
                }
                else
                {
                    currentResult = CalculateProbabilityToReachState(ocFileName, mainNode, faultsFlat, parameter.StateFormula).Value;
                }
                GC.Collect();
                resultValues[i] = currentResult;
            }

            return(new QuantitativeParametricAnalysisResults
            {
                From = parameter.From,
                To = parameter.To,
                Steps = parameter.Steps,
                SourceValues = sourceValues,
                ResultValues = resultValues
            });
        }
コード例 #6
0
        /// <summary>
        ///   Conduct a quantitative analysis where parameters may vary
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="parameter">The parameters of the parametric analysis.</param>
        public static QuantitativeParametricAnalysisResults ConductQuantitativeParametricAnalysis(ModelBase model, QuantitativeParametricAnalysisParameter parameter)
        {
            var stepSize = (parameter.To - parameter.From) / (parameter.Steps - 1);

            var sourceValues = new double[parameter.Steps];
            var resultValues = new double[parameter.Steps];

            for (var i = 0; i < parameter.Steps; i++)
            {
                var currentValue = i * stepSize;
                sourceValues[i] = currentValue;
                parameter.UpdateParameterInModel(currentValue);

                double currentResult;
                if (parameter.Bound.HasValue)
                {
                    currentResult = CalculateProbabilityToReachStateBounded(model, parameter.StateFormula, parameter.Bound.Value).Value;
                }
                else
                {
                    currentResult = CalculateProbabilityToReachState(model, parameter.StateFormula).Value;
                }
                System.GC.Collect();
                resultValues[i] = currentResult;
            }

            var result = new QuantitativeParametricAnalysisResults
            {
                From         = parameter.From,
                To           = parameter.To,
                Steps        = parameter.Steps,
                SourceValues = sourceValues,
                ResultValues = resultValues
            };

            return(result);
        }