public XElement ComputeFeedbackNFAXML(XElement nfaCorrectDesc, XElement nfaAttemptDesc, XElement maxGrade, XElement feedbackLevel, XElement enabledFeedbacks, XElement userId)
        {
            #region Check if item is in cache
            StringBuilder key = new StringBuilder();
            key.Append("feed");
            key.Append(nfaCorrectDesc.ToString());
            key.Append(nfaAttemptDesc.ToString());
            key.Append(feedbackLevel.ToString());
            key.Append(enabledFeedbacks.ToString());
            string keystr = key.ToString();

            var cachedValue = HttpContext.Current.Cache.Get(key.ToString());
            if (cachedValue != null)
            {
                HttpContext.Current.Cache.Remove(keystr);
                HttpContext.Current.Cache.Add(keystr, cachedValue, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null);
                return((XElement)cachedValue);
            }
            #endregion

            CharSetSolver solver = new CharSetSolver(BitWidth.BV64);

            //Read input
            var nfaCorrectPair = DFAUtilities.parseNFAFromXML(nfaCorrectDesc, solver);
            var nfaAttemptPair = DFAUtilities.parseNFAFromXML(nfaAttemptDesc, solver);

            var level    = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true);
            var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>();

            var maxG = int.Parse(maxGrade.Value);

            //Use this for generating 2 classes of feedback for reyjkiavik study
            var studentIdModule = int.Parse(userId.Value) % 2;
            //if (studentIdModule == 0)
            //    level = FeedbackLevel.Minimal;
            //else
            //    level = FeedbackLevel.Hint;
            //Give hints to everyone
            level = FeedbackLevel.Hint;

            //Compute feedback
            var feedbackGrade = NFAGrading.GetGrade(nfaCorrectPair.Second, nfaAttemptPair.Second, nfaCorrectPair.First, solver, 1500, maxG, level);

            //Pretty print feedback
            var feedString = "<ul>";
            foreach (var feed in feedbackGrade.Second)
            {
                feedString += string.Format("<li>{0}</li>", feed);
            }
            feedString += "</ul>";

            var output = string.Format("<div><grade>{0}</grade><feedString>{1}</feedString></div>", feedbackGrade.First, feedString);

            XElement outXML = XElement.Parse(output);
            //Add this element to chace and return it
            HttpContext.Current.Cache.Add(key.ToString(), outXML, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null);

            return(outXML);
        }
示例#2
0
        public void MarioBianucciNFAs()
        {
            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, '0');
            var b = solver.MkCharConstraint(false, '1');

            //PDLPred phi2 = new PDLIf(new PDLStartsWith("b"), new PDLEndsWith("b"));



            var movesSolution = new List <Move <BDD> >();

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


            var dfaSolution = Automaton <BDD> .Create(0, new int[] { 0, 1 }, movesSolution);

            var movesAttempt = new List <Move <BDD> >();

            movesAttempt.Add(new Move <BDD>(0, 0, a));
            movesAttempt.Add(new Move <BDD>(0, 1, b));
            movesAttempt.Add(new Move <BDD>(0, 1, null));
            movesAttempt.Add(new Move <BDD>(1, 2, a));
            movesAttempt.Add(new Move <BDD>(1, 1, b));
            movesAttempt.Add(new Move <BDD>(2, 2, a));
            movesAttempt.Add(new Move <BDD>(2, 3, b));
            movesAttempt.Add(new Move <BDD>(3, 0, a));
            movesAttempt.Add(new Move <BDD>(3, 3, b));
            var dfaAttempt = Automaton <BDD> .Create(0, new int[] { 0, 1 }, movesAttempt);

            var gr = NFAGrading.GetGrade(dfaSolution, dfaAttempt, al, solver, 4000, 10, FeedbackLevel.Hint);

            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }

            gr = NFAGrading.GetGrade(dfaAttempt, dfaSolution, al, solver, 4000, 10, FeedbackLevel.Hint);
            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }
        }
示例#3
0
        public void GradingNFAEps()
        {
            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 movesSol = new List <Move <BDD> >();

            movesSol.Add(new Move <BDD>(5, 0, null));
            movesSol.Add(new Move <BDD>(0, 0, a));
            movesSol.Add(new Move <BDD>(0, 0, b));
            movesSol.Add(new Move <BDD>(0, 1, a));
            movesSol.Add(new Move <BDD>(1, 2, b));

            var nfa1 = Automaton <BDD> .Create(5, new int[] { 2 }, movesSol);

            var movesAtt = new List <Move <BDD> >();

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

            var nfa2 = Automaton <BDD> .Create(0, new int[] { 4 }, movesAtt);

            List <Pair <int, IEnumerable <NFAFeedback> > > tests = new List <Pair <int, IEnumerable <NFAFeedback> > >();

            tests.Insert(0, NFAGrading.GetGrade(nfa1, nfa2, al, solver, timeout, 10, FeedbackLevel.Hint));
            tests.Insert(0, NFAGrading.GetGrade(nfa2, nfa1, al, solver, timeout, 10, FeedbackLevel.Hint));
            tests.Insert(0, NFAGrading.GetGrade(nfa1, nfa1, al, solver, timeout, 10, FeedbackLevel.Hint));
            tests.Insert(0, NFAGrading.GetGrade(nfa2, nfa2, al, solver, timeout, 10, FeedbackLevel.Hint));

            foreach (var test in tests)
            {
                Console.WriteLine("grade: {0}, ", test.First);
                foreach (var f in test.Second)
                {
                    Console.WriteLine(f.ToString());
                }
            }
        }
示例#4
0
        public void FlabioNFA2()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                '1', '0'
            };
            HashSet <char> al = new HashSet <char>(alph);

            var o = solver.MkCharConstraint(false, '1');
            var z = solver.MkCharConstraint(false, '0');

            var movesSolution = new List <Move <BDD> >();

            movesSolution.Add(new Move <BDD>(0, 1, null));
            movesSolution.Add(new Move <BDD>(0, 2, null));
            movesSolution.Add(new Move <BDD>(1, 1, z));
            movesSolution.Add(new Move <BDD>(1, 1, o));
            movesSolution.Add(new Move <BDD>(1, 3, z));
            movesSolution.Add(new Move <BDD>(2, 2, o));


            var dfaSolution = Automaton <BDD> .Create(0, new int[] { 2, 3 }, movesSolution);

            var movesAttempt = new List <Move <BDD> >();

            movesAttempt.Add(new Move <BDD>(0, 1, null));
            movesAttempt.Add(new Move <BDD>(0, 3, null));
            movesAttempt.Add(new Move <BDD>(1, 2, z));
            movesAttempt.Add(new Move <BDD>(2, 1, o));
            movesAttempt.Add(new Move <BDD>(2, 2, z));
            movesAttempt.Add(new Move <BDD>(1, 1, o));
            movesAttempt.Add(new Move <BDD>(3, 4, o));
            movesAttempt.Add(new Move <BDD>(4, 4, o));
            var dfaAttempt = Automaton <BDD> .Create(0, new int[] { 4, 2 }, movesAttempt);

            var gr = NFAGrading.GetGrade(dfaSolution, dfaAttempt, al, solver, 1500, 10, FeedbackLevel.Hint);

            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }

            gr = NFAGrading.GetGrade(dfaAttempt, dfaSolution, al, solver, 1500, 10, FeedbackLevel.Hint);
            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }
        }
示例#5
0
        public void AgutssonNFAs()
        {
            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 movesSolution = new List <Move <BDD> >();

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


            var dfaSolution = Automaton <BDD> .Create(0, new int[] { 2 }, movesSolution);

            var movesAttempt = new List <Move <BDD> >();

            movesAttempt.Add(new Move <BDD>(0, 0, a));
            movesAttempt.Add(new Move <BDD>(0, 0, b));
            movesAttempt.Add(new Move <BDD>(0, 1, a));
            movesAttempt.Add(new Move <BDD>(1, 2, a));
            movesAttempt.Add(new Move <BDD>(2, 3, a));
            var dfaAttempt = Automaton <BDD> .Create(0, new int[] { 3 }, movesAttempt);

            var gr = NFAGrading.GetGrade(dfaSolution, dfaAttempt, al, solver, 1500, 10, FeedbackLevel.Hint);

            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }

            gr = NFAGrading.GetGrade(dfaAttempt, dfaSolution, al, solver, 1500, 10, FeedbackLevel.Hint);
            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }
        }