Ejemplo n.º 1
0
        public static void RunFormula(string formula)
        {
            FormulaNode parsedFormula = null;

            PrintLine();
            Console.WriteLine("formula: " + formula);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                parsedFormula = FormulaParser.Parse(formula);
            } catch (Exception e)
            {
                Console.WriteLine("Parsing error: " + e.Message);
                return;
            }
            CTLSatisfiabilityChecker checker = new CTLSatisfiabilityChecker(parsedFormula);
            bool res = checker.Check();

            stopwatch.Stop();
            double time = ((double)stopwatch.ElapsedMilliseconds / 1000.0);

            Console.WriteLine("iterations: " + checker.Iterations);
            Console.WriteLine("time: " + time);
            Console.WriteLine("result: " + ConvSAT(res));

            PrintLine();
        }
Ejemplo n.º 2
0
        /*
         * <au> is an elementary formula of the form EX(ER(p,q))
         */
        private FormulaNode ComputeAUFragment(FormulaNode au, FormulaNode stateSet, SymbolicState state)
        {
#if DEBUG
            Console.WriteLine("Computing fragment for " + au);
#endif
            FormulaNode frag     = FormulaParser.Parse("~TRUE");
            FormulaNode notLeft  = new FormulaNode(LogicOperator.NOT, au[0][0], null);
            FormulaNode notRight = new FormulaNode(LogicOperator.NOT, au[0][1], null);
            while (true)
            {
                string        nextName   = "succ" + uniqueId.GetTicket().ToString();
                SymbolicState next       = new SymbolicState(elementary, nextName);
                FormulaNode   transition = GenTransition(state, next);
                FormulaNode   memberOf   = SymbolicState.Substitute(stateSet, state, next);
                FormulaNode   nextFrag   = SymbolicState.Substitute(frag, state, next);
                FormulaNode   newFrag    = new FormulaNode(LogicOperator.AND, transition, memberOf);
                newFrag = new FormulaNode(LogicOperator.AND, newFrag, nextFrag);
                newFrag = next.Quantify(LogicOperator.EXISTS, newFrag);

                newFrag = new FormulaNode(LogicOperator.AND, state.ValueOf(notLeft.NNF()), newFrag);

                // Add the big conjunction needed for fragAU
                List <FormulaNode> fragTerms = new List <FormulaNode>();

                foreach (FormulaNode el in elementary)
                {
                    if (el.GetLogicOperator() != LogicOperator.EX)
                    {
                        continue;
                    }

                    nextName   = "succ" + uniqueId.GetTicket().ToString();
                    next       = new SymbolicState(elementary, nextName);
                    transition = GenTransition(state, next);
                    memberOf   = SymbolicState.Substitute(stateSet, state, next);
                    nextFrag   = SymbolicState.Substitute(frag, state, next);


                    FormulaNode lhs = state.ValueOf(el);
                    FormulaNode rhs = new FormulaNode(LogicOperator.AND, transition, memberOf);
                    rhs = new FormulaNode(LogicOperator.AND, rhs, nextFrag);
                    rhs = new FormulaNode(LogicOperator.AND, rhs, next.ValueOf(SymbolicState.Substitute(el[0], state, next)));
                    rhs = next.Quantify(LogicOperator.EXISTS, rhs);

                    fragTerms.Add(new FormulaNode(LogicOperator.IMP, lhs, rhs));
                }

                newFrag = new FormulaNode(LogicOperator.AND, newFrag, JoinTerms(LogicOperator.AND, fragTerms));
                newFrag = new FormulaNode(LogicOperator.OR, state.ValueOf(notRight.NNF()), newFrag);

                if (IsFixpoint(newFrag, frag, state))
                {
                    return(frag);
                }

                frag = newFrag;
            }
        }
Ejemplo n.º 3
0
        private void ComputeEUFragments(FormulaNode stateSet, SymbolicState state)
        {
            #if DEBUG
            Console.WriteLine("Compute fragments");
#endif
            foreach (var e in elementary)
            {
                if (e.GetLogicOperator() != LogicOperator.EX)
                {
                    continue;
                }
                if (e[0].GetLogicOperator() != LogicOperator.EU)
                {
                    continue;
                }
#if DEBUG
                Console.WriteLine("Computing fragment for " + e);
#endif
                FormulaNode frag = FormulaParser.Parse("~TRUE");
                while (true)
                {
                    string        nextName   = "succ" + uniqueId.GetTicket().ToString();
                    SymbolicState next       = new SymbolicState(elementary, nextName);
                    FormulaNode   transition = GenTransition(state, next);
                    FormulaNode   memberOf   = SymbolicState.Substitute(stateSet, state, next);
                    FormulaNode   nextFrag   = SymbolicState.Substitute(frag, state, next);
                    FormulaNode   newFrag    = new FormulaNode(LogicOperator.AND, transition, memberOf);
                    newFrag = new FormulaNode(LogicOperator.AND, newFrag, nextFrag);
                    newFrag = next.Quantify(LogicOperator.EXISTS, newFrag);

                    newFrag = new FormulaNode(LogicOperator.AND, state.ValueOf(e[0][0]), newFrag);
                    newFrag = new FormulaNode(LogicOperator.OR, state.ValueOf(e[0][1]), newFrag);

                    if (IsFixpoint(newFrag, frag, state))
                    {
                        break;
                    }

                    frag = newFrag;
                }
                fragEU[e[0]] = frag;
            }
        }
Ejemplo n.º 4
0
        private static void AssertSat(string formulaString, bool expected)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            bool Completed = ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(timelimit), () =>
            {
                FormulaNode formula = FormulaParser.Parse(formulaString);
                Console.WriteLine("\nTEST: " + formulaString);
                var checker = new CTLSatisfiabilityChecker(formula);
                bool result = checker.Check();
                Console.WriteLine("Done");
                if (result != expected)
                {
                    throw new Exception("Wrong SAT value for " + formulaString);
                }
            });

            stopwatch.Stop();
            double time = (double)stopwatch.ElapsedMilliseconds / 1000.0;

            Console.WriteLine("TIME: " + time);
        }