public static WExpr ParseWhileProgramFromXML(XElement program)
        {
            XElement exprs       = program.Element("Exprs");
            XElement numVars     = program.Element("NumVariables");
            XElement uselessVars = program.Element("UselessVariables");

            int numVariables;

            if (int.TryParse(numVars.Value, out numVariables))
            {
                WExprParser parser = new WExprParser(numVariables);
                WExpr       rv     = parser.parseWExprFromXML((XElement)exprs.FirstNode);
                rv.UselessVariables = new HashSet <int>();
                foreach (string variable in WhileUtilities.ParseEnumerableFromXML(uselessVars))
                {
                    rv.UselessVariables.Add(int.Parse(variable));
                }
                return(rv);
            }
            else
            {
                //TODO
                return(null);
            }
        }
Exemplo n.º 2
0
 static void XML(params int[] indices)
 {
     if (indices.Length == 0)
     {
         foreach (WExpr program in programs)
         {
             string   s1            = program.ToString();
             XElement xml           = new XElement("WhileProgram", new XAttribute("NumVariables", program.GetNumVariables()), program.ToXML());
             WExpr    parsedProgram = WhileUtilities.ParseWhileProgramFromXML(xml);
             string   s2            = parsedProgram.ToString();
             Console.WriteLine(s1 == s2);
         }
     }
     else
     {
         foreach (int index in indices)
         {
             WExpr    program       = programs[index];
             string   s1            = program.ToString();
             XElement xml           = new XElement("WhileProgram", new XAttribute("NumVariables", program.GetNumVariables()), program.ToXML());
             WExpr    parsedProgram = WhileUtilities.ParseWhileProgramFromXML(xml);
             string   s2            = parsedProgram.ToString();
             Console.WriteLine(s1 == s2);
         }
     }
 }
Exemplo n.º 3
0
 static void NullTapes()
 {
     foreach (WExpr program in programs)
     {
         Console.WriteLine(program.ToString());
         Console.ReadKey();
         var     M = program.ToTMCB(-1);
         bool    dummy;
         int[][] output = M.Run(program.GetNumVariables(), out dummy);
         Console.WriteLine("output:");
         Console.WriteLine(WhileUtilities.TapesToString(output, M.blank));
         Console.ReadKey();
     }
 }
Exemplo n.º 4
0
 static void ConversionAndTMFunctionality(params int[] indices)
 {
     if (indices.Length == 0)
     {
         foreach (WExpr program in programs)
         {
             Console.WriteLine(program.ToString());
             Console.ReadKey();
             var M = program.ToTMCB(-1);
             foreach (int[][] input in WhileUtilities.NonNegIntTestInputs(program.GetNumVariables(), 4, program.GetUselessVariables().ToArray()))
             {
                 Console.WriteLine("input:");
                 Console.WriteLine(WhileUtilities.TapesToString(input, M.blank));
                 bool    dummy;
                 int[][] output = M.Run(input, out dummy);
                 Console.WriteLine("output:");
                 Console.WriteLine(WhileUtilities.TapesToString(output, M.blank));
                 Console.ReadKey();
             }
         }
     }
     else
     {
         foreach (int index in indices)
         {
             Console.WriteLine(programs[index].ToString());
             Console.ReadKey();
             var M = programs[index].ToTMCB(-1);
             foreach (int[][] input in WhileUtilities.NonNegIntTestInputs(programs[index].GetNumVariables(), 4, programs[index].GetUselessVariables().ToArray()))
             {
                 Console.WriteLine("input:");
                 Console.WriteLine(WhileUtilities.TapesToString(input, M.blank));
                 bool    dummy;
                 int[][] output = M.Run(input, out dummy);
                 Console.WriteLine("output:");
                 Console.WriteLine(WhileUtilities.TapesToString(output, M.blank));
                 Console.ReadKey();
             }
         }
     }
 }
Exemplo n.º 5
0
        public override bool KeepProgram(WExpr candidate)
        {
            Automata.TMCB <int, int> M = candidate.ToTMCB(-1);
            int numTapes      = candidate.GetNumVariables();
            int inputsPerTape = (int)Math.Pow(numTestInputs, (double)1 / numTapes);

            bool dummy;
            int  count = 0; //counts inputs for which the TM times out
            int  total = 0;

            foreach (int[][] input in WhileUtilities.NonNegIntTestInputs(numTapes, inputsPerTape, candidate.GetUselessVariables().ToArray()))
            {
                M.Run(input, out dummy);
                if (M.Timeout)
                {
                    ++count;
                }
                ++total;
            }
            return(decideByPercentage(count, total));
        }
Exemplo n.º 6
0
        public override bool KeepProgram(WExpr candidate)
        {
            Automata.TMCB <int, int> M = candidate.ToTMCB(-1);
            int numTapes      = candidate.GetNumVariables();
            int inputsPerTape = (int)Math.Pow(numTestInputs, (double)1 / numTapes);

            bool dummy;

            int[][] output;
            int     count = 0; //counts inputs that get modified by a run of the TM
            int     total = 0;

            foreach (int[][] input in WhileUtilities.NonNegIntTestInputs(numTapes, inputsPerTape, candidate.GetUselessVariables().ToArray()))
            {
                output = M.Run(input, out dummy);
                if (!WhileUtilities.TapesEqual(Array.ConvertAll(input, tape => WhileUtilities.TapeToString(tape, M.blank, null)), Array.ConvertAll(output, tape => WhileUtilities.TapeToString(tape, M.blank, null))))
                {
                    ++count;
                }
                ++total;
            }
            return(decideByPercentage(count, total));
        }