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   

let's merge our ideas/programs into a best, common solver !

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

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

Items
PostPosted: Sat Jul 23, 2005 6:39 am    Post subject: let's merge our ideas/programs into a best, common solver ! Reply with quote

I don't want to implement all these rules ...
Can't we do something which "includes" all the rules even if
it's a bit slower ?


Or better: is there a downloadable list of sets to test ?
We have a 9*9*9 ternary(0:allowed,1:forbidden,2:already placed)
array of placements (x,y,s) whether symbol s can go into cell (x,y).
As one rule, assume we have a subset of size -say- 6 of this 9*9*9.array ;
if its sum is -say- 5 , then we have another subset which can
be marked 1 (forbidden).
Now, let's make a list of all these (subset,sum,subset)-triples
which have to be checked ! Can your program generate them ?
Then that list can be easily included to improve and simplify
other solvers.


Whenever you have to guess, then it's likely that there are just
only two possibilities.
Check both of them, but this time only by making forced moves,
no further (2nd-level) guesses.
If one of the two possibilities leads to a dead end (=contradiction),
then we can choose the other one as a forced placement.


More generally :
use lookahead of level L to determine which of
the bifurcations (only 2 digits possible in row.column,block,cell)
have the fewest nodes at distance L from the bifurcation-centre.

L is adapted dynamically depending on the average number
of bifurcations and nodes, so that the total time spent
at distance k from a bifurcation is almost konstant(k).

I'm not so much concerned about the 9*9
puzzles here but about the larger ones 16*16,25*25,...
Yes, it's NP-complete but let's see how good we can do
here compared with other NP-complete problems.
The 9*9-case with all these rules is pretty well solvable,
at which level do the real problems arise ?

Guenter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hoppy

Joined: 15 Jul 2005
Posts: 7
:

Items
PostPosted: Sat Jul 23, 2005 11:00 am    Post subject: Reply with quote

The brute forcing methods just have to check the basic game rules - all squares must appear in each individual row/col/block.
The other tests such as looking for groups of numbers are used when attempting to solve with logic (no guessing or looking ahead - just rule out possibilities - and fill in numbers as the become certain).
This brute force method should work for larger grids, there are constants defined for grid & block size:
http://www.users.waitrose.com/~nihilist/sudoku.html
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sat Jul 23, 2005 1:51 pm    Post subject: Reply with quote

I convinced myself that the best method to write a solver is to
use the dancing links method - but without keeping the whole
4*n*n * n*n*n binary matrix, only the 4 nonzero entries
per row and the 9 nonzero entries per column.
I hope that's possible ?!

And then, always do forced placements immediately.
And check for bifurcations(= 2 possible placements), where
one way leads to a dead end (=contradiction) when filling
in the forced forced placements.
Call such bifurcations "forced placements of level 2".
This should include all the other rules with x-wing, disjoint subset,
etc. They are all forced placements of level 2.

We could extend this to bifurcations, where one way leads
to another bifurcation with two dead ends etc.
I wonder, whether that's what tilps is doing with his
ratings like 1.3.2
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tilps

Joined: 19 Jun 2005
Posts: 44
:

Items
PostPosted: Sat Jul 23, 2005 2:32 pm    Post subject: Reply with quote

Quote:
I convinced myself that the best method to write a solver is to
use the dancing links method - but without keeping the whole
4*n*n * n*n*n binary matrix, only the 4 nonzero entries
per row and the 9 nonzero entries per column.
I hope that's possible ?!


if you actually have the zeros at all then you arent actually doing dancing links, the speed of dancing links comes from not having the array at all, but from storing all the '1's' in multiply linked objects. See antony's source code over in the setting sudokus section.

If you want to do something which 'includes' all the rules, then you want to do what I am doing probably, runtime generated constructive logic. You find possibility pairs/tripples/quadruples/etc in the puzzle, and perform find the common eliminations that can be generated using simple logic on each branch of the possibility n-tuple. You can then reduce the set of changes on each branch down to just the ones needed to cause the elimination, which will show you the information you need to explain the 'logic rule' which has been used, to someone else. My rating system is an attempt to classify the logic rules generated in a 'basic' order of difficulty. Within each rating classification there are easier and harder ones, and there is probably some overlap between the classifications themselves, but as an overal concept, they show an order of difficulty.
Rating 0 puzzles are trivial
Rating 1.0.2 and 1.0.3 are solvable by most reasonable sudoku solvers.
Rating 1.1.2 is where the puzzles start to become 'interesting', tricks like xwing and xy-wing start to come into play. Locked doubles fall into this category.
Rating 1.2.x puzzles are all pretty much only for super-puzzle solvers. (My financee managed to solve rubylips 48-unwind puzzle by hand using logic ... I was impressed)
1.3+ is insane. (well, i havent given any of those to my fiancee yet, may turn out humans can do those too...)

Rating 2 is for where logic is not enough to find a common elimination, and that common elimination techniques need to be performed on possibility pairs/triples/etc within the branch already being looked at in order to generate common elimination on the current branching point.
Rating 2 is needed for locked tripples. I have found no evidence that rating 2 is needed for 3x3 puzzles. It may be needed for 4x4, I am investigating that now. Other than locked tripples, I dont see any human ever being able to actually use this level of logic.
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sat Jul 23, 2005 3:10 pm    Post subject: Reply with quote

>>I convinced myself that the best method to write a solver is to
>>use the dancing links method - but without keeping the whole
>>4*n*n * n*n*n binary matrix, only the 4 nonzero entries
>>per row and the 9 nonzero entries per column.
>>I hope that's possible ?!
>
>
>if you actually have the zeros at all then you arent actually
>doing dancing links, the speed of dancing links comes from not
>having the array at all, but from storing all the '1's' in multiply
>linked objects. See antony's source code over in the setting sudokus
>section.

you're probably right. I'll search for antony's code.
We might need a modified dancing links because we have a special
array which could speedup some things. And we want to keep
track of the constraints to report the solution-way with rows,cols,
blocks to readers.

>If you want to do something which 'includes' all the rules, then
>you want to do what I am doing probably, runtime generated
>constructive logic.

whatever that is..

>You find possibility pairs/tripples/quadruples/etc in the puzzle,
>and perform find the common eliminations that can be generated
>using simple logic on each branch of the possibility n-tuple.
>You can then reduce the set of changes on each branch down to
>just the ones needed to cause the elimination, which will show
>you the information you need to explain the 'logic rule' which
>has been used, to someone else.

which can be done in different ways. IMO the simplest is the way
explained in my previous post.

>My rating system is an attempt to classify the logic rules generated
>in a 'basic' order of difficulty.

which depends on your subjective classification. While I claim
that my classification is more "canonical". You just measure
the degree of bifurcation or lookahead in a well-defined
search-tree. Just graph-theoretical parameters.

>Within each rating classification there are easier and harder ones,
>and there is probably some overlap between the classifications themselves,
>but as an overal concept, they show an order of difficulty.

that's the problem. Others might have other interpretations of overlap

>Rating 0 puzzles are trivial
>Rating 1.0.2 and 1.0.3 are solvable by most reasonable sudoku solvers.
>Rating 1.1.2 is where the puzzles start to become 'interesting',
>tricks like xwing and xy-wing start to come into play.

in my rating there is no difference between these terms.Why should
e.g. "x-wing" be more or less difficult than "forced chain" ?
It's both just lookahead of level 1 : assume a placement, make
forced moves, see if you get a contradiction (dead end).

>Locked doubles fall into this category.

I don't know locked doubles or xy-wing ATM. Maybe I should/will look
it up..

>Rating 1.2.x puzzles are all pretty much only for super-puzzle solvers.
>(My financee managed to solve rubylips 48-unwind puzzle by hand using
>logic ... I was impressed)
>1.3+ is insane. (well, i havent given any of those to my fiancee yet,
>may turn out humans can do those too...)

depends on the time which you invest

>Rating 2 is for where logic is not enough to find a common elimination,

you just have to increase the lookahead-level. Well, depends on how
you define "common elimination"

>and that common elimination techniques need to be performed on
>possibility pairs/triples/etc within the branch already being looked
>at in order to generate common elimination on the current branching point.
>Rating 2 is needed for locked tripples. I have found no evidence that
>rating 2 is needed for 3x3 puzzles. It may be needed for 4x4, I am
>investigating that now. Other than locked tripples, I dont see any
>human ever being able to actually use this level of logic.

given enough time he will.

Once I implemented my lookahead-rating, I'll try to generate
harder sudokus...


Guenter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jaap

Joined: 13 Jun 2005
Posts: 24
:
Location: NL

Items
PostPosted: Sat Jul 23, 2005 10:23 pm    Post subject: Reply with quote

tilps wrote:
if you actually have the zeros at all then you arent actually doing dancing links, the speed of dancing links comes from not having the array at all, but from storing all the '1's' in multiply linked objects.


I used Dancing Links (DLX) in a polyomino solver, and it works quite well. In my sudoku solver I decided to kind of use dlx again, but this time indeed storing the full matrix, including zeros, and not do any of that actual linking stuff.

While not storing the zeros does give a some speed improvement, I think the biggest advantage of dancing links over more naive brute force is that dancing links always fills in the most constrained option first, so that the branching factor of the search tree is smaller.

In the case of Sudoku I felt that doing the linking dance was not worth the trouble, mainly because it is a relatively small problem anyway. It is easier to program, and easier to reset the matrix for the next solve (just reactivate any 'deleted' columns and rows of the matrix).

Jaap
http://www.geocities.com/jaapsch/puzzles/
http://www.geocities.com/jaapsch/sudoku.htm
_________________
Jaap
--
Jaap's Puzzle Page:
http://www.geocities.com/jaapsch/puzzles
Back to top
View user's profile Send private message Visit poster's website
tilps

Joined: 19 Jun 2005
Posts: 44
:

Items
PostPosted: Sat Jul 23, 2005 11:59 pm    Post subject: Reply with quote

dukuso wrote:


>If you want to do something which 'includes' all the rules, then
>you want to do what I am doing probably, runtime generated
>constructive logic.

whatever that is..

constructive logic is about making progress without using contradiction. Its runtime generated because I don't program the actual logic rules into the program, I program the general concept which appears in all of the logic rules I have seen people use.

Quote:

>My rating system is an attempt to classify the logic rules generated
>in a 'basic' order of difficulty.

which depends on your subjective classification. While I claim
that my classification is more "canonical". You just measure
the degree of bifurcation or lookahead in a well-defined
search-tree. Just graph-theoretical parameters.

I measure how large a logic set is needed to make progress from a given board and under what circumstances the logic set is generated, that is what drives my rating. These may be graph theoretical parameters, but not on the same graph as you are working from.

Quote:

>Rating 0 puzzles are trivial
>Rating 1.0.2 and 1.0.3 are solvable by most reasonable sudoku solvers.
>Rating 1.1.2 is where the puzzles start to become 'interesting',
>tricks like xwing and xy-wing start to come into play.

in my rating there is no difference between these terms.Why should
e.g. "x-wing" be more or less difficult than "forced chain" ?
It's both just lookahead of level 1 : assume a placement, make
forced moves, see if you get a contradiction (dead end).

If you take advantage of the fact that you reach a deadend then your solver will be accused of using trial and error rather than just logic to solve.
As to why should the rating be any different. No 3x3 puzzle I have found requires anything more then one lookahead at any stage to make logical progress. So every puzzle ends up rated either 0 or 1. 0 being trivial and 1 being easy to impossible for humans. But xwing is easier than swordfish is easier than jellyfish is easier than super-long-fishy-cycle. hence 1.1 < 1.2 < 1.3 < 1.4+

Quote:

>Rating 2 is for where logic is not enough to find a common elimination,

you just have to increase the lookahead-level. Well, depends on how
you define "common elimination"


If you are writing a 'runtime generated constructive logic' solver, there isnt really a large space for defining common elimination.
Back to top
View user's profile Send private message
tilps

Joined: 19 Jun 2005
Posts: 44
:

Items
PostPosted: Sun Jul 24, 2005 12:31 am    Post subject: Reply with quote

jaap wrote:

While not storing the zeros does give a some speed improvement, I think the biggest advantage of dancing links over more naive brute force is that dancing links always fills in the most constrained option first, so that the branching factor of the search tree is smaller.


DLX has two advantages, backtracking is cheap in that memory costs are tiny and you don't have to clone your array, and that it keeps efficient track of the current branching factors. Trying to choose the smallest branching factor is a 'standard' technique in brute force. Not something I associate with DLX at all. DLX also recurses very well, it requires only 1 pointer per recursion and you store that on an external stack anyway.

As to sudoku being a small problem, 3x3 certainly is, but if you ever want to generate a 5x5 sudoku you may find performance starts to matter.
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sun Jul 24, 2005 8:49 am    Post subject: Reply with quote

jaap wrote:
tilps wrote:
if you actually have the zeros at all then you arent actually doing dancing links, the speed of dancing links comes from not having the array at all, but from storing all the '1's' in multiply linked objects.


I used Dancing Links (DLX) in a polyomino solver, and it works quite well. In my sudoku solver I decided to kind of use dlx again, but this time indeed storing the full matrix, including zeros, and not do any of that actual linking stuff.

While not storing the zeros does give a some speed improvement, I think the biggest advantage of dancing links over more naive brute force is that dancing links always fills in the most constrained option first, so that the branching factor of the search tree is smaller.

In the case of Sudoku I felt that doing the linking dance was not worth the trouble, mainly because it is a relatively small problem anyway. It is easier to program, and easier to reset the matrix for the next solve (just reactivate any 'deleted' columns and rows of the matrix).

Jaap
http://www.geocities.com/jaapsch/puzzles/
http://www.geocities.com/jaapsch/sudoku.htm



for most polyominoes problems, it's slower than the normal method.
Assume you have a long rectangle, you would fill it top to
bottom, not leaving any holes. How could you tell this method
to DLX ? It would probably first fill the 4 corners and then add
pieces to any of the 4 chunks.
Storing the zeros would require n^5 space for sudokus ! So 64*64
would probably be already too large.

Yes, the algo fills the most constrained position first, but what when
there are many columns of sum 2 as is typical for sudoku ?


The advantage of DLX with sudokus is, that you need only one routine
to check the 4 constraints, but I haven't yet done it, so I still
have 4 routines . Well, they are almost identical so I could
copy them and make some small changes. So I can also better
keep track, which move I'm actually doing.
Hmm, with DLX you derive this info from the address of the column ?
But aren't some columns deleted during the algo ?



Guenter.
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