示例#1
0
        public void TestStateDistinguisher()
        {
            var solver = ContextFreeGrammar.GetContext();
            var A      = solver.Convert("A.*A").Determinize().RemoveEpsilons();
            var B      = solver.Convert("B.*B.*B").Determinize().RemoveEpsilons();
            var AB     = A.Intersect(B);
            var states = new List <int>(AB.GetStates());
            var dist   = new StateDistinguisher_Moore <BDD>(AB, bdd => (char)bdd.GetMin());

            //check suffix-closedness
            foreach (var s in dist.GetAllDistinguishingStrings())
            {
                for (int i = 0; i < s.Length; i++)
                {
                    Assert.IsTrue(dist.IsDistinguishingString(s.Substring(i)));
                }
            }
            //check that the states in the minimized automaton are all distiguishable
            var ABMin = AB.Minimize();
            //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)
                    {
                        string s;
                        Assert.IsTrue(dist.AreDistinguishable(p, q, out s));
                    }
                }
            }
        }
示例#2
0
        public void TestStateDistinguisher_EnumerateAllDistinguishingSequences()
        {
            var solver = ContextFreeGrammar.GetContext();
            var regex  = "^([0-9]{4,}|[3-9][0-9]{2}|2[5-9][0-9])$";

            string[] regexes           = File.ReadAllLines(regexesFile);
            var      nfa               = solver.Convert(regex).RemoveEpsilons();
            var      dfa               = nfa.Determinize();//.MakeTotal();
            var      mfa               = dfa.Minimize();
            var      dist              = new StateDistinguisher <BDD>(dfa, x => (char)x.GetMin(), false);
            int      minimalStateCount = mfa.StateCount;
            var      distinguishers    = new Dictionary <Tuple <int, int>, List <ConsList <BDD> > >();

            foreach (int p in mfa.GetStates())
            {
                foreach (int q in mfa.GetStates())
                {
                    if (p != q)
                    {
                        var pq = (p < q ? new Tuple <int, int>(p, q) : new Tuple <int, int>(q, p));
                        if (!distinguishers.ContainsKey(pq))
                        {
                            distinguishers[pq] = new List <ConsList <BDD> >(dist.EnumerateAllDistinguishingSequences(p, q));
                        }
                    }
                }
            }
            Assert.AreEqual <int>((mfa.StateCount * (mfa.StateCount - 1)) / 2, distinguishers.Count);
        }
示例#3
0
        public void TestCFG_PDAConstruction()
        {
            var input = "S -> (x) (y)";
            var cfg   = ContextFreeGrammar.Parse(input);
            var pda   = cfg.ToPDA <BDD>();
            var aut   = ContextFreeGrammar.GetContext().Convert("xy");
            var pda2  = pda.Intersect(aut);

            BDD[] w;
            Assert.IsTrue(pda2.IsNonempty(out w));
            string s = cfg.BuiltinTerminalAlgebra.ChooseString(w);

            Assert.AreEqual <string>("xy", s);
        }
示例#4
0
        public void TestStateDistinguisherH2_Concrete()
        {
            var solver            = ContextFreeGrammar.GetContext();
            var regex             = "^([0-9]{4,}|[3-9][0-9]{2}|2[5-9][0-9])$";
            var nfa               = solver.Convert(regex).RemoveEpsilons();
            var dfa               = nfa.Determinize();//.MakeTotal();
            var mfa               = dfa.Minimize();
            var dist              = new StateDistinguisher <BDD>(dfa, x => (char)x.GetMin());
            int minimalStateCount = mfa.StateCount;
            var witnesses         = dist.GetAllDistinguishingStrings();

            AssertIsSuffixClosed(witnesses);
            //var w = dist.GetDistinguishingSequence(1, 10);
            int distinguisherCount = witnesses.Length;

            Assert.IsTrue(distinguisherCount < minimalStateCount + 1);
        }
示例#5
0
        public void TestStateDistinguisherH2()
        {
            var solver = ContextFreeGrammar.GetContext();
            var regex  = "^([0-9]{4,}|[3-9][0-9]{2}|2[5-9][0-9])$";

            string[] regexes           = File.ReadAllLines(regexesFile);
            var      nfa               = solver.Convert(regex).RemoveEpsilons();
            var      dfa               = nfa.Determinize();//.MakeTotal();
            var      mfa               = dfa.Minimize();
            var      dist              = new StateDistinguisher <BDD>(dfa);
            int      minimalStateCount = mfa.StateCount;
            var      witnesses         = dist.GetAllDistinguishingSequences();

            AssertIsSuffixClosed(witnesses);
            //var w = dist.GetDistinguishingSequence(1, 10);
            int distinguisherCount = witnesses.Length;

            Assert.IsTrue(distinguisherCount < minimalStateCount + 1);
            CheckAllStatePairDistinguishers(dfa, mfa, dist);
        }
示例#6
0
 char GetChar(BDD pred)
 {
     return((char)ContextFreeGrammar.GetContext().CharSetProvider.GetMin(pred));
 }
示例#7
0
        Automaton <BDD> MkAutomaton(string regex)
        {
            var regex_with_anchors = "^(" + regex + ")$";

            return(ContextFreeGrammar.GetContext().CharSetProvider.Convert(regex_with_anchors).RemoveEpsilons());
        }
示例#8
0
 BDD MkPred(string c)
 {
     return(ContextFreeGrammar.GetContext().CharSetProvider.MkCharSetFromRegexCharClass(c));
 }