Esempio n. 1
0
        public void TestStateDistinguisherH()
        {
            var solver = new CharSetSolver();
            var A      = solver.Convert("A").Determinize().RemoveEpsilons();
            var B      = solver.Convert("B.*B").Determinize().RemoveEpsilons();
            var AB     = A.Intersect(B);
            var states = new List <int>(AB.GetStates());
            var dist   = new StateDistinguisher <BDD>(AB);
            //check suffix-closedness
            var ABMin   = AB.Minimize();
            var diststr = dist.GetAllDistinguishingSequences();
            //here we know that the minimization algorithm keeps the same state ids
            Func <int, int, Tuple <int, int> > MkPair = (x, y) => (x <= y ? new Tuple <int, int>(x, y) : new Tuple <int, int>(y, x));

            foreach (var p in ABMin.States)
            {
                foreach (var q in ABMin.States)
                {
                    if (p != q)
                    {
                        var d = dist.GetDistinguishingSequence(p, q);
                        Assert.IsTrue(d != null);
                        //check that d distinguishes p from q
                        var p1 = p;
                        var q1 = q;
                        for (int i = 0; i < d.Length; i++)
                        {
                            p1 = AB.GetTargetState(p1, d[i]);
                            q1 = AB.GetTargetState(q1, d[i]);
                        }
                        Assert.IsTrue(AB.IsFinalState(p1) != AB.IsFinalState(q1));
                    }
                }
            }
        }
Esempio n. 2
0
        private static void ValidateDistinguishers(Automaton <BDD> aut, Automaton <BDD> autMin, StateDistinguisher <BDD> dist, int i, string regex)
        {
            var distseqs = dist.GetAllDistinguishingSequences();

            if (distseqs.Length > autMin.StateCount)
            {
                Console.WriteLine(string.Format("{0}, {1}, {2}", i, distseqs.Length - autMin.StateCount, regex));
            }

            foreach (var p in autMin.States)
            {
                foreach (var q in autMin.States)
                {
                    if (p != q)
                    {
                        var d = dist.GetDistinguishingSequence(p, q);
                        Assert.IsTrue(d != null);
                        //check that d distinguishes p from q
                        int p1;
                        int q1;
                        //aut may be partial, if false is returned it means that the implicit sink state was reached
                        bool pok = aut.TryGetTargetState(p, out p1, d.ToArray());
                        bool qok = aut.TryGetTargetState(q, out q1, d.ToArray());
                        Assert.IsTrue(pok || qok);
                        if (!pok)
                        {
                            Assert.IsTrue(aut.IsFinalState(q1));
                        }
                        else if (!qok)
                        {
                            Assert.IsTrue(aut.IsFinalState(p1));
                        }
                        else
                        {
                            Assert.IsTrue(aut.IsFinalState(q1) != aut.IsFinalState(p1));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private static void CheckAllStatePairDistinguishers(Automaton <BDD> dfa, Automaton <BDD> mfa, StateDistinguisher <BDD> dist)
 {
     foreach (var p in mfa.GetStates())
     {
         foreach (var q in mfa.GetStates())
         {
             if (p != q)
             {
                 var  d = dist.GetDistinguishingSequence(p, q);
                 int  q1;
                 int  p1;
                 bool ok_q = dfa.TryGetTargetState(q, out q1, d.ToArray());
                 bool ok_p = dfa.TryGetTargetState(p, out p1, d.ToArray());
                 Assert.IsTrue(ok_q || ok_p);
                 if (ok_q && ok_p)
                 {
                     Assert.IsTrue(dfa.IsFinalState(q1) != dfa.IsFinalState(p1));
                 }
             }
         }
     }
 }