code: public double getFitness(Sudoku candidate,
                               List<? extends Sudoku> population)
      {
          // We can assume that there are no duplicates in any rows because
          // the candidate factory and evolutionary operators that we use do
          // not permit rows to contain duplicates.
  
          int fitness = 0;
  
          // Check columns for duplicates.
          Set<Integer> values = new HashSet<Integer>(Sudoku.SIZE * 2); // Big enough to avoid re-hashing.
          for (int column = 0; column < Sudoku.SIZE; column++)
          {
              for (int row = 0; row < Sudoku.SIZE; row++)
              {
                  values.add(candidate.getValue(row, column));
              }
              fitness += (Sudoku.SIZE - values.size());
              values.clear();
          }
  
          // Check sub-grids for duplicates.
          for (int band = 0; band < Sudoku.SIZE; band += 3)
          {
              for (int stack = 0; stack < Sudoku.SIZE; stack += 3)
              {
                  for (int row = band; row < band + 3; row++)
                  {
                      for (int column = stack; column < stack + 3; column++)
                      {
                          values.add(candidate.getValue(row, column));
                      }
                  }
                  fitness += (Sudoku.SIZE - values.size());
                  values.clear();
              }
          }
          return fitness;
      }
docs: The fitness score for a potential Sudoku solution is the number of
  cells that conflict with other cells in the grid (i.e. if there are
  two 7s in the same column, both of these cells are conflicting).  A
  lower score indicates a fitter individual.
  @param candidate The Sudoku grid to evaluate.
  @param population {@inheritDoc}
  @return The fitness score for the specified individual.