0

I need to create a program (in C#) to solve Sudoku's with Random Restart Hill Climbing and as operator switching values of two fields. The start solution of the sudoku will always have each field assigned a value to (from 1 to nn) where each rectangular subgrid of nn has each number occuring only once in it.

Now I have two questions:

  1. How do I determine the next two fields of the sudoku to operate for the hill climbing algorithm?

  2. When do I restart the hill climbing algorithm? ( / How to determine a (local) maximum has been reached, there are no more sucessors better than the current solution?)

If anyone could help me out on this it'd be much appreciated.

Best regards.

user2999349
  • 859
  • 8
  • 21
  • The next two numbers are of the sequence and this is restarted when the rules of soduku are broken – Shon Jun 02 '16 at 09:58
  • @Shon How do you mean of the sequence? I have a sudoku grid where each field has a number assigned to it and from that I need to determine 2 fields to swap values. As for the restarts the rules of sudoku are already broken untill a global maximum solution is found, except for the rule that each number should only occur once in a subgrid (as that's how I initialize a start solution). Hill climbing should terminate when a maximum has been reached (in this case when there's no better successor situation that can be formed by swapping 2 fields' values), but I don't know how to determine this. – user2999349 Jun 02 '16 at 10:02
  • A sudoku will have each digit 1 to 9 occur nine times. So you can determine at the beginning which number numbers are missing and randomly fill in the the board with these missing numbers. The you can solve by swapping the added numbers until game is solved. – jdweng Jun 02 '16 at 10:22
  • @jdweng Yes exactly but I need to use random restart hill climbing for this which does that with a heuristic function to check the quality of the newly formed solution after a swap. Then if the new solution is better it keeps it otherwise tries a different swap, etc. However the algorithm needs to restart with a new random solution when no better (successor) solutions can be created by swapping but I don't know how to verify this when for example picking the fields to swap randomly (these should be within the same subgrid btw) – user2999349 Jun 02 '16 at 11:24
  • 1
    Randomly picking is going to take forever to solve. You need to try every combination and randomly picking for every combination doesn't work. Now if you want to randomly pick a subgrid that will work. For scoring results I wold count duplicate numbers in each column and row. – jdweng Jun 02 '16 at 12:44
  • @jdweng Ah alright thanks, that makes sense. I'll try by going through every possible combination, I guess I'll have to keep lists of all swapable fields for each subgrid then so when all combinations are checked I know the maximum has been reached. As for the heuristic function I had to use the amount of missing numbers in the sudoku. – user2999349 Jun 02 '16 at 13:04

0 Answers0