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   

somebody tried this? "Dancing templates"

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

Joined: 10 Oct 2005
Posts: 50
:

Items
PostPosted: Fri Dec 09, 2005 4:12 pm    Post subject: somebody tried this? "Dancing templates" Reply with quote

Reading about dancing links (DLX) I suddenly realised that you can also combine dancing links with templates.

the rows (placements) becomes the templates+ symbol (a big number) {9* (6^6), I cannot find my calculator}

While the number of collums / constraint become much smaller number (90 vs 324) ( only the RC constraints and a collumn/ constraint per symbol)


I am not sure if it will be quicker than the "normal DLX" but it has a lot of efficiency in it, the depth of the search will be reduced to 9, (vs 61- 81) (only nine templates make a soduku) and maybe even more interesting the test of constraints can be done bitwise (there are only 90 of them).
Against it are the very much lager number of rows (9 * 6^6 vs 729) and more constraints per row.(10 vs 4)

maybe there are even more efficienties possible.
(I haven't said anything about grouping the templates by symbols yet)


I will add more mathematical data as it becomes available, (when i find my calculator)
But i think that my computing power is not up to this way of solving soduko. (and i am using basic instead of more capable languages)

But maybe yours is...

Please try.
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Fri Dec 09, 2005 6:29 pm    Post subject: Reply with quote

yes, a sudoku solution is just a disjoint union of 9 out of
the 46656 templates and thus an exact cover problem
with 46656 rows and 81 columns. That is for the
empty grid.
Now given a sudoku with clues, select those out of the
46656 templates, which have only clues of one value
(=digit=symbol) in it.
Any solution of the sudoku must be a disjoint union of those
templates and vice versa.

I don't think this method will be very effective, though.
But it's worth trying. Should be easy to test...

I don't see, why you think you need 9*46656 rows and 90 columns
Back to top
View user's profile Send private message Send e-mail Visit poster's website
soduko

Joined: 10 Oct 2005
Posts: 50
:

Items
PostPosted: Fri Dec 09, 2005 8:06 pm    Post subject: Reply with quote

Quote:

I don't see, why you think you need 9*46656 rows and 90 columns


rows
419.904 = every template x every symbol

collumns
90 = every position (81) + every symbol (9)


I do not see how you can do DLX with only 46656 rows
(It is not just a disjoint set of 9 templates without symbols, the templates have a symbol)

The symbol also needs a collumn, to get only one template for every symbol.

But maybe you are right and it can be done with only 46656 rows,. (it would make it much faster)


Also the numbers i mentioned are for all existing posibilities. (a bit like starting with an empty grid)

It is more practical to start with an reduced set by eliminating all templates-symbol combinations and positions that are made impossible or met by the clues.
It then becomes the theoretical question where do you draw the line between initialising and starting, presuming you draw such a line.
And number you calculate this way are very puzzle based.
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sat Dec 10, 2005 5:10 am    Post subject: Reply with quote

you are right, it should be done with 90 columns and 46656*9 rows
for the empty grid.
You could try 46656 rows and 81 columns but then you must filter the
output, since some templates might contain the same symbol.
I tried it, it's very slow while your method found the solution
in 5sec. - still much slower than the normal method.

When each symbol occurs as a clue, then after the reduction
there can't remain more than 46656 rows.

I tried this sudoku:
7.8...3.....2.1...5.........4.....263...8.......1...9..9.6....4....7.5...........
and 12854 rows remained after the reduction.

Further reductions due to forced placements are probably useless
since the algo would do these anyway.
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: Sat Dec 10, 2005 11:43 am    Post subject: Reply with quote

Quote:
you are right, it should be done with 90 columns and 46656*9 rows
for the empty grid.

With this large number of rows, I see no possibility to make this faster than DLX on the 4 basic constraints.

I still use the templates in Sudo Cue. For a single digit, they outperform any human-style solving technique.

At this moment I am implementing the very promising "constraint subsets" technique. Because they are very hard to find, I am using templates to check if there may be possible eliminations for a single digit, and then try to find a constraint subset for that digit, which can explain the eliminations.

Ruud.
_________________
Meet me at sudocue.net
Back to top
View user's profile Send private message Visit poster's website
dukuso

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

Items
PostPosted: Sat Dec 10, 2005 12:46 pm    Post subject: Reply with quote

yes, it's much slower.
And probably not feasable for larger sudokus.
How many templates are there for 16*16 ? Probably too many.

The number of rows is not the main problem,
when converting sudokus to SAT-instances you
can get very large files too (before reducing due to clues)-
yet this is the fastest known method.

The templates method could become more intesting
when you add further constraints, like in 3doku
or magic sudoku.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
soduko

Joined: 10 Oct 2005
Posts: 50
:

Items
PostPosted: Sat Dec 10, 2005 6:27 pm    Post subject: Reply with quote

hello Dusoku and Ruud

Dusoku wrote:
Quote:
you are right, it should be done with 90 columns and 46656*9 rows
for the empty grid.
You could try 46656 rows and 81 columns but then you must filter the
output, since some templates might contain the same symbol.
I tried it, it's very slow while your method found the solution
in 5sec. - still much slower than the normal method.

When each symbol occurs as a clue, then after the reduction
there can't remain more than 46656 rows.


It is a bit what is it supposed to solve.
an empty grid is for this technique a worst case scenario
with only one clue placed the number of rows is down from 419.904 to 336.960 (5148 + 8*(46656-5148))
(see below for where the 5148 comes from)


Terminology

Quote:

a "pinned" symbol is a symbol that is mentioned in the list with clues
a "free" symbol is a symbol that is not a pinned symbol

"valid" template
For a "pinned" symbol any template that has ALL clues positions for that symbol, and none of the positions of other clues
For a "free" symbol any template that has none of the clue postitions.


"invalid" template (this is only a negating of the "valid" template)
A template that has some but not all clues postions of a certain symbol
or
A template that has clues postions from different symbols
or
Only if there are no "free symbols" a template that has no clues positions




New insights

You only need collumns for "free" symbols
("valid" templates from pinned symbols have already common collumns so there is no need for an extra common collumn)

Added later:

Keep the collumns per symbol (for both "free" and "pinned" symbols)
and delete of all the position collumns were a clue was placed.
(they are not needed anymore, they have the same function as the symbol collumns)




If there is none or only one "free symbol" there can only be 46656 rows
(Probably much less)


Reflections on more than one "free" symbol

All free symbols have the same basic templates (basic template == the templates without the symbol itself)

If there are two or more "free" symbols the puzzle cannot have an unique solution. (the number of solutions always has a factor |"free"symbol|! in it.
(so you can discard them directly if you are looking for sudoku's with an unique solution.)


Quote:

I tried this sudoku:
7.8...3.....2.1...5.........4.....263...8.......1...9..9.6....4....7.5...........

and 12854 rows remained after the reduction.


Strange, according to
http://www.setbb.com/phpbb/viewtopic.php?t=241&mforum=sudoku
(BTW a post from Ruud)
Quote:
Theory:

There are 46656 different configurations for any value in the grid.
With 1 position given, 5184 configurations are left.
(a chute is a line of 3 boxes)
With 2 positions given in 1 chute, 864 configurations are left.
With 2 positions given in 2 chutes, 576 configurations are left.
With 3 positions given in 1 chute, 288 are left.
With 3 positions given in 3 chutes, only 64 combinations are left.
Each given other value in a non-blocked position also slightly reduces the number of combinations.


In your example all symbols have at least 2 positions
so there can be at most 9 * 864 = 7776 rows left.
(only looking at "With 2 positions given in 1 chute, 864 configurations are left." , again a worst case scenario, so in practice it should be lower)

How do you come to 12854 rows?







PS
Can we start new treads as an introduction in SAT instances and a new tread as introduction in the "constraint subsets" technique


Both thanks for your comments,
Yesterday i had the idea that the time for normal DLX was past, Now I am not so sure anymore....
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sun Dec 11, 2005 3:00 am    Post subject: Reply with quote

I did include all those templates as rows in the matrix, which
just only hit symbols of one type. They needn't hit all the symbols
of that type.

That's useless, I changed that.
Now the matrix has typically 500 rows on hard sudokus,
but sometimes upto 7000.
Speed does compare well with the convential method,
but I generated the matrix with another program,
that time was excluded.

I'm wondering whether that method is competitive for
25*25 sudokus or QWHs ?
Probably not, but it's worth trying...

or maybe a combined method: generate one subproblem
for each template for the most common symbol
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 -> Programming 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