Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

what should a solver do when there is no unique solution?

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku
View previous topic :: View next topic  
Author Message
Bob Hanson

Joined: 05 Oct 2005
Posts: 187
:
Location: St. Olaf College

Items
PostPosted: Mon Nov 07, 2005 3:23 am    Post subject: what should a solver do when there is no unique solution? Reply with quote

What should a solver do when it discovers there is no unique solution?

Sudoku Assistant http://www.stolaf.edu/people/hansonr/sudoku

simply reports that it is "stuck" and that the puzzle probably does not have a unique solution. Is that the proper response?

This occurs when the hypothesis "X can be eliminated" cannot be proved for any remaining node. That makes sense, of course, because if there are ultimately two possible solutions, then for some cells you can never prove which of the two possible values can be eliminated.

It seems to me this could be valuable -- a solver that proves a puzzle is not unique. Yes? No? Should it just go on and solve it anyway?

What do other solvers do?

Test sample:

9.6.83..2
1.56.9...
..3..7.69
75439.62.
3...6..95
.69.5...4
59.83.2..
6...759.3
43.91....

Thanks.
_________________
Bob Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
Back to top
View user's profile Send private message Send e-mail Visit poster's website
abik

Joined: 10 Sep 2005
Posts: 18
:
Location: Santa Clara

Items
PostPosted: Mon Nov 07, 2005 5:36 am    Post subject: Reply with quote

Hi Bob,
We had a similar discussion in the nodes-per-second thread (see http://www.setbb.com/phpbb/viewtopic.php?t=222&mforum=sudoku). I think solvers should simply report the impurity together with the number of solutions, see output of my solver below. Solving for just one solution can substantially reduce search time, however.
Aart
http://www.aartbik.com/



Code:

=> sudoku -p mulisol.txt
Aart's Sudoku Solver v1.0Beta

PROBLEM:
  +---+---+---+
  |9.6|.83|..2|
  |1.5|6.9|...|
  |..3|..7|.69|
  +---+---+---+
  |754|39.|62.|
  |3..|.6.|.95|
  |.69|.5.|..4|
  +---+---+---+
  |59.|83.|2..|
  |6..|.75|9.3|
  |43.|91.|...|
  +---+---+---+

#PUZZLES=1 #SOLUTIONS=25 #IMPURE-PUZZLES=1
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dukuso

Joined: 14 Jul 2005
Posts: 424
:
Location: germany

Items
PostPosted: Mon Nov 07, 2005 7:52 am    Post subject: Reply with quote

and if there are really many solutions, too many to count
them in reasonable time, then it would be nice if the
solver could give an estimate of the number of solutions !

(using Monte Carlo tries or such)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Mon Nov 07, 2005 12:16 pm    Post subject: Reply with quote

I've implemented it this way:

When a puzzle is loaded/pasted or manually entered, a fast backtracking solver using Knuth's dancing links algorithm first validates the puzzle. This routine can report the state of the puzzle:

1. Valid (only one solution)
2. Invalid (no solution)
3. Invalid (more than one solution)

I've limited this routine, so that it will not search for solutions forever. At this moment it stops at 100,000 solutions found. (this takes less than a second)

When a puzzle is invalid, the human-style solver will not be called, and the state is reported by the program.

Validating the puzzle is important if you want to implement techniques like uniqueness tests and magic cells.

The solver could be configured in such a way thay it can find all possible solutions, but that is more a feature for a math program, not for a puzzler's assistant. I think the average puzzler may want to know if it's a 2 solution or a 4 solution puzzle, but when these numbers get really big, who cares...

Ruud.
Back to top
View user's profile Send private message Visit poster's website
soduko

Joined: 10 Oct 2005
Posts: 50
:

Items
PostPosted: Mon Nov 07, 2005 10:37 pm    Post subject: Reply with quote

I would like that it reports.
all possible solutions superinposed in one grid.

I do not think imake my self clear
Embarassed

better give an example
I would like the output to be something like:

Code:

This puzzle has ??? solutions or
This puzzle has more than ???  solutions

all solutions in one grid:

+----------------+----------------+----------------+
| 9c   47   6c   | 1    8c   3c   | 47   5    2c   |
| 1c   247  5c   | 6c   24   9c   | 3478 378  78   |
| 28   248  3c   | 5    24   7c   | 1    6c   9c   |
+----------------+----------------+----------------+
| 7c   5c   4c   | 3c   9c   18   | 6c   2c   18   |
| 3c   18   128  | 247  6c   24   | 78   9c   5c   |
| 28   6c   9c   | 27   5c   18   | 378  1378 4c   |
+----------------+----------------+----------------+
| 5c   9c   17   | 8c   3c   46   | 2c   14   167  |
| 6c   128  128  | 24   7c   5c   | 9c   148  3c   |
| 4c   3c   278  | 9c   1c   26   | 5    78   679  |
+-------+--------+----------------+----------------+




(the c indicates that the value was a clue)

so the solver has to check that there are solutions with one of the extra values as well.

hope that this makes it clear...
Back to top
View user's profile Send private message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Mon Nov 07, 2005 11:22 pm    Post subject: Reply with quote

Quote:
I would like that it reports all possible solutions superinposed in one grid.

You can do that by using a solver that goes all the way in T&E (or any named variety), and let it eliminate as many candidates as it can find. The remaining candidates must be part of any of the possible solutions.

Personally, I'm not so interested in grids with multiple solutions, only in being able to recognize and reject them.
Back to top
View user's profile Send private message Visit poster's website
Bob Hanson

Joined: 05 Oct 2005
Posts: 187
:
Location: St. Olaf College

Items
PostPosted: Mon Nov 07, 2005 11:26 pm    Post subject: Reply with quote

OK, in that case, just go to Sudoku Assistant, and when it gets stuck, click on "Table". It will give you that picture. Clues will be in red.
_________________
Bob Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Tue Nov 08, 2005 5:03 am    Post subject: Reply with quote

I don't think there's much need to report the full number of solutions unless that's in demand by someone. Just run the sucker through dancing links and have it bail out at solution #2. After all, 2 solutions or 1900, you're still dealing with an invalid sudoku.
Back to top
View user's profile Send private message
soduko

Joined: 10 Oct 2005
Posts: 50
:

Items
PostPosted: Tue Nov 08, 2005 10:00 am    Post subject: Reply with quote

Quote:

OK, in that case, just go to Sudoku Assistant, and when it gets stuck, click on "Table". It will give you that picture. Clues will be in red.


No, that does give a table with all candidates that logic (by any name) could not remove. (As far as I understand it)

This is a stricter test there must be a (full grid) solution with that candidate on that square.

It is usefull to test if the logic is complete.

If all (nesesary) logic is implemented then the two are the same, if it is not there will be a difference.

I made a post about this in the mathematics of Sudoku forum
[url]forum.http://www.setbb.com/phpbb/viewtopic.php?t=362&mforum=sudoku[/url]
Back to top
View user's profile Send private message
Bob Hanson

Joined: 05 Oct 2005
Posts: 187
:
Location: St. Olaf College

Items
PostPosted: Tue Nov 08, 2005 10:03 pm    Post subject: Reply with quote

oh, I see. OK. Nevermind!
_________________
Bob Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron