Ejemplo n.º 1
0
        /// <summary>
        /// Return the approx of the min SFA accepting only the strings accepted by the 3SFA
        /// </summary>
        /// <returns></returns>
        public Automaton <S> GetApproxMinimalConsistentSFA(IBoolAlgMinterm <S> solver, int numAttempts)
        {
            var           min    = this.Minimize(solver);
            Automaton <S> minDfa = min.GetBiggestLanguageSFA().Minimize(solver);
            var           minSt  = minDfa.StateCount;

            Automaton <S> tmp = min.GetSmallestLanguageSFA().Minimize(solver);

            if (tmp.StateCount < minSt)
            {
                minDfa = tmp;
            }

            Random r = new Random();

            for (int i = 0; i < numAttempts; i++)
            {
                var fin = new HashSet <int>(min.acceptingStateSet);
                foreach (var st in min.dontCareStateSet)
                {
                    if (r.Next() % 2 == 0)
                    {
                        fin.Add(st);
                    }
                }
                tmp = Automaton <S> .Create(solver, min.initialState, fin, min.GetMoves());

                if (tmp.StateCount < minSt)
                {
                    minDfa = tmp;
                }
            }
            return(minDfa);
        }
Ejemplo n.º 2
0
 public bool IsComplete(Automaton <S> l1, Automaton <S> l2, IBoolAlgMinterm <S> solver)
 {
     if (!GetSmallestLanguageSFA().Minus(l1, solver).IsEmpty)
     {
         return(false);
     }
     return(l2.Complement(solver).Minus(GetBiggestLanguageSFA(), solver).IsEmpty);
 }
Ejemplo n.º 3
0
        public AutomataAlgebra(IBoolAlgMinterm <S> solver)
        {
            this.solver = solver;
            mtg         = new MintermGenerator <Automaton <S> >(this);
            this.empty  = Automaton <S> .MkEmpty(solver);

            this.full = Automaton <S> .MkFull(solver);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns true iff this automaton and another automaton B are equivalent
        /// </summary>
        /// <param name="B">another autonmaton</param>
        public bool IsEquivalentWith(ThreeAutomaton <S> B, IBoolAlgMinterm <S> solver)
        {
            Automaton <S> accA = Automaton <S> .Create(algebra, this.initialState, this.acceptingStateSet, this.GetMoves());

            Automaton <S> accB = Automaton <S> .Create(algebra, B.initialState, B.acceptingStateSet, B.GetMoves());

            if (!accA.IsEquivalentWith(accB, solver))
            {
                return(false);
            }

            Automaton <S> rejA = Automaton <S> .Create(algebra, this.initialState, this.rejectingStateSet, this.GetMoves());

            Automaton <S> rejB = Automaton <S> .Create(algebra, B.initialState, B.rejectingStateSet, B.GetMoves());

            return(rejA.IsEquivalentWith(rejB, solver));
        }
Ejemplo n.º 5
0
        //Automaton<T> Restrict<T>(Automaton<IMonadicPredicate<BDD, T>> autom)
        //{
        //    List<Move<T>> moves = new List<Move<T>>();
        //    foreach (var move in autom.GetMoves())
        //        moves.Add(new Move<T>(move.SourceState, move.TargetState, move.Label.ProjectSecond()));
        //    var res = Automaton<T>.Create(autom.InitialState, autom.GetFinalStates(), moves);
        //    return res;
        //}

        public void TestWS1S_UseOfCharRangePreds <T>(IBoolAlgMinterm <T> solver, T isDigit, T isWordLetter, IRegexConverter <T> regexConverter)
        {
            var ca = new CartesianAlgebraBDD <T>(solver);
            var x  = new Variable("x", false);
            var y  = new Variable("y", false);
            var z  = new Variable("z", false);
            var X  = new Variable("X", false);
            //there are at least two distinct positions x and y
            var xy = new WS1SAnd <T>(new WS1SAnd <T>(new WS1SNot <T>(new WS1SEq <T>(x, y)), new WS1SSingleton <T>(x)), new WS1SSingleton <T>(y));
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var phi = new WS1SExists <T>(X, new WS1SAnd <T>(
                                             new WS1SAnd <T>(new WS1SSubset <T>(x, X), new WS1SSubset <T>(y, X)),
                                             new WS1SNot <T>(new WS1SExists <T>(z, new WS1SNot <T>(
                                                                                    new WS1SOr <T>(new WS1SNot <T>(new WS1SAnd <T>(new WS1SSingleton <T>(z), new WS1SSubset <T>(z, X))),
                                                                                                   new WS1SPred <T>(isWordLetter, z)))))));

            var psi2        = new WS1SAnd <T>(xy, phi);
            var atLeast2wEE = new WS1SExists <T>(x, new WS1SExists <T>(y, psi2));
            var psi1        = new WS1SAnd <T>(new WS1SSingleton <T>(x), new WS1SPred <T>(isDigit, x));
            var aut_psi1    = psi1.GetAutomaton(ca, x);
            //aut_psi1.ShowGraph("SFA(psi1)");
            var atLeast1d = new WS1SExists <T>(x, psi1);
            var psi       = new WS1SAnd <T>(atLeast2wEE, atLeast1d);
            var aut1      = psi.GetAutomaton(ca);
            //var aut_atLeast1d = atLeast1d.GetAutomaton(solver);

            var aut2 = regexConverter.Convert(@"\w.*\w", System.Text.RegularExpressions.RegexOptions.Singleline).Intersect(regexConverter.Convert(@"\d"), solver);

            //aut1.ShowGraph("aut1");
            //aut2.ShowGraph("aut2");

            bool equiv = aut2.IsEquivalentWith(BasicAutomata.Restrict(aut1), solver);

            Assert.IsTrue(equiv);

            //solver.ShowGraph(aut_atLeast1d, "aut_atLeast1d");

            var aut_psi2 = psi2.GetAutomaton(ca, x, y);
            // var aut_atLeast2wEE = atLeast2wEE.GetAutomaton(ca, "x", "y");
            // var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver);
            //aut_psi2.ShowGraph("SFA(psi2)");
            //aut_atLeast2wEE.ShowGraph("aut_atLeast2wEE");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            //solver.ShowGraph(aut_atLeast2wEE2, "aut_atLeast2wEE2");
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Minimization of FAs using a symbolic generalization of Moore's algorithm.
 /// This is a quadratic algorithm.
 /// </summary>
 public ThreeAutomaton <S> Minimize(IBoolAlgMinterm <S> solver)
 {
     return(MinimizeClassical(solver, 0));
 }
Ejemplo n.º 7
0
 public MSOAlgebra(IBoolAlgMinterm <S> solver)
 {
     this.solver = solver;
     mtg         = new MintermGenerator <MSOFormula <S> >(this);
 }