Exemplo n.º 1
0
 private static void AddElementsFor(this IList<string> alphabet, LTLFormula formula)
 {
     var traversal = new ExtractAlphabet (formula);
     foreach (var element in traversal.Alphabet)
        if (!alphabet.Contains (element))
             alphabet.Add (element);
 }
Exemplo n.º 2
0
 public void CheckAtomic()
 {
     const string s = "atom";
     var f = new LTLFormula (s);
     Assert.AreEqual (s, f.Atomic);
     Assert.IsNull (f.Left);
     Assert.IsNull (f.Right);
     Assert.AreEqual (LTLOperator.NONE, f.Operator);
 }
Exemplo n.º 3
0
 public void CheckAndOperator2()
 {
     var l = new LTLFormula ("qwe");
     var r = new LTLFormula ("rty");
     var f = LTLFormula.And (l, r);
     Assert.IsNull (f.Atomic);
     Assert.AreEqual (l, f.Left);
     Assert.AreEqual (r, f.Right);
     Assert.AreEqual (LTLOperator.LOGIC_AND, f.Operator);
 }
Exemplo n.º 4
0
        ///**
        //* Add an edge from a state to a state with labeling specified
        //* by a formula in propositional logic in prefix form.
        //* @param from  the 'from' state index
        //* @param to    the 'to' state index
        //* @param guard the formula
        //*/
        //public void addEdge(int from, int to, string guard)
        //{

        //    EdgeCreator ec = new EdgeCreator(from, to, _nba);

        //    LTLFormula ltl_guard= LTLPrefixParser.parse(guard, _nba.nba_i_getAPSet());
        //    //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

        //    LTLFormula guard_dnf=ltl_guard.toDNF();
        //    //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

        //    guard_dnf.forEachMonom(ec);
        //}

        /**
         * Add an edge from a state to a state with labeling specified
         * by a formula in propositional logic in prefix form.
         * @param from  the 'from' state index
         * @param to    the 'to' state index
         * @param guard the formula
         */
        public void addEdge(int from, int to, List <Proposition> labels)
        {
            Debug.Assert(labels.Count > 0);
            LTLNode root = createNodeFromLabel(labels[labels.Count - 1]);

            if (labels.Count > 1)
            {
                for (int i = labels.Count - 2; i >= 0; i--)
                {
                    root = new LTLNode(type_t.T_AND, createNodeFromLabel(labels[i]), root);
                }
            }

            EdgeCreator ec = new EdgeCreator(from, to, _nba);

            LTLFormula ltl_guard = new LTLFormula(root, _nba.nba_i_getAPSet());
            //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

            LTLFormula guard_dnf = ltl_guard.toDNF();

            //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

            guard_dnf.forEachMonom(ec);
        }
Exemplo n.º 5
0
        public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
        {
            if (Array.Exists(old, formula => formula == this)) {
                return true;
            }

            return false;
        }
Exemplo n.º 6
0
        public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
        {
            if (Array.Exists(old, formula => formula == this)) {
                return true;
            }

            bool cond1, cond2 = false;
            cond2 = this.Right.IsImplied(old, next);
            cond1 = this.Left.IsImplied(old, next);

            return cond1 && cond2;
        }
Exemplo n.º 7
0
 public Release(LTLFormula left, LTLFormula right)
 {
     Left = left;
     Right = right;
 }
Exemplo n.º 8
0
        public void CheckUOperator()
        {
            var l = new LTLFormula ("qwe");
            var r = new LTLFormula ("rty");
            var f = LTLFormula.U (l, r);

            Assert.IsNull (f.Atomic);
            Assert.AreEqual (l, f.Left);
            Assert.AreEqual (r, f.Right);
            Assert.AreEqual (LTLOperator.LTL_U, f.Operator);
        }
Exemplo n.º 9
0
        public void CheckPrintOr()
        {
            const string s1 = "qwe";
            const string s2 = "asd";
            var f = new LTLFormula (s1) | new LTLFormula (s2);

            Assert.AreEqual ("({" + s1 + "}) or ({" + s2 + "})", f.ToString ());
        }
Exemplo n.º 10
0
 public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
 {
     return true;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LittleSharp.Buchi.Node"/> class with the given name and initial obligations.
 /// </summary>
 /// <param name='name'>
 /// The name of the node.
 /// </param>
 /// <param name='initialObligations'>
 /// The initial obligations.
 /// </param>
 public Node(string name, LTLFormula initialObligations)
     : this(name)
 {
     QueueUtils.AddsUnique(New, initialObligations);
 }
Exemplo n.º 12
0
        public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
        {
            if (Array.Exists(old, formula => formula == this)) {
                return true;
            }

            if (this.Enclosed != null) {
                if (next != null) {
                    return Array.Exists(next, formula => formula == this.Enclosed);
                } else {
                    return false;
                }
            } else {
                return true;
            }
        }
Exemplo n.º 13
0
 public Next(LTLFormula enclosed)
 {
     Enclosed = enclosed;
 }
Exemplo n.º 14
0
        ///**
        //* Add an edge from a state to a state with labeling specified
        //* by a formula in propositional logic in prefix form.
        //* @param from  the 'from' state index
        //* @param to    the 'to' state index
        //* @param guard the formula
        //*/
        //public void addEdge(int from, int to, string guard)
        //{
        //    EdgeCreator ec = new EdgeCreator(from, to, _nba);
        //    LTLFormula ltl_guard= LTLPrefixParser.parse(guard, _nba.nba_i_getAPSet());
        //    //    std::cerr << ltl_guard->toStringPrefix() << std::endl;
        //    LTLFormula guard_dnf=ltl_guard.toDNF();
        //    //    std::cerr << guard_dnf->toStringPrefix() << std::endl;
        //    guard_dnf.forEachMonom(ec);
        //}
        /**
         * Add an edge from a state to a state with labeling specified
         * by a formula in propositional logic in prefix form.
         * @param from  the 'from' state index
         * @param to    the 'to' state index
         * @param guard the formula
         */
        public void addEdge(int from, int to, List<Proposition> labels)
        {
            Debug.Assert(labels.Count > 0);
            LTLNode root = createNodeFromLabel(labels[labels.Count - 1]);
            if(labels.Count > 1)
            {
                for (int i = labels.Count-2; i >= 0; i--)
                {
                    root = new LTLNode(type_t.T_AND, createNodeFromLabel(labels[i]), root);
                }
            }

            EdgeCreator ec = new EdgeCreator(from, to, _nba);

            LTLFormula ltl_guard = new LTLFormula(root, _nba.nba_i_getAPSet());
            //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

            LTLFormula guard_dnf = ltl_guard.toDNF();
            //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

            guard_dnf.forEachMonom(ec);
        }
Exemplo n.º 15
0
        public void CheckPrintAtom()
        {
            const string s = "zxcasd";
            var f = new LTLFormula (s);

            Assert.AreEqual ('{' + s + '}', f.ToString ());
        }
Exemplo n.º 16
0
        public void CheckPrintComplexFormula()
        {
            const string s1 = "qwe";
            const string s2 = "asd";
            const string s3 = "zxc";

            var f1 = (new LTLFormula (s1) & new LTLFormula (s2)) | new LTLFormula (s3);
            var f2 = new LTLFormula (s1) & (new LTLFormula (s2) | new LTLFormula (s3));

            Assert.AreEqual ("(({" + s1 + "}) and ({" + s2 + "})) or ({" + s3 + "})", f1.ToString ());
            Assert.AreEqual ("({" + s1 + "}) and (({" + s2 + "}) or ({" + s3 + "}))", f2.ToString ());
        }
Exemplo n.º 17
0
 public double Satisfy (State s, LTLFormula formula)
 {
     if (formula is True) return 1;
     if (formula is False) return 0;
     
     if (formula is Next) return Satisfy (s, formula as Next);
     if (formula is Proposition) return Satisfy (s, formula as Proposition);
     if (formula is Finally) return Satisfy (s, formula as Finally);
     if (formula is Until) return Satisfy (s, formula as Until);
     if (formula is Globally) return 1 - Satisfy (s, new Finally(new Negation((formula as Globally).Enclosed)));
     
     if (formula is Implication) return Satisfy (s, formula as Implication);
     if (formula is Disjunction) return Satisfy (s, formula as Disjunction);
     if (formula is Conjunction) return Satisfy (s, formula as Conjunction);
     if (formula is Negation) return Satisfy (s, formula as Negation);
     
     if (formula is ParenthesedExpression) return Satisfy (s, (formula as ParenthesedExpression).Enclosed);
     
     throw new NotImplementedException(formula.GetType ().Name + " not implemented");
 }
Exemplo n.º 18
0
        public void CheckROperator()
        {
            var l = new LTLFormula ("qwe");
            var r = new LTLFormula ("rty");
            var f = LTLFormula.R (l, r);

            Assert.IsNull (f.Atomic);
            Assert.IsNotNull (f.Left);
            Assert.IsNull (f.Right);
            Assert.AreEqual (LTLOperator.LOGIC_NOT, f.Operator);

            var f1 = f.Left;
            Assert.IsNull (f1.Atomic);
            Assert.IsNotNull (f1.Left);
            Assert.IsNotNull (f1.Right);
            Assert.AreEqual (LTLOperator.LTL_U, f1.Operator);

            var f2 = f1.Left;
            Assert.IsNull (f2.Atomic);
            Assert.AreEqual (l, f2.Left);
            Assert.IsNull (f2.Right);
            Assert.AreEqual (LTLOperator.LOGIC_NOT, f2.Operator);

            var f3 = f1.Right;
            Assert.IsNull (f3.Atomic);
            Assert.AreEqual (r, f3.Left);
            Assert.IsNull (f3.Right);
            Assert.AreEqual (LTLOperator.LOGIC_NOT, f3.Operator);
        }
Exemplo n.º 19
0
 private IEnumerable<State> ComputeNotS0 (IEnumerable<State> b, LTLFormula C)
 {
     // take the pre of b
     var states = Pre (b).Where (s => Satisfy (s, C) == 1);
     
     // if we did add somes states, fixed point is not reached
     if (states.Any (s => !b.Contains (s))) {
         return ComputeNotS0 (states.Union (b).Distinct (), C);
     }
     
     return states.Union (b).Distinct ();
 }
Exemplo n.º 20
0
        public void CheckXOperator()
        {
            var l = new LTLFormula ("qwe");
            var f = LTLFormula.X (l);

            Assert.IsNull (f.Atomic);
            Assert.AreEqual (l, f.Left);
            Assert.IsNull (f.Right);
            Assert.AreEqual (LTLOperator.LTL_X, f.Operator);
        }
Exemplo n.º 21
0
 private IEnumerable<State> ComputeS1 (LTLFormula b, LTLFormula c)
 {
     var B = States.Where (s => Satisfy (s, b) == 1);
     var C = States.Where (s => Satisfy (s, c) == 1); 
     var buscub = B.Union (States.Except (C.Union (B)));
     
     var newSM = new MarkovChain ();
     foreach (var s in States) {
         newSM.Add (s);
         foreach (var t in States) {
             if (buscub.Contains (s)) {
                 newSM.Add (new Transition (1, s, t));
             } else {
                 var transition = Transitions.Where (trans => trans.From.Equals (s)
                                                     & trans.To.Equals (t)).SingleOrDefault ();
                 if (transition != null) 
                     newSM.Add (transition);
             }
         }
     }
     
     return newSM.States.Where (s => Satisfy (s, new Finally(b)) == 1);
 }
Exemplo n.º 22
0
 public double Probability (LTLFormula formula)
 {
     var ltf = this.LongTermFraction;
     var d = new Dictionary<string, double> ();
     
     foreach (var state in States) {
         d[state.Identifier] = Satisfy (state, formula);
         Console.WriteLine ("P({0}) = {1:F2} x {2:F2} = {3:F2}", 
                            state.Identifier,
                            d[state.Identifier],
                            ltf[state.Identifier],
                            d[state.Identifier] * ltf[state.Identifier] );
     }
     
     foreach (var i in ltf.Keys) {
         d[i] *= ltf[i];
     }
     
     Console.WriteLine ("sum : " + ltf.Values.Sum ());
     
     return d.Values.Sum ();
 }
Exemplo n.º 23
0
        public void CheckGOperator()
        {
            var l = new LTLFormula ("qwe");
            var f = LTLFormula.G (l);

            Assert.IsNull (f.Atomic);
            Assert.IsNotNull (f.Left);
            Assert.IsNull (f.Right);
            Assert.AreEqual (LTLOperator.LOGIC_NOT, f.Operator);

            var f1 = f.Left;
            Assert.IsNull (f1.Atomic);
            Assert.AreEqual (LTLFormula.TRUE, f1.Left);
            Assert.IsNotNull (f1.Right);
            Assert.AreEqual (LTLOperator.LTL_U, f1.Operator);

            var f2 = f1.Right;
            Assert.IsNull (f2.Atomic);
            Assert.AreEqual (l, f2.Left);
            Assert.IsNull (f2.Right);
            Assert.AreEqual (LTLOperator.LOGIC_NOT, f2.Operator);
        }
Exemplo n.º 24
0
        public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
        {
            if (Array.Exists(old, formula => formula == this)) {
                return true;
            }

            bool cond1, cond2, cond3 = false;
            cond2 = this.Left.IsImplied(old, next);
            cond1 = this.Right.IsImplied(old, next);
            if (next != null) {
                cond3 = Array.Exists(next, formula => formula == this);
            }

            return (cond1 && cond2) || (cond1 && cond3);
        }
Exemplo n.º 25
0
 public void CheckNotOperator2()
 {
     var l = new LTLFormula ("qwe");
     var f = LTLFormula.Not (l);
     Assert.IsNull (f.Atomic);
     Assert.AreEqual (l, f.Left);
     Assert.IsNull (f.Right);
     Assert.AreEqual (LTLOperator.LOGIC_NOT, f.Operator);
 }
Exemplo n.º 26
0
 public And(LTLFormula left, LTLFormula right)
 {
     Left = left; Right = right;
 }
Exemplo n.º 27
0
 public void CheckOrOperator1()
 {
     var l = new LTLFormula ("qwe");
     var r = new LTLFormula ("rty");
     var f = l | r;
     Assert.IsNull (f.Atomic);
     Assert.AreEqual (l, f.Left);
     Assert.AreEqual (r, f.Right);
     Assert.AreEqual (LTLOperator.LOGIC_OR, f.Operator);
 }
Exemplo n.º 28
0
 private static void Check(LTLFormula f)
 {
     Assert.AreEqual (f, LTLFormula.Parse (f.ToString ().Replace ('[', '(').Replace (']', ')')));
 }
Exemplo n.º 29
0
 public bool IsImplied(LTLFormula[] old, LTLFormula[] next)
 {
     return (Array.Exists(old, formula => formula == this));
 }