Example #1
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = Ltl.X(true);
				var expected = new UnaryFormula(
					new StateFormula(new BooleanLiteralExpression(true)),
					UnaryFormulaOperator.Next, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = Ltl.X(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(new BinaryExpression(BinaryOperator.Less, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
					UnaryFormulaOperator.Next, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = Ltl.X(Ltl.X(intValue <= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(new BinaryExpression(BinaryOperator.LessEqual, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
						UnaryFormulaOperator.Next, PathQuantifier.None),
					UnaryFormulaOperator.Next, PathQuantifier.None);

				Check(actual, expected);
			}
		}
Example #2
0
		protected override void Check()
		{
			{
				var actual = !((CtlFormula)false);
				var expected = new UnaryFormula(
					new StateFormula(new BooleanLiteralExpression(false)),
					UnaryFormulaOperator.Not, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = !(Ctl.AX(true));
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(new BooleanLiteralExpression(true)), UnaryFormulaOperator.Next, PathQuantifier.All),
					UnaryFormulaOperator.Not, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = !Ctl.EF(true);
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(new BooleanLiteralExpression(true)), UnaryFormulaOperator.Finally, PathQuantifier.Exists),
					UnaryFormulaOperator.Not, PathQuantifier.None);

				Check(actual, expected);
			}
		}
Example #3
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = Ctl.AX(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(new BinaryExpression(BinaryOperator.Less, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
					UnaryFormulaOperator.Next, PathQuantifier.All);

				Check(actual, expected);
			}

			{
				var actual = Ctl.AX(Ctl.AX(intValue <= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(new BinaryExpression(BinaryOperator.LessEqual, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
						UnaryFormulaOperator.Next, PathQuantifier.All),
					UnaryFormulaOperator.Next, PathQuantifier.All);

				Check(actual, expected);
			}

			{
				var actual = Ctl.EX(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(new BinaryExpression(BinaryOperator.Less, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
					UnaryFormulaOperator.Next, PathQuantifier.Exists);

				Check(actual, expected);
			}

			{
				var actual = Ctl.EX(Ctl.EX(intValue <= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(new BinaryExpression(BinaryOperator.LessEqual, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
						UnaryFormulaOperator.Next, PathQuantifier.Exists),
					UnaryFormulaOperator.Next, PathQuantifier.Exists);

				Check(actual, expected);
			}
		}
Example #4
0
		protected override void Check()
		{
			{
				var actual = !(X(true));
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(() => true), UnaryOperator.Next),
					UnaryOperator.Not);

				Check(actual, expected);
			}

			{
				var actual = !X(true);
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(() => true), UnaryOperator.Next),
					UnaryOperator.Not);

				Check(actual, expected);
			}
		}
Example #5
0
		protected override void Check()
		{
			{
				var actual = !(Ltl.X(true));
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(new BooleanLiteralExpression(true)), UnaryFormulaOperator.Next, PathQuantifier.None),
					UnaryFormulaOperator.Not, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = !Ltl.X(true);
				var expected = new UnaryFormula(
					new UnaryFormula(new StateFormula(new BooleanLiteralExpression(true)), UnaryFormulaOperator.Next, PathQuantifier.None),
					UnaryFormulaOperator.Not, PathQuantifier.None);

				Check(actual, expected);
			}
		}
Example #6
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = G(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(() => intValue < 7),
					UnaryOperator.Globally);

				Check(actual, expected);
			}

			{
				var actual = G(G(intValue >= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(() => intValue >= 7),
						UnaryOperator.Globally),
					UnaryOperator.Globally);

				Check(actual, expected);
			}

			{
				var actual = AG(EG(intValue >= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new UnaryFormula(
							new UnaryFormula(
								new StateFormula(() => intValue >= 7),
								UnaryOperator.Globally),
							UnaryOperator.Exists),
						UnaryOperator.Globally),
					UnaryOperator.All);

				Check(actual, expected);
			}
		}
Example #7
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = X(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(() => intValue < 7),
					UnaryOperator.Next);

				Check(actual, expected);
			}

			{
				var actual = X(X(intValue >= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(() => intValue >= 7),
						UnaryOperator.Next),
					UnaryOperator.Next);

				Check(actual, expected);
			}

			{
				var actual = AX(EX(intValue >= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new UnaryFormula(
							new UnaryFormula(
								new StateFormula(() => intValue >= 7),
								UnaryOperator.Next),
							UnaryOperator.Exists),
						UnaryOperator.Next),
					UnaryOperator.All);

				Check(actual, expected);
			}
		}
        /// <summary>
        ///   Calculates the probability to reach a state where <paramref name="stateFormula" /> holds.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="stateFormula">The state formula to be checked.</param>
        public static Probability CalculateProbabilityToReachState(ModelBase model, Formula stateFormula)
        {
            Probability probabilityToReachState;

            var probabilityToReachStateFormula = new UnaryFormula(stateFormula, UnaryOperator.Finally);

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            markovChainGenerator.AddFormulaToCheck(probabilityToReachStateFormula);
            var markovChain = markovChainGenerator.GenerateMarkovChain(stateFormula);

            using (var modelChecker = new BuiltinDtmcModelChecker(markovChain, System.Console.Out))
            {
                probabilityToReachState = modelChecker.CalculateProbability(probabilityToReachStateFormula);
            }
            return(probabilityToReachState);
        }
Example #9
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = Ltl.F(intValue < 7);
				var expected = new UnaryFormula(
					new StateFormula(new BinaryExpression(BinaryOperator.Less, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
					UnaryFormulaOperator.Finally, PathQuantifier.None);

				Check(actual, expected);
			}

			{
				var actual = Ltl.F(Ltl.F(intValue >= 7));
				var expected = new UnaryFormula(
					new UnaryFormula(
						new StateFormula(new BinaryExpression(BinaryOperator.GreaterEqual, new IntegerLiteralExpression(7), new IntegerLiteralExpression(7))),
						UnaryFormulaOperator.Finally, PathQuantifier.None),
					UnaryFormulaOperator.Finally, PathQuantifier.None);

				Check(actual, expected);
			}
		}
        /// <summary>
        ///   Calculates the probability to reach a state where <paramref name="stateFormula" /> holds.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="stateFormula">The state formula which _must_ finally be true.</param>
        public static ProbabilityRange CalculateProbabilityRangeToReachState(ModelBase model, Formula stateFormula)
        {
            ProbabilityRange probabilityRangeToReachState;

            var probabilityToReachStateFormula = new UnaryFormula(stateFormula, UnaryOperator.Finally);

            var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);

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

            nmdpGenerator.AddFormulaToCheck(probabilityToReachStateFormula);
            nmdpGenerator.Configuration.SuccessorCapacity *= 8;
            var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess(stateFormula);

            if (_convertNmdpToMdp)
            {
                var nmdpToMpd = new NmdpToMdp(nmdp);
                var mdp       = nmdpToMpd.MarkovDecisionProcess;
                using (var modelChecker = new BuiltinMdpModelChecker(mdp, System.Console.Out))
                {
                    probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(probabilityToReachStateFormula);
                }
            }
            else
            {
                using (var modelChecker = new BuiltinNmdpModelChecker(nmdp, System.Console.Out))
                {
                    probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(probabilityToReachStateFormula);
                }
            }

            return(probabilityRangeToReachState);
        }
Example #11
0
		protected override void Check()
		{
			var intValue = 7;

			{
				var actual = U(intValue < 7, false);
				var expected = new BinaryFormula(
					new StateFormula(() => intValue < 7),
					BinaryOperator.Until,
					new StateFormula(() => false));

				Check(actual, expected);
			}

			{
				var actual = U(G(intValue >= 7), false);
				var expected = new BinaryFormula(
					new UnaryFormula(
						new StateFormula(() => intValue >= 7),
						UnaryOperator.Globally),
					BinaryOperator.Until,
					new StateFormula(() => false));

				Check(actual, expected);
			}

			{
				var actual = U(intValue >= 7, F(false));
				var expected = new BinaryFormula(
					new StateFormula(() => intValue >= 7),
					BinaryOperator.Until,
					new UnaryFormula(new StateFormula(() => false), UnaryOperator.Finally));

				Check(actual, expected);
			}

			{
				var actual = U(G(intValue >= 7), F(false));
				var expected = new BinaryFormula(
					new UnaryFormula(
						new StateFormula(() => intValue >= 7),
						UnaryOperator.Globally),
					BinaryOperator.Until,
					new UnaryFormula(new StateFormula(() => false), UnaryOperator.Finally));

				Check(actual, expected);
			}

			{
				var actual = AU(G(intValue >= 7), F(false));
				var expected = new UnaryFormula(
					new BinaryFormula(
						new UnaryFormula(
							new StateFormula(() => intValue >= 7),
							UnaryOperator.Globally),
						BinaryOperator.Until,
						new UnaryFormula(new StateFormula(() => false), UnaryOperator.Finally)),
					UnaryOperator.All);

				Check(actual, expected);
			}

			{
				var actual = EU(G(intValue >= 7), F(false));
				var expected = new UnaryFormula(
					new BinaryFormula(
						new UnaryFormula(
							new StateFormula(() => intValue >= 7),
							UnaryOperator.Globally),
						BinaryOperator.Until,
						new UnaryFormula(new StateFormula(() => false), UnaryOperator.Finally)),
					UnaryOperator.Exists);

				Check(actual, expected);
			}
		}
        /// <summary>
        ///   Calculates the probability to reach a state where <paramref name="stateFormula" /> holds.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="stateFormula">The state formula which _must_ finally be true.</param>
        public static ProbabilityRange CalculateProbabilityRangeToReachState(ModelBase model, Formula stateFormula)
        {
            var finallyStateFormula = new UnaryFormula(stateFormula, UnaryOperator.Finally);

            return(CalculateProbabilityRangeOfFormula(model, finallyStateFormula));
        }