public void RegexFeedbackDominik() { var solver = new CharSetSolver(BitWidth.BV64); List <char> alph = new List <char> { '0', '1' }; HashSet <char> al = new HashSet <char>(alph); var escapedRexpr1 = string.Format(@"^(1*(01*01*01*)*)$"); var escapedRexpr2 = string.Format(@"^((0*0*0*)*)$"); Automaton <BDD> aut1 = null; Automaton <BDD> aut2 = null; try { aut1 = solver.Convert(escapedRexpr1).RemoveEpsilons(solver.MkOr).Determinize(solver);; aut2 = solver.Convert(escapedRexpr2).RemoveEpsilons(solver.MkOr).Determinize(solver);; } catch (ArgumentException e) { throw new PDLException("The input is not a well formatted regular expression: " + e.Message); } var v1 = DFAGrading.GetGrade(aut1, aut2, al, solver, timeout, 10, FeedbackLevel.Minimal, true, false, false); Console.WriteLine("Grade: {0}", v1.First); foreach (var feed in v1.Second) { Console.WriteLine(feed.ToString()); } }
public void Feedback2() { CharSetSolver solver = new CharSetSolver(BitWidth.BV64); var al = new HashSet <char>(new char[] { 'a', 'b' }); var dfa1 = new PDLModSetEq(new PDLIndicesOf("a"), 2, 1).GetDFA(al, solver); var a = solver.MkCharConstraint(false, 'a'); var b = solver.MkCharConstraint(false, 'b'); var movescorrect = new List <Move <BDD> >(); movescorrect.Add(new Move <BDD>(0, 0, b)); movescorrect.Add(new Move <BDD>(0, 1, a)); movescorrect.Add(new Move <BDD>(1, 0, a)); movescorrect.Add(new Move <BDD>(1, 0, b)); var dfa2 = Automaton <BDD> .Create(0, new int[] { 1 }, movescorrect); var v4 = DFAGrading.GetGrade(dfa1, dfa2, al, solver, timeout, 10, FeedbackLevel.Hint); Console.WriteLine("Grade: {0}", v4.First); foreach (var v in v4.Second) { Console.WriteLine("Feedback: {0}", v); } }
public XElement ComputeFeedbackRegexp(XElement regexCorrectDesc, XElement regexAttemptDesc, XElement alphabet, XElement feedbackLevel, XElement enabledFeedbacks, XElement maxGrade) { CharSetSolver solver = new CharSetSolver(BitWidth.BV64); try { var dfaCorrectPair = DFAUtilities.parseRegexFromXML(regexCorrectDesc, alphabet, solver); var dfaAttemptPair = DFAUtilities.parseRegexFromXML(regexAttemptDesc, alphabet, solver); var level = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true); var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>(); bool dfaedit = false, moseledit = false, density = true; int maxG = int.Parse(maxGrade.Value); var feedbackGrade = DFAGrading.GetGrade(dfaCorrectPair.Second, dfaAttemptPair.Second, dfaCorrectPair.First, solver, 1500, maxG, level, dfaedit, moseledit, density); var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; return(XElement.Parse(string.Format("<div><grade>{0}</grade><feedback>{1}</feedback></div>", feedbackGrade.First, feedString))); } catch (PDLException pdlex) { return(XElement.Parse(string.Format("<div>Error: {0} </div>", pdlex.Message))); } }
public void CounterexampleFeedback() { 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 movescorrect = new List <Move <BDD> >(); movescorrect.Add(new Move <BDD>(0, 0, a)); movescorrect.Add(new Move <BDD>(0, 1, b)); movescorrect.Add(new Move <BDD>(1, 1, a)); movescorrect.Add(new Move <BDD>(1, 1, b)); var dfa_correct = Automaton <BDD> .Create(0, new int[] { 0 }, movescorrect); var moves1 = new List <Move <BDD> >(); moves1.Add(new Move <BDD>(0, 0, a)); moves1.Add(new Move <BDD>(0, 0, b)); var dfa1 = Automaton <BDD> .Create(0, new int[] { 0 }, moves1); var v1 = DFAGrading.GetGrade(dfa_correct, dfa1, al, solver, timeout, 10, FeedbackLevel.Minimal, true, false, false); Console.WriteLine("Grade: {0}", v1.First); foreach (var feed in v1.Second) { Console.WriteLine(feed.ToString()); } }
public XElement ComputeFeedbackXML(XElement dfaCorrectDesc, XElement dfaAttemptDesc, XElement maxGrade, XElement feedbackLevel, XElement enabledFeedbacks) { #region Check if item is in cache StringBuilder key = new StringBuilder(); key.Append("feed"); key.Append(dfaCorrectDesc.ToString()); key.Append(dfaAttemptDesc.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 dfaCorrectPair = DFAUtilities.parseDFAFromXML(dfaCorrectDesc, solver); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); var level = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true); var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>(); //bool dfaedit = enabList.Contains("dfaedit"), moseledit = enabList.Contains("moseledit"), density = enabList.Contains("density"); bool dfaedit = true, moseledit = true, density = true; var maxG = int.Parse(maxGrade.Value); //Compute feedback var feedbackGrade = DFAGrading.GetGrade(dfaCorrectPair.Second, dfaAttemptPair.Second, dfaCorrectPair.First, solver, 1500, maxG, level, dfaedit, density, moseledit); //Pretty print feedback var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); break; } feedString += "</ul>"; //var output = string.Format("<result><grade>{0}</grade><feedString>{1}</feedString></result>", feedbackGrade.First, feedString); var outXML = new XElement("result", new XElement("grade", feedbackGrade.First), new XElement("feedString", XElement.Parse(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); }
public void Grade2DFAs() { var solver = new CharSetSolver(BitWidth.BV64); List <char> alph = new List <char> { 'a', 'b' }; HashSet <char> al = new HashSet <char>(alph); PDLPred phi = new PDLAnd(new PDLIntGeq(new PDLIndicesOf("a"), 2), new PDLIntGeq(new PDLIndicesOf("b"), 2)); //PDLPred phi2 = new PDLIf(new PDLStartsWith("b"), new PDLEndsWith("b")); var dfaCorr = phi.GetDFA(al, solver); 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, 1, b)); moves.Add(new Move <BDD>(1, 2, a)); moves.Add(new Move <BDD>(1, 2, b)); moves.Add(new Move <BDD>(2, 3, a)); moves.Add(new Move <BDD>(2, 3, b)); moves.Add(new Move <BDD>(3, 3, a)); moves.Add(new Move <BDD>(3, 3, b)); //moves.Add(new Move<BDD>(3, 4, a)); //moves.Add(new Move<BDD>(3, 2, b)); //moves.Add(new Move<BDD>(4, 4, a)); //moves.Add(new Move<BDD>(4, 5, b)); //moves.Add(new Move<BDD>(5, 6, a)); //moves.Add(new Move<BDD>(5, 4, b)); //moves.Add(new Move<BDD>(6, 6, a)); //moves.Add(new Move<BDD>(6, 6, b)); var dfa2 = Automaton <BDD> .Create(0, new int[] { 3 }, moves); //Assert.IsTrue(phi2.GetDFA(al,solver).IsEquivalentWith(dfa2,solver)); solver.SaveAsDot(dfaCorr, "aa", "corr"); solver.SaveAsDot(dfa2, "aa", "wrong"); //var v0 = DFADensity.GetDFADifferenceRatio(dfa1, dfa2, al, solver); //var v1 = PDLEditDistance.GetMinimalFormulaEditDistanceRatio(dfa1, dfa2, al, solver, timeout); //var v2 = DFAEditDistance.GetDFAOptimalEdit(dfa1, dfa2, al, solver, 4, new StringBuilder()); //Console.WriteLine("density ratio: {0}; pdl edit distance: {1}; dfa edit distance: {2}", v0, v1, v2); var gr = DFAGrading.GetGrade(dfaCorr, dfa2, al, solver, 2000, 10, FeedbackLevel.Hint, true, true, true); Console.WriteLine(gr.First); foreach (var f in gr.Second) { Console.WriteLine(f.ToString()); } }
public void GradingTest1() { 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, 0, a)); moves.Add(new Move <BDD>(0, 1, b)); moves.Add(new Move <BDD>(1, 1, b)); moves.Add(new Move <BDD>(1, 2, a)); moves.Add(new Move <BDD>(2, 2, a)); moves.Add(new Move <BDD>(2, 3, b)); moves.Add(new Move <BDD>(3, 3, b)); moves.Add(new Move <BDD>(3, 4, a)); moves.Add(new Move <BDD>(4, 4, a)); moves.Add(new Move <BDD>(4, 5, b)); moves.Add(new Move <BDD>(5, 6, a)); moves.Add(new Move <BDD>(5, 5, b)); moves.Add(new Move <BDD>(6, 6, a)); moves.Add(new Move <BDD>(6, 6, b)); var dfa1 = Automaton <BDD> .Create(0, new int[] { 4, 5 }, moves); var moves1 = new List <Move <BDD> >(); moves1.Add(new Move <BDD>(0, 0, a)); moves1.Add(new Move <BDD>(0, 1, b)); moves1.Add(new Move <BDD>(1, 1, b)); moves1.Add(new Move <BDD>(1, 2, a)); moves1.Add(new Move <BDD>(2, 2, a)); moves1.Add(new Move <BDD>(2, 3, b)); moves1.Add(new Move <BDD>(3, 3, b)); moves1.Add(new Move <BDD>(3, 4, a)); moves1.Add(new Move <BDD>(4, 4, a)); moves1.Add(new Move <BDD>(4, 4, b)); var dfa2 = Automaton <BDD> .Create(0, new int[] { 4 }, moves1); var v1 = DFAGrading.GetGrade(dfa1, dfa2, al, solver, timeout, 10, FeedbackLevel.Hint); Console.WriteLine("grade0: {0}, ", v1); }
public XElement ComputeFeedbackNfaToDfa(XElement nfaCorrectDesc, XElement dfaAttemptDesc, XElement maxGrade) { #region Check if item is in cache StringBuilder key = new StringBuilder(); key.Append("feedNFADFA"); key.Append(nfaCorrectDesc.ToString()); key.Append(dfaAttemptDesc.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 dfaCorrect = nfaCorrectPair.Second.RemoveEpsilons(solver.MkOr).Determinize(solver).Minimize(solver); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); var level = FeedbackLevel.Hint; var maxG = int.Parse(maxGrade.Value); //Compute feedback var feedbackGrade = DFAGrading.GetGrade(dfaCorrect, dfaAttemptPair.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); }
public void Feedback1() { CharSetSolver solver = new CharSetSolver(BitWidth.BV64); var al = new HashSet <char>(new char[] { 'a', 'b' }); var dfa1 = new PDLModSetEq(new PDLIndicesOf("a"), 2, 0).GetDFA(al, solver); var dfa2 = new PDLModSetEq(new PDLIndicesOf("a"), 2, 1).GetDFA(al, solver); var v4 = DFAGrading.GetGrade(dfa2, dfa1, al, solver, timeout, 10, FeedbackLevel.Hint); Console.WriteLine("Grade: {0}", v4.First); foreach (var v in v4.Second) { Console.WriteLine("Feedback: {0}", v); } }
public void DileepTest3() { //XElement dfaCorrectDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state><state sid=\"1\"><label>1</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>1</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"2\"> <from>1</from> <to>1</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"3\"> <from>1</from> <to>0</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> <state sid=\"1\"></state> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement dfaCorrectDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state><state sid=\"1\"><label>1</label></state><state sid=\"2\"><label>2</label></state><state sid=\"3\"><label>3</label></state><state sid=\"4\"><label>4</label></state><state sid=\"5\"><label>5</label></state><state sid=\"6\"><label>6</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>1</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"2\"> <from>1</from> <to>1</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"3\"> <from>1</from> <to>2</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"4\"> <from>2</from> <to>2</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"5\"> <from>2</from> <to>3</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"6\"> <from>3</from> <to>3</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"7\"> <from>3</from> <to>4</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"8\"> <from>4</from> <to>4</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"9\"> <from>4</from> <to>5</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"10\"> <from>5</from> <to>5</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"11\"> <from>5</from> <to>6</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"12\"> <from>6</from> <to>6</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"13\"> <from>6</from> <to>6</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> <state sid=\"4\"></state><state sid=\"5\"></state> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement dfaAttemptDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement feedbackLevel = XElement.Parse("<level xmlns=\"http://automatagrader.com/\">smallhint</level>"); XElement enabledFeedbacks = XElement.Parse("<metrics xmlns=\"http://automatagrader.com/\">dfaedit,moseledit,density</metrics>"); CharSetSolver solver = new CharSetSolver(BitWidth.BV64); //XElement dfaAttemptDesc = dfaAttemptHint.Element("Automaton"); //FeedbackLevel level = (FeedbackLevel)Convert.ToInt32(dfaAttemptHint.Element("FeedbackLevel").Value); var dfaCorrectPair = DFAUtilities.parseDFAFromXML(dfaCorrectDesc, solver); Console.WriteLine(feedbackLevel); Console.WriteLine(enabledFeedbacks); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); //var sb = new StringBuilder(); var level = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true); var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>(); bool dfaedit = enabList.Contains("dfaedit"), moseledit = enabList.Contains("moseledit"), density = enabList.Contains("density"); var feedbackGrade = DFAGrading.GetGrade(dfaCorrectPair.Second, dfaAttemptPair.Second, dfaCorrectPair.First, solver, 2000, 10, level, dfaedit, moseledit, density); var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; Console.WriteLine(string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString)); }
public void ComputeFeedback() { var solver = new CharSetSolver(BitWidth.BV64); List <char> alph = new List <char> { '0', '1' }; HashSet <char> al = new HashSet <char>(alph); var correct = new PDLContains("0101"); var dfa_correct = correct.GetDFA(al, solver); var o = solver.MkCharConstraint(false, '0'); var l = solver.MkCharConstraint(false, '1'); var moves = new List <Move <BDD> >(); moves.Add(new Move <BDD>(0, 0, l)); moves.Add(new Move <BDD>(0, 1, o)); moves.Add(new Move <BDD>(1, 1, o)); moves.Add(new Move <BDD>(1, 2, l)); moves.Add(new Move <BDD>(2, 3, o)); moves.Add(new Move <BDD>(2, 0, l)); moves.Add(new Move <BDD>(3, 0, o)); moves.Add(new Move <BDD>(3, 4, l)); moves.Add(new Move <BDD>(4, 4, o)); moves.Add(new Move <BDD>(4, 4, l)); var dfa_wrong = Automaton <BDD> .Create(0, new int[] { 4 }, moves); var v1 = DFAGrading.GetGrade(dfa_correct, dfa_wrong, al, solver, timeout, 10, FeedbackLevel.Hint, true, true, true); Console.WriteLine("Grade: {0}", v1.First); foreach (var feed in v1.Second) { Console.WriteLine(feed.ToString()); } }
public void DileepTest1() { 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); PDLPred phi = new PDLModSetEq(new PDLIndicesOf("a"), 2, 1); phi = new PDLAnd(new PDLStartsWith("a"), phi); var dfa1 = phi.GetDFA(al, solver); var a = solver.MkCharConstraint(false, 'a'); var b = solver.MkCharConstraint(false, 'b'); var moves = new List <Move <BDD> >(); moves.Add(new Move <BDD>(0, 0, a)); moves.Add(new Move <BDD>(0, 5, a)); moves.Add(new Move <BDD>(5, 0, a)); moves.Add(new Move <BDD>(5, 5, b)); var dfa2 = Automaton <BDD> .Create(0, new int[] { 5 }, moves); var feedbackGrade = DFAGrading.GetGrade(dfa1, dfa2, al, solver, timeout, 10, FeedbackLevel.Solution, true, false, false); var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; Console.Write(string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString)); }
public void MaheshCase4() { // contains baba as substring 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 movescorrect = new List <Move <BDD> >(); int R = 10; movescorrect.Add(new Move <BDD>(0, 0, a)); movescorrect.Add(new Move <BDD>(0, 1, b)); movescorrect.Add(new Move <BDD>(1, 2, a)); movescorrect.Add(new Move <BDD>(1, 1, b)); movescorrect.Add(new Move <BDD>(2, 0, a)); movescorrect.Add(new Move <BDD>(2, 3, b)); movescorrect.Add(new Move <BDD>(3, 4, a)); movescorrect.Add(new Move <BDD>(3, 1, b)); movescorrect.Add(new Move <BDD>(4, 4, a)); movescorrect.Add(new Move <BDD>(4, 4, b)); var dfa_correct = Automaton <BDD> .Create(0, new int[] { 4, 0 }, movescorrect); var moves1 = new List <Move <BDD> >(); moves1.Add(new Move <BDD>(0, 0, a)); moves1.Add(new Move <BDD>(0, 1, b)); moves1.Add(new Move <BDD>(1, 2, a)); moves1.Add(new Move <BDD>(1, 0, b)); moves1.Add(new Move <BDD>(2, 0, a)); moves1.Add(new Move <BDD>(2, 3, b)); moves1.Add(new Move <BDD>(3, 4, a)); moves1.Add(new Move <BDD>(3, 0, b)); moves1.Add(new Move <BDD>(4, 4, a)); moves1.Add(new Move <BDD>(4, 4, b)); var dfa1 = Automaton <BDD> .Create(0, new int[] { 0, 4 }, moves1); var moves2 = new List <Move <BDD> >(); moves2.Add(new Move <BDD>(0, 0, a)); moves2.Add(new Move <BDD>(0, 1, b)); moves2.Add(new Move <BDD>(1, 2, a)); moves2.Add(new Move <BDD>(1, 1, b)); moves2.Add(new Move <BDD>(2, 2, a)); moves2.Add(new Move <BDD>(2, 3, b)); moves2.Add(new Move <BDD>(3, 4, a)); moves2.Add(new Move <BDD>(3, 3, b)); moves2.Add(new Move <BDD>(4, 4, a)); moves2.Add(new Move <BDD>(4, 4, b)); var dfa2 = Automaton <BDD> .Create(0, new int[] { 4 }, moves2); var moves3 = new List <Move <BDD> >(); moves3.Add(new Move <BDD>(0, R, a)); moves3.Add(new Move <BDD>(0, 1, b)); moves3.Add(new Move <BDD>(1, 2, a)); moves3.Add(new Move <BDD>(1, R, b)); moves3.Add(new Move <BDD>(2, R, a)); moves3.Add(new Move <BDD>(2, 3, b)); moves3.Add(new Move <BDD>(3, 4, a)); moves3.Add(new Move <BDD>(3, R, b)); moves3.Add(new Move <BDD>(4, 4, a)); moves3.Add(new Move <BDD>(4, 4, b)); moves3.Add(new Move <BDD>(R, R, a)); moves3.Add(new Move <BDD>(R, R, b)); var dfa3 = Automaton <BDD> .Create(0, new int[] { 4 }, moves3); var moves4 = new List <Move <BDD> >(); moves4.Add(new Move <BDD>(0, 0, a)); moves4.Add(new Move <BDD>(0, 1, b)); moves4.Add(new Move <BDD>(1, 2, a)); moves4.Add(new Move <BDD>(1, 1, b)); moves4.Add(new Move <BDD>(2, 0, a)); moves4.Add(new Move <BDD>(2, 3, b)); moves4.Add(new Move <BDD>(3, 3, a)); moves4.Add(new Move <BDD>(3, 1, b)); //moves4.Add(new Move<BDD>(4, 4, a)); //moves4.Add(new Move<BDD>(4, 4, b)); var dfa4 = Automaton <BDD> .Create(0, new int[] { 0 }, moves4); var moves5 = new List <Move <BDD> >(); moves5.Add(new Move <BDD>(0, 5, a)); moves5.Add(new Move <BDD>(0, 1, b)); moves5.Add(new Move <BDD>(1, 2, a)); moves5.Add(new Move <BDD>(1, 6, b)); moves5.Add(new Move <BDD>(2, 7, a)); moves5.Add(new Move <BDD>(2, 3, b)); moves5.Add(new Move <BDD>(3, 4, a)); moves5.Add(new Move <BDD>(3, 8, b)); moves5.Add(new Move <BDD>(4, 4, a)); moves5.Add(new Move <BDD>(4, 4, b)); moves5.Add(new Move <BDD>(5, 5, a)); moves5.Add(new Move <BDD>(5, 1, b)); moves5.Add(new Move <BDD>(6, 2, a)); moves5.Add(new Move <BDD>(6, 0, b)); moves5.Add(new Move <BDD>(7, 7, a)); moves5.Add(new Move <BDD>(7, 3, b)); moves5.Add(new Move <BDD>(8, 4, a)); moves5.Add(new Move <BDD>(8, 8, b)); var dfa5 = Automaton <BDD> .Create(0, new int[] { 4 }, moves5); //var v1 = Grading.GetGrade(dfa_correct, dfa1, al, solver, timeout, 10); //var v2 = Grading.GetGrade(dfa_correct, dfa2, al, solver, timeout, 10); //var v3 = Grading.GetGrade(dfa_correct, dfa3, al, solver, timeout, 10); var v4 = DFAGrading.GetGrade(dfa_correct, dfa4, al, solver, timeout, 10, FeedbackLevel.Minimal, true, false, false); //var v5 = Grading.GetGrade(dfa_correct, dfa5, al, solver, timeout, 10); //Console.WriteLine("Grade: {0}, Feedback: {1}", v1.First, v1.Second); //Console.WriteLine("Grade: {0}, Feedback: {1}", v2.First, v2.Second); //Console.WriteLine("Grade: {0}, Feedback: {1}", v3.First, v3.Second); Console.WriteLine("Grade: {0}, Feedback: {1}", v4.First, v4.Second); //Console.WriteLine("Grade: {0}, Feedback: {1}", v5.First, v5.Second); //Assert.IsTrue(v1 > v2 && v2 > v3); }
public void VladKlimkivDFAs() { 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'); //PDLPred phi2 = new PDLIf(new PDLStartsWith("b"), new PDLEndsWith("b")); var movesSolution = new List <Move <BDD> >(); movesSolution.Add(new Move <BDD>(0, 1, a)); movesSolution.Add(new Move <BDD>(0, 2, b)); movesSolution.Add(new Move <BDD>(1, 0, a)); movesSolution.Add(new Move <BDD>(1, 3, b)); movesSolution.Add(new Move <BDD>(2, 3, a)); movesSolution.Add(new Move <BDD>(2, 5, b)); movesSolution.Add(new Move <BDD>(3, 2, a)); movesSolution.Add(new Move <BDD>(3, 4, b)); movesSolution.Add(new Move <BDD>(4, 5, a)); movesSolution.Add(new Move <BDD>(4, 1, b)); movesSolution.Add(new Move <BDD>(5, 4, a)); movesSolution.Add(new Move <BDD>(5, 1, b)); var dfaSolution = Automaton <BDD> .Create(0, new int[] { 2 }, movesSolution); var movesAttempt = new List <Move <BDD> >(); movesAttempt.Add(new Move <BDD>(0, 1, b)); movesAttempt.Add(new Move <BDD>(0, 2, a)); movesAttempt.Add(new Move <BDD>(1, 0, b)); movesAttempt.Add(new Move <BDD>(1, 3, a)); movesAttempt.Add(new Move <BDD>(2, 3, b)); movesAttempt.Add(new Move <BDD>(2, 5, a)); movesAttempt.Add(new Move <BDD>(3, 2, b)); movesAttempt.Add(new Move <BDD>(3, 4, a)); movesAttempt.Add(new Move <BDD>(4, 5, b)); movesAttempt.Add(new Move <BDD>(4, 1, a)); movesAttempt.Add(new Move <BDD>(5, 4, b)); movesAttempt.Add(new Move <BDD>(5, 1, a)); var dfaAttempt = Automaton <BDD> .Create(0, new int[] { 2 }, movesAttempt); var gr = DFAGrading.GetGrade(dfaSolution, dfaAttempt, al, solver, 1500, 10, FeedbackLevel.Hint, true, true, true); Console.WriteLine(gr.First); foreach (var f in gr.Second) { Console.WriteLine(f.ToString()); } gr = DFAGrading.GetGrade(dfaAttempt, dfaSolution, al, solver, 1500, 10, FeedbackLevel.Hint, true, true, true); Console.WriteLine(gr.First); foreach (var f in gr.Second) { Console.WriteLine(f.ToString()); } }
public void LorisTest() { HashSet <char> al = new HashSet <char>(new char[] { 'a', 'b' }); CharSetSolver solver = new CharSetSolver(BitWidth.BV64); string rexpr1 = "(a|b)*"; var escapedRexpr = string.Format("^({0})$", rexpr1); Automaton <BDD> aut1 = null; try { aut1 = solver.Convert(escapedRexpr); } catch (ArgumentException e) { throw new PDLException("The input is not a well formatted regular expression.\n" + e.ToString()); } catch (AutomataException e) { throw new PDLException("The input is not a well formatted regular expression.\n" + e.ToString()); } var diff = aut1.Minus(solver.Convert("^(a|b)*$"), solver); if (!diff.IsEmpty) { throw new PDLException("The regular expression should only accept strings over (a|b)*."); } string rexpr2 = "(a|b)+"; escapedRexpr = string.Format("^({0})$", rexpr2); Automaton <BDD> aut2 = null; try { aut2 = solver.Convert(escapedRexpr); } catch (ArgumentException e) { throw new PDLException("The input is not a well formatted regular expression.\n" + e.ToString()); } catch (AutomataException e) { throw new PDLException("The input is not a well formatted regular expression.\n" + e.ToString()); } diff = aut2.Minus(solver.Convert("^(a|b)*$"), solver); if (!diff.IsEmpty) { throw new PDLException("The regular expression should only accept strings over (a|b)*."); } var feedbackGrade = DFAGrading.GetGrade(aut1, aut2, al, solver, 2000, 10, FeedbackLevel.Solution, false, true, true); var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; Console.WriteLine(string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString)); }