Ejemplo n.º 1
0
        //create dotfiles for all attempts
        private static void CreateDotFiles(int probId)
        {
            string fromDir = "C:/Users/Dileep/Desktop/Attempts/" + probId + "/";
            string toDir   = "C:/Users/Dileep/Desktop/Graded/" + probId + "/";

            Directory.CreateDirectory(toDir);
            var    files = Directory.GetFiles(fromDir, "*.xml", System.IO.SearchOption.AllDirectories);
            string outputFile;

            foreach (string inputFile in files)
            {
                outputFile = toDir + Path.GetFileNameWithoutExtension(inputFile);
                var solver = new CharSetSolver(BitWidth.BV64);

                try
                {
                    var aut = DFAUtilities.parseDFAfromEvent(inputFile, solver);
                    solver.SaveAsDot(aut.Second, "second", outputFile);
                }
                catch (System.FormatException e)
                {
                    Console.WriteLine("EXCEPTION: {0}", e);
                    Console.WriteLine("Failed: {0}", Path.GetFileNameWithoutExtension(inputFile));
                }
            }
        }
Ejemplo n.º 2
0
        private static void GradeMetric(int probId, long timeout)
        {
            string      dir     = "C:/Users/Dileep/Desktop/Attempts/" + probId + "/";
            string      ansFile = "C:/Users/Dileep/Desktop/Answers/ans-" + probId + ".xml";
            List <char> alph    = new List <char> {
                'a', 'b'
            };
            HashSet <char> al          = new HashSet <char>(alph);
            CharSetSolver  solver      = new CharSetSolver(BitWidth.BV64);
            var            dfa_correct = DFAUtilities.parseDFAfromTutor(ansFile, solver);

            using (StreamReader reader = new StreamReader(dir + "clean.txt"))
                using (StreamWriter writer = new StreamWriter(dir + "Tool-Ind-" + probId + ".txt", false))
                {
                    string   id;
                    string[] file;
                    while ((id = reader.ReadLine()) != null)
                    {
                        //CharSetSolver solver = new CharSetSolver(BitWidth.BV64);
                        file = Directory.GetFiles(dir, id + ".xml", System.IO.SearchOption.AllDirectories);
                        Console.WriteLine(file[0]);
                        var dfa = DFAUtilities.parseDFAfromEvent(file[0], solver);
                        var g1  = Grading.GetGrade(dfa_correct.Second, dfa.Second, al, solver, timeout, 10, FeedbackLevel.Minimal, true, false, false);
                        var g2  = Grading.GetGrade(dfa_correct.Second, dfa.Second, al, solver, timeout, 10, FeedbackLevel.Minimal, false, false, true);
                        var g3  = Grading.GetGrade(dfa_correct.Second, dfa.Second, al, solver, timeout, 10, FeedbackLevel.Minimal, false, true, false);
                        Console.WriteLine("---- {0},{1},{2},{3}", id, g1.First, g2.First, g3.First);
                        writer.WriteLine("{0},{1},{2},{3}", id, g1.First, g2.First, g3.First);
                    }
                }
        }
Ejemplo n.º 3
0
        //private static void Grade

        private static int GradeSingle(string file1, string file2)
        {
            List <char> alph = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);
            CharSetSolver  solver = new CharSetSolver(BitWidth.BV64);
            var            aut1 = DFAUtilities.parseDFAfromTutor(file1, solver);
            var            aut2 = DFAUtilities.parseDFAfromEvent(file2, solver);
            var            dfa1 = aut1.Second; var dfa2 = aut2.Second;

            return(Grading.GetGrade(dfa1, dfa2, al, solver, 20000, 10).First);
        }
Ejemplo n.º 4
0
        private static int GradeTest(int probId, long timeout)
        {
            string fromDir = "C:/Users/Dileep/Desktop/Attempts/" + probId + "/";
            string toDir   = "C:/Users/Dileep/Desktop/Graded/" + probId + "/";

            Directory.CreateDirectory(toDir);
            var    files = Directory.GetFiles(fromDir, "*.xml", System.IO.SearchOption.AllDirectories);
            string outputFile;
            string ansFile = "C:/Users/Dileep/Desktop/Answers/" + "ans-" + probId + ".xml";

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

            var ans_aut     = DFAUtilities.parseDFAfromTutor(ansFile, solver);
            var dfa_correct = ans_aut.Second;

            TextWriter tmp = Console.Out;

            var count = 0;

            foreach (string inputFile in files)
            {
                outputFile = toDir + Path.GetFileNameWithoutExtension(inputFile) + "-grade.txt";

                var aut = DFAUtilities.parseDFAfromEvent(inputFile, solver);
                var dfa = aut.Second;

                //var writer = new StreamWriter(outputFile, false);
                //Console.SetOut(writer);
                var gradeFeedback = Grading.GetGrade(dfa_correct, dfa, al, solver, timeout, 10);
                var grade         = gradeFeedback.First;
                var feedback      = gradeFeedback.Second;
                if (grade < 10)
                {
                    count++;
                }
                Console.WriteLine("Wrong: #{0}", count);

                //writer.Close();
            }

            return(count);

            //Console.SetOut(tmp);
        }
Ejemplo n.º 5
0
        private static void LazyGrade(int probId)
        {
            string      dir     = "C:/Users/Dileep/Desktop/Attempts/" + probId + "/";
            string      ansFile = "C:/Users/Dileep/Desktop/Answers/ans-" + probId + ".xml";
            List <char> alph    = new List <char> {
                'a', 'b'
            };
            HashSet <char> al          = new HashSet <char>(alph);
            CharSetSolver  solver      = new CharSetSolver(BitWidth.BV64);
            var            dfa_correct = DFAUtilities.parseDFAfromTutor(ansFile, solver);

            using (StreamReader reader = new StreamReader(dir + "clean.txt"))
                using (StreamWriter writer = new StreamWriter(dir + "Lazy-" + probId + ".txt", false))
                {
                    string   id;
                    string[] file;
                    int      g;
                    RandomGen.SetSeedFromSystemTime();
                    while ((id = reader.ReadLine()) != null)
                    {
                        //CharSetSolver solver = new CharSetSolver(BitWidth.BV64);
                        file = Directory.GetFiles(dir, id + ".xml", System.IO.SearchOption.AllDirectories);
                        Console.WriteLine(file[0]);
                        var dfa = DFAUtilities.parseDFAfromEvent(file[0], solver);
                        if (dfa_correct.Second.IsEquivalentWith(dfa.Second, solver))
                        {
                            g = (RandomGen.GetUniform() > 0.5 ? 10 : 9);
                        }
                        else
                        {
                            g = (int)Math.Max(Math.Min(8.0 - Math.Abs(dfa_correct.Second.StateCount - dfa.Second.StateCount) * 2.0 + RandomGen.GetNormal(0, 2), 10.0), 0.0);
                        }
                        //var g = DFAGrading.GetGrade(dfa_correct.Second, dfa.Second, al, solver, timeout, 10);
                        Console.WriteLine("---- {0},{1}", id, g);
                        writer.WriteLine("{0},{1}", id, g);
                    }
                }
        }
Ejemplo n.º 6
0
        //A test to see how many isomorphic solutions are graded differently by the same grader
        private static void IsoTest(int prob, string grader)
        {
            //get grader score, get DFA from XML for that id ,check if printDFA in Dictionary and add score to that list
            string dir     = "C:/Users/Dileep/Desktop/Attempts/" + prob + "/";
            var    ret     = new Dictionary <string, List <Pair <int, int> > >();
            var    score   = new Dictionary <int, int>();
            string outFile = dir + "Iso-" + grader + ".txt";

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

            using (TextFieldParser parser = new TextFieldParser(dir + grader + "-" + prob + ".txt"))
            {
                parser.Delimiters = new string[] { "," };
                while (true)
                {
                    string[] parts = parser.ReadFields();
                    if (parts == null)
                    {
                        break;
                    }
                    score.Add(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1])); // has also unclean problems
                }
            }
            List <int> clean = new List <int>(); // will have ids of clean problems

            using (StreamReader reader = new StreamReader(dir + "/clean.txt"))
            {
                string line; int id;
                while ((line = reader.ReadLine()) != null)
                {
                    id = Convert.ToInt32(line);
                    clean.Add(id);
                }
            }
            // go through clean, put a list for printDFA if not present, put score in that list.
            string[] file;
            var      sb = new StringBuilder();
            int      ex = 0;
            string   dfaString;

            foreach (int i in clean)
            {
                file = Directory.GetFiles(dir, i + ".xml", System.IO.SearchOption.AllDirectories);
                try
                {
                    DFAUtilities.printDFA(DFAUtilities.parseDFAfromEvent(file[0], solver).Second, al, sb);
                    dfaString = sb.ToString();
                    if (!ret.ContainsKey(dfaString))
                    {
                        ret.Add(dfaString, new List <Pair <int, int> >());
                    }
                    ret[dfaString].Add(new Pair <int, int>(i, score[i]));
                }
                catch (Exception e)
                {
                    Console.WriteLine("EXCEPTION: " + e);
                    ex++;
                }
                sb.Clear();
            }
            using (var writer = new StreamWriter(outFile, false))
            {
                writer.WriteLine("# of string/list pairs: {0}", ret.Count);
                writer.WriteLine("# of exceptions: {0}", ex);
                Console.WriteLine("# of string/list pairs: {0}", ret.Count);
                Console.WriteLine("# of exceptions: {0}", ex);
                foreach (KeyValuePair <string, List <Pair <int, int> > > pair in ret)
                {
                    if (pair.Value.Count != 1)
                    {
                        foreach (Pair <int, int> p in pair.Value)
                        {
                            Console.Write("({0},{1})", p.First, p.Second);
                            writer.Write("({0},{1})", p.First, p.Second);
                        }
                        Console.WriteLine("");
                        writer.WriteLine("");
                    }
                }
            }
        }