Esempio n. 1
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();
             }
         }
     }
 }
Esempio n. 2
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));
        }
Esempio n. 3
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));
        }