Esempio n. 1
0
        public void FromSDATest()
        {
            var sda = new SDA <char, char>("ZAB");

            sda.AddTransition('a', 'Z', "ZZ");
            sda.AddTransition('a', 'Z', "ZZ");
            sda.AddTransition('a', 'Z', "AZ");
            sda.AddTransition('b', 'A');
            sda.AddTransition('b', 'A', "B");
            sda.AddTransition('c', 'B');
            sda.AddTransition('d', 'Z');

            var exp = new DeterminisedSDA <char, char>("ZAB");

            exp.AddTransition('a', 'Z', new StackSymbolSequenceSet <char>(new StackSymbolSequence <char>[] { new StackSymbolSequence <char>("ZZ"), new StackSymbolSequence <char>("AZ") }));
            exp.AddTransition('b', 'A', new StackSymbolSequenceSet <char>(new StackSymbolSequence <char>[] { new StackSymbolSequence <char>(""), new StackSymbolSequence <char>("B") }));
            exp.AddTransition('c', 'B', new StackSymbolSequenceSet <char>(new StackSymbolSequence <char>[] { new StackSymbolSequence <char>("") }));
            exp.AddTransition('d', 'Z', new StackSymbolSequenceSet <char>(new StackSymbolSequence <char>[] { new StackSymbolSequence <char>("") }));

            var act = DeterminisedSDA <char, char> .FromSDAInNormalForm(sda);

            Assert.IsTrue(exp.Equals(act));

            Assert.IsTrue(act.ShortestWordsOfStackSymbols['Z'].SequenceEqual("d"));
            Assert.IsTrue(act.ShortestWordsOfStackSymbols['B'].SequenceEqual("c"));
            Assert.IsTrue(act.ShortestWordsOfStackSymbols['A'].SequenceEqual("b"));
        }
 private Node(Operation <A, S> operationToHere, Node <A, S> parent, DeterminisedSDA <A, S> sda, IEnumerable <A> symbols)
 {
     OperationToHere = operationToHere;
     Parent          = parent;
     this.sda        = sda;
     this.symbols    = symbols;
 }
        /// <summary>
        /// converts the given DPDA to a determinised SDA. The both given stack symbols are converted to the corresponding configuration-sets
        /// in the SDA
        /// </summary>
        /// <param name="dpda"></param>
        /// <param name="initialStackSymbols1"></param>
        /// <param name="initialStackSymbols2"></param>
        /// <returns></returns>
        public static DeterminisedSDAResult ToDeterminisedSDA(PDA <A, S> dpda, S initialStackSymbols1, S initialStackSymbols2)
        {
            var sdaResult = ToSDAInNormalForm(dpda);

            var allStackSymbols     = DictionaryFromStackSymbols(sdaResult.sda.AllStackSymbols);
            var epsilonStackSymbols = DictionaryFromStackSymbols(sdaResult.EpsilonStackSymbols);

            var initialConfig1 = ConvertInitialConfigurationToSDAConfiguration(allStackSymbols, epsilonStackSymbols, dpda, initialStackSymbols1);
            var initialCinfig2 = ConvertInitialConfigurationToSDAConfiguration(allStackSymbols, epsilonStackSymbols, dpda, initialStackSymbols2);

            var res = DeterminisedSDA <A, TripleStackSymbol <S> > .FromSDAInNormalForm(sdaResult.sda);

            return(new DeterminisedSDAResult(res, initialConfig1, initialCinfig2));
        }
        public void ToSDAInNormalFormTest()
        {
            var dpda = new PDA <char, char>(new AcceptanceCondition.EmptyStack(), true, 'Z', false, "ZA");

            dpda.AddState(1, false);

            dpda.HasNormalForm();

            dpda.AddTransition().From(0).To(0).Read('a').Pop('Z').Push("AZ");
            dpda.AddTransition().From(0).To(0).Read('a').Pop('A').Push("AA");
            dpda.AddTransition().From(0).To(1).Read('b').Pop('A').Push("A");
            dpda.AddTransition().From(1).To(1).Read('c').Pop('A').Push();
            dpda.AddTransition().From(1).To(1).Read().Pop('Z').Push();

            var symbols = new Dictionary <string, TripleStackSymbol <char> >()
            {
                { "0A1", new TripleStackSymbol <char>(0, 'A', 1) },
                { "0Z1", new TripleStackSymbol <char>(0, 'Z', 1) },
                { "1A1", new TripleStackSymbol <char>(1, 'A', 1) }
            };

            var exp = new SDA <char, TripleStackSymbol <char> >(symbols.Values);

            exp.AddTransition('a', symbols["0Z1"], new TripleStackSymbol <char>[] { symbols["0A1"] });
            exp.AddTransition('a', symbols["0A1"], new TripleStackSymbol <char>[] { symbols["0A1"], symbols["1A1"] });
            exp.AddTransition('b', symbols["0A1"], new TripleStackSymbol <char>[] { symbols["1A1"] });
            exp.AddTransition('c', symbols["1A1"]);

            var act = DPDAInNormalFormToSDAConverter <char, char> .ToSDAInNormalForm(dpda).sda;

            Assert.IsTrue(exp.Equals(act));

            var actPDA = act.ToPDA(symbols["0Z1"]);

            actPDA.CreateRunner();
            dpda.CreateRunner();

            var equalityResult = new PDAEqualityResult <char, TripleStackSymbol <char> >(dpda, actPDA, "abc", 7, 300000, 3000);

            Assert.IsTrue(equalityResult.AreEqual);

            var actDeterminisedSDA = DeterminisedSDA <char, TripleStackSymbol <char> > .FromSDAInNormalForm(act);

            actDeterminisedSDA.CalculateShortestWordsOfStackSymbols();

            Assert.IsTrue(actDeterminisedSDA.ShortestWordsOfStackSymbols[symbols["1A1"]].SequenceEqual("c"));
            Assert.IsTrue(actDeterminisedSDA.ShortestWordsOfStackSymbols[symbols["0A1"]].SequenceEqual("bc"));
            Assert.IsTrue(actDeterminisedSDA.ShortestWordsOfStackSymbols[symbols["0Z1"]].SequenceEqual("abc"));
        }
 public DeterminisedSDAResult(DeterminisedSDA <A, TripleStackSymbol <S> > sda, IEnumerable <StackSymbolSequence <TripleStackSymbol <S> > > initialConfig1, IEnumerable <StackSymbolSequence <TripleStackSymbol <S> > > initialConfig2)
 {
     this.sda          = sda;
     InitialConfigSet1 = initialConfig1;
     InitialConfigSet2 = initialConfig2;
 }
 public Node(StackSymbolSequenceSet <S> leftHand, StackSymbolSequenceSet <S> rightHand, Operation <A, S> operationToHere, Node <A, S> parent, DeterminisedSDA <A, S> sda, IEnumerable <A> symbols)
     : this(operationToHere, parent, sda, symbols)
 {
     LeftHand  = leftHand;
     RightHand = rightHand;
 }