Пример #1
0
        /**
         * Default constructor.
         * @param threadsNumber     Threads number.
         */
        internal SolverTests(int threadsNumber)
        {
            THREADS_NUMBER = threadsNumber;
            threads        = new Thread[THREADS_NUMBER];
            runners        = new TestRunner[THREADS_NUMBER];
            testsResults   = new bool[NUMBER_OF_TESTS];
            int[] testsIds = new int[NUMBER_OF_TESTS];
            for (int i = 0; i < NUMBER_OF_TESTS; i++)
            {
                testsIds[i] = i;
            }

            /*
             * Randomization of tests before assignments to threads
             */
            for (int i = 0; i < NUMBER_OF_TESTS; i++)
            {
                int lastIndex = NUMBER_OF_TESTS - i - 1;
                int j         = SudokuStore.randomIndex(NUMBER_OF_TESTS - i);
                if (j != lastIndex)
                {
                    int l = testsIds[lastIndex];
                    testsIds[lastIndex] = testsIds[j];
                    testsIds[j]         = l;
                }
            }

            /*
             * Tests assignments to threads
             */
            int defThreadSize = NUMBER_OF_TESTS / THREADS_NUMBER;
            int remaining     = NUMBER_OF_TESTS - defThreadSize * THREADS_NUMBER;
            int t             = 0;

            for (int i = 0; i < THREADS_NUMBER; i++)
            {
                int threadSize = defThreadSize;
                if (i < remaining)
                {
                    threadSize++;
                }
                int[] assigments = new int[threadSize];
                for (int j = 0; j < threadSize; j++)
                {
                    assigments[j] = testsIds[t];
                    t++;
                }
                runners[i] = new TestRunner(i, assigments, testsResults);
                threads[i] = new Thread(runners[i].run);
            }
        }
Пример #2
0
        /**
         * Random string generator.
         * @param length    Length of random string.
         * @return          Random string containing a-zA-Z0-9.
         */
        public static String randomString(int length)
        {
            if (length < 1)
            {
                return("");
            }
            char[] chars =
            {
                'z', 'x', 'c', 'v', 'b', 'n', 'm', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
                'Z', 'X', 'C', 'V', 'B', 'N', 'M', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
            };
            String rndStr = "";

            for (int i = 0; i < length; i++)
            {
                rndStr = rndStr + chars[SudokuStore.randomIndex(chars.Length)];
            }
            return(rndStr);
        }
Пример #3
0
 /**
  * Default constructor based on random Sudoku puzzle example.
  *
  * @param parameters      Optional parameters.
  *
  * @see #PARAM_DO_NOT_SOLVE
  * @see #PARAM_DO_NOT_TRANSFORM
  * @see #PARAM_GEN_RND_BOARD
  */
 public SudokuGenerator(params char[] parameters)
 {
     setParameters(parameters);
     initInternalVars();
     if (generateRandomBoard == true)
     {
         boardInit(null, "random board");
     }
     else
     {
         int example = SudokuStore.randomIndex(SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES);
         int[,] board = SudokuStore.boardCopy(SudokuStore.getPuzzleExample(example));
         if (transformBeforeGeneration == true)
         {
             boardInit(SudokuStore.seqOfRandomBoardTransf(board), "transformed example: " + example);
         }
         else
         {
             boardInit(board, "example: " + example);
         }
     }
 }