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   

Dancing Links pivoting heuristics

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

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Wed Sep 14, 2005 12:03 am    Post subject: Dancing Links pivoting heuristics Reply with quote

Hi all,

Other than the two mentioned in the Knuth dancing links paper, what other heuristics exist in choosing the best column on which to pivot?

Blessings,
Foster
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Wed Sep 14, 2005 3:20 am    Post subject: Re: Dancing Links pivoting heuristics Reply with quote

MontagFTB wrote:
Hi all,

Other than the two mentioned in the Knuth dancing links paper, what other heuristics exist in choosing the best column on which to pivot?

Blessings,
Foster


which two did he mention ? I only know the one where you choose
the column c with minumum number of intersecting rows rows(c).
But what happens on ties ?
That's some columns with 2 intersecting rows, 3 or more
are very unlikely.

I experimented a bit, but it's propably only interesting for 16*16 sudoku or larger, for 9*9 I didn't observe much difference.

First, sometimes the solver "hangs around" in some uninteresting
areas of searchspace.
So it helps if you randomize which column to choose on ties.
Better was to choose the first with 50% and the last with 50%.

I tried to count the number of rows in parallel columns,
(minimize rows(cols(rows(c))) )
but that somehow gave no improvent.


I found two other suggestions in the Regin-Gomes-paper

1) select the variable with the minimum domain size and then select
the value which occurs the fewest times in the domains of the variables
of the rows and columns of the selected variable

2) when two variables have the same size of domain we select the one for which the number of instantiated variables of the row and of the column is maximum.

This is for QWH, so no blocks-constraint.

"variable" is one of the 81 cells, I think. Domain size should be the number of candidates for that cell.
rows, columns are those of the sudoku, not the exact cover matrix.
instantiated variables should be the cells which are already
filled with symbols.

telle me how it goes, if you are trying any of these,
or sudoku-specific variations !



-Guenter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
angusj
Site Admin
Joined: 18 Jun 2005
Posts: 406
:

Items
PostPosted: Wed Sep 14, 2005 5:32 am    Post subject: Re: Dancing Links pivoting heuristics Reply with quote

dukuso wrote:
which two did he mention ? I only know the one where you choose the column c with minumum number of intersecting rows

I think the other is simply to choose the first (leftmost) uncovered column.
Back to top
View user's profile Send private message Visit poster's website
MontagFTB

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Wed Sep 14, 2005 6:20 am    Post subject: Re: Dancing Links pivoting heuristics Reply with quote

angusj wrote:
dukuso wrote:
which two did he mention ? I only know the one where you choose the column c with minumum number of intersecting rows

I think the other is simply to choose the first (leftmost) uncovered column.


(brainfart)
Those are the two. Would it make sense to limit the search range to the columns representing the cells (1..81), and choose the most constrained from those? I'm wondering if those aren't the ones usually chosen by default anyhow, as row/col/box colums will have at least as many as the most constrained cell column... limiting the search to those columns may speed up the most-constrained-search, but I doubt that's where the bottleneck of the algorithm lies at this point.
(/brainfart)

Blessings,
Foster
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Thu Sep 15, 2005 6:23 am    Post subject: Re: Dancing Links pivoting heuristics Reply with quote

MontagFTB wrote:


. Would it make sense to limit the search range to the columns representing the cells (1..81), and choose the most constrained from those? I'm wondering if those aren't the ones usually chosen by default anyhow, as row/col/box colums will have at least as many as the most constrained cell column... limiting the search to those columns may speed up the most-constrained-search, but I doubt that's where the bottleneck of the algorithm lies at this point.


I didn't yet obserce this,interesting. It's not the bottleneck,
maybe it was in my earlier version.
I just changed my program to search the first 81 columns only -
and it was 3 times slower.
I'm not sure I did it correctly, though
Back to top
View user's profile Send private message Send e-mail Visit poster's website
MontagFTB

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Thu Sep 15, 2005 6:38 am    Post subject: filling cells and speed improvements Reply with quote

Make sure the first 81 columns represent the first 81 cells in the puzzle: if they represent another part of the encoding you may be limiting yourself prematurely. I didn't end up limiting it to the first 81 columns, but I found if you break when you find a row with sz = 1 you get a speed boost. A size of 1 can be found often within the 81 cells (and hence one of the first 81 columns), and increasingly so as other cells are filled.

Blessings,
Foster
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Thu Sep 15, 2005 7:07 am    Post subject: Re: filling cells and speed improvements Reply with quote

MontagFTB wrote:
Make sure the first 81 columns represent the first 81 cells in the puzzle: if they represent another part of the encoding you may be limiting yourself prematurely. I didn't end up limiting it to the first 81 columns, but I found if you break when you find a row with sz = 1 you get a speed boost. A size of 1 can be found often within the 81 cells (and hence one of the first 81 columns), and increasingly so as other cells are filled.

Blessings,
Foster


yes, I checked it's the first 81 columns.
What you mean : row with sz=1 ? All rows have size 4, so is it
a column with size 1 ? Of course these are chosen immediately.
Doesn't matter in which order.
So, it's only interesting for columns of size 2.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
MontagFTB

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Thu Sep 15, 2005 3:50 pm    Post subject: Reply with quote

Sorry, yes, I meant columns with size 1.

According to knuth's algorithm in the dancing links paper the search for the most constrained column doesn't automatically stop at 1. Your implementation might; mine didn't. But it does now.

Hm... I wonder if we could find some way to determine if the column we have selected is the last column of size sz. Then we can increment some size tracker to sz+1, and the next time through the algorithm if we find a column with that size we can now break, as we know we have found the most constrained column. This couldn't be preprocessed as the sizes in the columns are constantly changing... I'll have to think about that one a bit. Thoughts?

Blessings,
Foster
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Thu Sep 15, 2005 4:47 pm    Post subject: Reply with quote

Foster, can you reformulate :

----------------------------------------
Would it make sense to limit the search range to the columns representing the cells (1..81), and choose the most constrained from those? I'm wondering if those aren't the ones usually chosen by default anyhow, as row/col/box colums will have at least as many as the most constrained cell column...
-------------------------------------

i.e. the last sentence ? Seems that I misunderstood something.
We have 324 columns, 81 for rc,81 for rs,81 for cs, 81 for bs

row,col,block,symbol

let the size of a column be the number of unmarked rows intersecting it

all rows have size 4 anyway, since whenever a column is deleted
all intersecting rows are deleted too.

Now we search for the column of minimum size.
This needn't be a column of type rc, if you meant this.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
MontagFTB

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Thu Sep 15, 2005 5:41 pm    Post subject: Reply with quote

dukuso wrote:
Foster, can you reformulate :

----------------------------------------
Would it make sense to limit the search range to the columns representing the cells (1..81), and choose the most constrained from those? I'm wondering if those aren't the ones usually chosen by default anyhow, as row/col/box colums will have at least as many as the most constrained cell column...
-------------------------------------

i.e. the last sentence ? Seems that I misunderstood something.
We have 324 columns, 81 for rc,81 for rs,81 for cs, 81 for bs

row,col,block,symbol

let the size of a column be the number of unmarked rows intersecting it

all rows have size 4 anyway, since whenever a column is deleted
all intersecting rows are deleted too.

Now we search for the column of minimum size.
This needn't be a column of type rc, if you meant this.


I'm not quite sure what you mean by 'symbol'... my four 81-sized groups are row, col, block, and cell. 'Cell' being one of the 81 squares in the puzzle. Your encoding may be different, it may not, I'm not sure. In any case I was wondering if the following would be true (according to the encoding scheme I'm using):

For any row, col, or block constraint there is a cell that is at least as constrained as it. Thus, you need merely search over the cell columns to find a (if not the) most constrained column. Since row, col, and block columns are a summation of cells, the most constrained column set will contain at least one cell.
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Thu Sep 15, 2005 6:12 pm    Post subject: Reply with quote

That inference is fairly trivial to disprove. It's easy to find partially solved boards where in a row, for example, each cell may have 2+ candidates but a particular digit only appears in one of them. And indeed, it's hardly possible to call something a constraint if it's always at least as loose as a different constraint.

In dancing links, finding 1 unmarked row in one of the first 81 columns only reveals a naked single, while the next 243 columns can reveal hidden singles. If you only test the first 1/4 of the columns, you'll basically be forcing your solver into making guesses in situations where the next move is already constrained.

Regarding the idea of breaking after finding the most constrained column: Well, it's possible, but you'd only want to do it in situations where that column had size 0 (i.e., the board is insoluble in its present state). When you find a size 2+ column you want to keep going to find the 1's. And if you find a 1, you'll want to use its information to keep finding 1's. Thus it makes sense--except possibly in a human-like solver algorithm--to loop through all columns to find 1's, not stopping or resetting along the way, and then to repeat the loop again until no more are found. Of course, in a standard DLX implementation you'd always move on to the next step and start the loop from scratch whenever a single was found.


Last edited by Lummox JR on Thu Sep 15, 2005 6:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Thu Sep 15, 2005 6:16 pm    Post subject: Reply with quote

symbol is one of the 9 digits which go into a cell.

rc: each cell contains exactly one of the 9 symbols
rs: each symbol occurs exactly once in each row
cs: each symbol occurs exactly once in each column
bs: each symbol occurs exactly once in each block

these are the 324 Columns (constraints)

rcs: symbol s goes into the cell in row r and column c

these are the 729 Rows (placements)

placement rcs meets constraints rc,rs,cs,bs
where b is the block defined by row r and column c


now, it can happen that r1s7 has size 1 but all
rc have size >1 :


Code:


.94...13.
.........
....76..2
.8..1....
.32......
...2.....
....5.4..
.....8..7
..63.4..8







what's a "column set" ?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
MontagFTB

Joined: 12 Sep 2005
Posts: 14
:

Items
PostPosted: Thu Sep 15, 2005 8:46 pm    Post subject: Reply with quote

dukuso wrote:
now, it can happen that r1s7 has size 1 but all rc have size >1 :

Yes, I see what you are saying here now. Back to the drawing board for me...
dukuso wrote:
what's a "column set" ?

By 'column set' I mean a subset of the columns that are related to one another in the common constraint they represent. In your case I would consider rc, rs, cs, and bs to be your four column sets, but there could be multiple ways to slice the columns in a matrix into column sets. It's a terminology I use that makes sense to me.

Blessings,
Foster
Back to top
View user's profile Send private message
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