public void MyTest()
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            var           solver        = new CharSetSolver(BitWidth.BV64);
            List <char>   alph          = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            var a     = solver.MkCharConstraint(false, 'a');
            var b     = solver.MkCharConstraint(false, 'b');
            var moves = new List <Move <BDD> >();

            moves.Add(new Move <BDD>(0, 1, a));
            moves.Add(new Move <BDD>(0, 3, b));
            moves.Add(new Move <BDD>(1, 2, b));
            moves.Add(new Move <BDD>(2, 1, a));
            moves.Add(new Move <BDD>(1, 1, a));
            moves.Add(new Move <BDD>(2, 2, b));

            moves.Add(new Move <BDD>(3, 4, a));
            moves.Add(new Move <BDD>(4, 3, b));
            moves.Add(new Move <BDD>(3, 3, b));
            moves.Add(new Move <BDD>(4, 4, a));

            var dfa1 = Automaton <BDD> .Create(0, new int[] { 0, 1, 3 }, moves).Determinize(solver).Minimize(solver);

            foreach (var v in pdlEnumerator.SynthesizePDL(al, dfa1, solver, new StringBuilder(), 5000))
            {
                Console.WriteLine(PDLUtil.ToEnglishString(v));
                break;
            }
        }
Exemplo n.º 2
0
        public void DileepTest1()
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            PDLPred       phi           = new PDLAtSet('a', new PDLPredSet("x", new PDLModSetEq(new PDLAllPosBefore(new PDLPosVar("x")), 2, 1)));

            var solver = new CharSetSolver(BitWidth.BV64);
            var alph   = new List <char> {
                'a', 'b'
            };
            var al = new HashSet <char>(alph);

            var dfa = phi.GetDFA(al, solver);

            //solver.SaveAsDot(dfa, "C:/Users/Dileep/Desktop/oddPos.dot");

            PDLPred       synthPhi = null;
            StringBuilder sb       = new StringBuilder();

            foreach (var phi1 in pdlEnumerator.SynthesizePDL(al, dfa, solver, sb, 10000))
            {
                synthPhi = phi1;
                break;
            }

            Console.WriteLine(sb);
        }
        private List <Pair <PDLPred, long> > SynthTimer(PDLPred phi, HashSet <char> al, StringBuilder sb)
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();

            var       solver = new CharSetSolver(BitWidth.BV64);
            Stopwatch sw     = new Stopwatch();
            var       dfa    = phi.GetDFA(al, solver);

            List <Pair <PDLPred, long> > predList = new List <Pair <PDLPred, long> >();
            List <PDLPred> phiList = new List <PDLPred>();

            PDLPred v;
            var     func = new Func <PDLPred>(() =>
            {
                sw.Start();
                foreach (var p in pdlEnumerator.SynthesizePDL(al, dfa, solver, new StringBuilder(), 5000))
                {
                    sw.Stop();
                    predList.Add(new Pair <PDLPred, long>(p, sw.ElapsedMilliseconds));
                    sw.Start();
                }
                return(null);
            });


            var test = TryExecute(func, timeout, out v);

            phi.ToString(sb);
            sb.AppendLine();
            sb.AppendLine("=");
            foreach (var pair in predList)
            {
                sb.AppendLine();
                pair.First.ToString(sb);
                sb.AppendLine();
                sb.AppendLine("Elapsed Time: " + pair.Second + " ms");
            }
            return(predList);
        }
        private void runTest(string testName)
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            CharSetSolver solver        = new CharSetSolver(BitWidth.BV64);
            var           dfa_al        = ReadDFA(testName, solver);

            PDLPred       synthPhi = null;
            StringBuilder sb       = new StringBuilder();

            sb.AppendLine("*------------------------------------");
            sb.AppendLine("| " + testName);
            sb.AppendLine("|------------------------------------");

            foreach (var phi in pdlEnumerator.SynthesizePDL(dfa_al.First, dfa_al.Second, solver, sb, timeout))
            {
                synthPhi = phi;
                break;
            }

            sb.AppendLine("*------------------------------------");
            sb.AppendLine();

            System.Console.WriteLine(sb);
        }
Exemplo n.º 5
0
        public void DileepTest()
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            PDLPred       phi           = new PDLIntGeq(new PDLIndicesOf("ab"), 2);

            var solver = new CharSetSolver(BitWidth.BV64);
            var alph   = new List <char> {
                'a', 'b'
            };
            var al = new HashSet <char>(alph);

            var dfa = phi.GetDFA(al, solver);

            PDLPred       synthPhi = null;
            StringBuilder sb       = new StringBuilder();

            foreach (var phi1 in pdlEnumerator.SynthesizePDL(al, dfa, solver, sb, 10000))
            {
                synthPhi = phi1;
                break;
            }

            Console.WriteLine(sb);
        }
        private List <Pair <int, Pair <PDLPred, long> > > SynthTimer(PDLPred phi, HashSet <char> al, StringBuilder sb)
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            var           solver        = new CharSetSolver(BitWidth.BV64);
            Stopwatch     sw            = new Stopwatch();
            var           dfa           = DFAUtilities.normalizeDFA(phi.GetDFA(al, solver)).First;

            List <Pair <int, Pair <PDLPred, long> > > predList = new List <Pair <int, Pair <PDLPred, long> > >();
            List <PDLPred> phiList = new List <PDLPred>();

            PDLPred v;
            var     func = new Func <PDLPred>(() =>
            {
                foreach (var state in dfa.States)
                {
                    var dfaSt = Automaton <BDD> .Create(dfa.InitialState, new int[] { state }, dfa.GetMoves());
                    dfaSt     = dfaSt.Determinize(solver).Minimize(solver);
                    sw.Reset();
                    sw.Start();
                    foreach (var p in pdlEnumerator.SynthesizePDL(al, dfaSt, solver, new StringBuilder(), 3000))
                    {
                        sw.Stop();
                        predList.Add(new Pair <int, Pair <PDLPred, long> >(state, new Pair <PDLPred, long>(p, sw.ElapsedMilliseconds)));
                        break;
                    }
                }
                return(null);
            });


            var test = TryExecute(func, timeout, out v);

            sb.Append("Language: ");
            phi.ToString(sb);
            sb.AppendLine();
            //sb.AppendLine("States: "+dfa.StateCount);
            sb.AppendLine();
            sb.AppendLine("---------------------------");
            sb.AppendLine("STATE SUMMARY");
            sb.AppendLine("---------------------------");
            var coveredStates = new HashSet <int>();

            foreach (var pair in predList)
            {
                sb.AppendLine();
                coveredStates.Add(pair.First);
                sb.AppendLine("State " + pair.First + (((dfa.GetFinalStates()).Contains(pair.First))?(" is final"):("")));
                sb.AppendLine("Elapsed Time: " + pair.Second.Second + " ms");
                sb.AppendLine("Formula: ");
                pair.Second.First.ToString(sb);
                sb.AppendLine();
            }
            sb.AppendLine();
            foreach (var state in dfa.States)
            {
                if (!coveredStates.Contains(state))
                {
                    sb.AppendLine(string.Format("description for state {0} not found", state));
                }
            }
            return(predList);
        }
        public override string ToString()
        {
            long enumTimeout = 1000L;

            #region feedback components
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            PDLPred       symmPhi       = null;
            PDLPred       underPhi      = null;
            string        posWitness    = null;
            string        negWitness    = null;
            //If hint or solution try computing the description of the symmdiff
            if (level == FeedbackLevel.Hint || level == FeedbackLevel.Solution)
            {
                //Avoid formulas that are too complex
                var maxSize = 7;
                if (symmetricDifference.StateCount < 15)
                {
                    foreach (var phi1 in pdlEnumerator.SynthesizePDL(alphabet, symmetricDifference, solver, new StringBuilder(), enumTimeout))
                    {
                        var sizePhi1 = phi1.GetFormulaSize();
                        if (sizePhi1 < maxSize && !phi1.IsComplex())
                        {
                            maxSize = sizePhi1;
                            symmPhi = phi1;
                        }
                    }
                }
            }
            //Avoid empty string case and particular string
            if (symmPhi is PDLEmptyString || symmPhi is PDLIsString)
            {
                symmPhi = null;
            }

            //If not minimal try computing and underapprox of symmdiff
            if (symmPhi == null && level != FeedbackLevel.Minimal)
            {
                //Avoid formulas that are too complex
                var minSize = 9;
                if (symmetricDifference.StateCount < 15)
                {
                    foreach (var phi2 in pdlEnumerator.SynthesizeUnderapproximationPDL(alphabet, symmetricDifference, solver, new StringBuilder(), enumTimeout))
                    {
                        var formula  = phi2.First;
                        var sizeForm = formula.GetFormulaSize();
                        if (sizeForm < minSize && !formula.IsComplex())
                        {
                            minSize  = sizeForm;
                            underPhi = formula;
                        }

                        break;
                    }
                }
            }
            //Avoid empty string case and particular string
            if (underPhi is PDLEmptyString || underPhi is PDLIsString)
            {
                underPhi = null;
            }

            if (!positiveDifference.IsEmpty)
            {
                posWitness = DFAUtilities.GenerateShortTerm(positiveDifference, solver);
            }
            else
            {
                negWitness = DFAUtilities.GenerateShortTerm(negativeDifference, solver);
            }
            #endregion

            string result = ""; //string.Format("U: {0}%. ", utility);
            if (symmPhi != null)
            {
                if (symmPhi is PDLEmptyString)
                {
                    result += "Your solution does not behave correctly on the empty string";
                }
                else
                {
                    result += string.Format("Your solution is not correct on this set of strings: <br /> <div align='center'>{0}</div>", PDLUtil.ToEnglishString(symmPhi));
                }
            }
            else
            if (underPhi != null)
            {
                if (underPhi is PDLEmptyString)
                {
                    result += "Your solution does not behave correctly on the empty string";
                }
                else
                {
                    result += string.Format("Your solution is not correct on this set of strings: <br /> <div align='center'>{0}</div>",
                                            PDLUtil.ToEnglishString(underPhi));
                }
            }
            else
            {
                if (posWitness != null)
                {
                    result += string.Format("Your solution does not accept the {0} while the correct solution does.",
                                            posWitness != "" ? "string '<i>" + posWitness + "</i>'" : "empty string");
                }
                else
                {
                    result += string.Format("Your solution accepts the {0} while the correct solution doesn't.",
                                            negWitness != "" ? "string '<i>" + negWitness + "</i>'" : "empty string");
                }
            }
            return(result);
        }