public void TextP48()
        {
            var solver = new CharSetSolver(CharacterEncoding.Unicode);
            var alph   = new List <char> {
                'a', 'b'
            };
            var al = new HashSet <char>(alph);

            var moves = new List <Move <CharSet> >();

            var a = solver.MkCharConstraint(false, 'a');
            var b = solver.MkCharConstraint(false, 'b');

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

            var dfa = Automaton <CharSet> .Create(0, new int[] { 2 }, moves).Determinize(solver).Minimize(solver);

            var sb = new StringBuilder();

            DFAUtilities.printDFA(dfa, al, sb);
            System.Console.WriteLine(sb);
        }
예제 #2
0
        private static void PrintDFA(Automaton <BDD> dfa, string name, HashSet <char> al)
        {
            var sb = new StringBuilder();

            DFAUtilities.printDFA(dfa, al, sb);

            System.IO.StreamWriter file = new System.IO.StreamWriter(@"../../../TestPDL/DFAs/" + name + ".txt");
            file.WriteLine(sb);
            file.Close();
        }
        //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("");
                    }
                }
            }
        }