/// <summary>
        /// This method computes for each row the list of digit permutations that respect the target mask, that is the list of valid rows discarding columns and boxes
        /// </summary>
        /// <param name="sudokuBoard">the target sudoku to account for</param>
        /// <returns>the list of permutations available</returns>
        public IList <IList <IList <int> > > GetRowsPermutations(SudokuBoard sudokuBoard)
        {
            if (sudokuBoard == null)
            {
                return(UnfilteredPermutations);
            }

            // we store permutations to compute them once only for each target Sudoku
            if (!_rowsPermutations.TryGetValue(sudokuBoard, out var toReturn))
            {
                // Since this is a static member we use a lock to prevent parallelism.
                // This should be computed once only.
                lock (_rowsPermutations)
                {
                    if (!_rowsPermutations.TryGetValue(sudokuBoard, out toReturn))
                    {
                        toReturn = GetRowsPermutationsUncached(sudokuBoard);
                        _rowsPermutations[sudokuBoard] = toReturn;
                    }
                }
            }
            return(toReturn);
        }
 /// <summary>
 /// Constructor with a mask sudoku to solve, assuming a length of 9 genes
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 public SudokuPermutationsChromosome(SudokuBoard targetSudokuBoard) : this(targetSudokuBoard, 9)
 {
 }
示例#3
0
 /// <summary>
 /// Constructor that takes the target Sudoku, the number of permutation genes per row, and the number of Sudokus to evaluate
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="nbPermutations">the number of permutation genes per row</param>
 /// <param name="nbSudokus">the number of Sudokus generated for evaluation</param>
 public SudokuRandomPermutationsChromosome(SudokuBoard targetSudokuBoard, int nbPermutations, int nbSudokus) : base(targetSudokuBoard, 9 * nbPermutations)
 {
     _nbPermutations = nbPermutations;
     _nbSudokus      = nbSudokus;
 }
 /// <summary>
 /// /// Constructor with a mask and extended mask accounting for initial constraint propagation for faster cloning
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="extendedMask">The cell domains after initial constraint propagation</param>
 public SudokuPermutationsChromosome(SudokuBoard targetSudokuBoard, Dictionary <int, List <int> > extendedMask) : this(targetSudokuBoard, extendedMask, 9)
 {
 }
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="extendedMask">The cell domains after initial constraint propagation</param>
 /// <param name="length">The number of genes for the sudoku chromosome</param>
 public SudokuPermutationsChromosome(SudokuBoard targetSudokuBoard, Dictionary <int, List <int> > extendedMask, int length) : base(targetSudokuBoard, extendedMask, length)
 {
 }
示例#6
0
 public SudokuFitness(SudokuBoard targetSudokuBoard)
 {
     _targetSudokuBoard = targetSudokuBoard;
 }
 /// <summary>
 /// Constructor with a mask and a number of genes
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="length">the number of genes</param>
 public SudokuPermutationsChromosome(SudokuBoard targetSudokuBoard, int length) : this(targetSudokuBoard, null, length)
 {
 }
示例#8
0
 /// <summary>
 /// Constructor with additional precomputed domains for faster cloning
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="extendedMask">The cell domains after initial constraint propagation</param>
 public SudokuCellsChromosome(SudokuBoard targetSudokuBoard, Dictionary <int, List <int> > extendedMask) : base(targetSudokuBoard, extendedMask, 81)
 {
 }
示例#9
0
        /// <summary>
        /// Builds a single Sudoku from the 81 genes
        /// </summary>
        /// <returns>A Sudoku board built from the 81 genes</returns>
        public override IList <SudokuBoard> GetSudokus()
        {
            var sudoku = new SudokuBoard(GetGenes().Select(g => (int)g.Value));

            return(new List <SudokuBoard>(new[] { sudoku }));
        }
示例#10
0
 /// <summary>
 /// Basic constructor with target sudoku to solve
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 public SudokuCellsChromosome(SudokuBoard targetSudokuBoard) : this(targetSudokuBoard, null)
 {
 }
示例#11
0
 /// <summary>
 /// Constructor that accepts an additional extended mask for quick cloning
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="extendedMask">The cell domains after initial constraint propagation</param>
 /// <param name="length">The number of genes for the sudoku chromosome</param>
 public SudokuChromosomeBase(SudokuBoard targetSudokuBoard, Dictionary <int, List <int> > extendedMask, int length) : base(length)
 {
     _targetSudokuBoard = targetSudokuBoard;
     _extendedMask      = extendedMask;
     CreateGenes();
 }
示例#12
0
 /// <summary>
 /// Constructor that accepts a Sudoku to solve
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="length">The number of genes for the sudoku chromosome</param>
 public SudokuChromosomeBase(SudokuBoard targetSudokuBoard, int length) : this(targetSudokuBoard, null, length)
 {
 }
示例#13
0
 /// <summary>
 /// Constructor that takes the target Sudoku, the number of permutation genes per row, and the number of Sudokus to evaluate
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="nbPermutations">the number of permutation genes per row</param>
 /// <param name="nbSudokus">the number of Sudokus generated for evaluation</param>
 public SudokuRandomPermutationsChromosome(SudokuBoard targetSudokuBoard, Dictionary <int, List <int> > extendedMask, int nbPermutations, int nbSudokus) : base(targetSudokuBoard, extendedMask, 9 * nbPermutations)
 {
     _nbPermutations = nbPermutations;
     _nbSudokus      = nbSudokus;
 }
示例#14
0
 /// <summary>
 /// Constructor that takes the target Sudoku, the number of permutation genes per row, and the number of Sudokus to evaluate
 /// </summary>
 /// <param name="targetSudokuBoard">the target sudoku to solve</param>
 /// <param name="nbPermutations">the number of permutation genes per row</param>
 /// <param name="nbSudokus">the number of Sudokus generated for evaluation</param>
 public SudokuRandomPermutationsChromosome(SudokuBoard targetSudokuBoard, int nbPermutations, int nbSudokus) : this(targetSudokuBoard, null, nbPermutations, nbSudokus)
 {
 }