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   

Speedy VB6 backtracker solver (source coming later on)

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

Joined: 02 Aug 2005
Posts: 44
:

Items
PostPosted: Mon Aug 15, 2005 1:07 pm    Post subject: Speedy VB6 backtracker solver (source coming later on) Reply with quote

Due to contest at VBForums I can't give out the source yet, so I just have to give what I can: the compiled executable. I do tell some technical aspects though.

The logics:
- Naked single
- Hidden single
- Naked pair/triplet/quad aka naked subset (partial)

Each of these are very optimized and there isn't much if any speed gain to do. The same logics are used in backtracking with an additional validator (which is also partial). With partial I mean that the features are so much optimized for speed that the feature is not "perfect": for example, the code doesn't detect all naked triplets. The validator doesn't recognise if there are two same numbers in the same row/col/square. But it validates super fast, which is very important in backtracking when using these logics.



Program features:
- benchmark sudokus (various methods)
- count number of solutions for a sudoku (limits to finding one million solutions per puzzle, which takes about 20 seconds)
- supports five different file formats (the most common ones?)
- supports two different multisudoku/batch formats ("web friendly" and a custom one)
- convert sudokus to different formats (both single file formats and multisudoku/batch formats)
- convert batch format file to different formats



Download


Feel free to compare with your own programs Smile And I hope there is use for the conversion feature! It is still a work in progress, so please report any bugs etc. you find. The program is not meant for playing, it is more of a "technology preview".
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Tue Aug 16, 2005 3:37 am    Post subject: Reply with quote

hi Merri,

thanks for the program.
I will install it later. (or wait 10days for the source...)
Is there a commandline version, which just times
the sodokus in a given file ?

what's

- Naked single
- Hidden single
- Naked pair/triplet/quad aka naked subset (partial)

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

Joined: 02 Aug 2005
Posts: 44
:

Items
PostPosted: Tue Aug 16, 2005 7:11 am    Post subject: Reply with quote

I saw these names being used elsewhere.

Naked single: take out the known numbers, if there is only one number left in some cell after doing this, it must be that number.
Hidden single: if a number in a cell is the only possible number in a row/column/square, it must be that number.
Partial naked pair: if there are two cells with the same candidates in a row/column/square, clear the candidates in the other cells in that row/column/square.
Partial naked triplet and naked quad: the same as above for three cells and three candidates and four cells and four candidates.

And no, there is no command line options or command line version (it is on a bit of a harder side to make a command line application in Visual Basic).
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Tue Aug 16, 2005 7:45 am    Post subject: Reply with quote

Merri wrote:
I saw these names being used elsewhere.

Naked single: take out the known candidates, if there is only
one candidate left in some cell after doing this, it must be that candidate.

Hidden single: if a number in a cell is the only possible candidate in a row/column/square, it must be that number.

**square=block ?
** IMO we have 324 basic constraints : rc,rs,cs,bs
**r=row,c=column,b=block,s=symbol

Partial naked pair: if there are two cells with the same candidates in a row/column/square, clear the candidates in the other cells in that row/column/square.
Partial naked triplet and naked quad: the same as above for three cells and three candidates and four cells and four candidates.

And no, there is no command line options or command line version (it is on a bit of a harder side to make a command line application in Visual Basic).



have you tried to use more of these rules, if only few cells are filled
and fewer of these rules later, when many celld are filled ?

edit: now I replaced "numbers" by "candidates" in
some instances of Merry's description above


Last edited by dukuso on Sun Aug 28, 2005 6:30 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Merri

Joined: 02 Aug 2005
Posts: 44
:

Items
PostPosted: Tue Aug 16, 2005 8:28 am    Post subject: Reply with quote

Humm? How could I use them less or more? They are pretty much the core of the whole thing. Well... I could turn off hidden single and naked subset and it would still do the work, but it would be slower. The whole idea with the logics in backtracking mode is to turn off false answers and paths as fast as possible. These simple logic rules work the best when there are many cells filled and the whole speed of my program depend on how fast these can do their work.


Edit

Here is a more detailed description of how my algorithm works:

- look for naked singles until none can be found; try other logics:
-- look for hidden singles; return to naked singles if success
--- look for naked subset; return to naked singles if success
---- if still unsolved, exit
- if solved, return True; otherwise look for cell with least candidates
- start backtracking from the given cell; return True if success
-- make a copy of all optimization arrays
-- select one of the candidates of the cell, apply it to the cell
-- look for naked singles until none can be found; try Nishio
--- if Nishio succeeds, look for naked singles until none can be found
---- check for validity
----- look for hidden singles; return to naked singles if success
------ look for naked subset; return to naked singles if success
-- if valid but not solved, look for another cell with least candidates; backtrack
-- if valid and solved, return True and end all backtracking
-- if failed Nishio or if unvalid, reset all optimization arrays
-- unmark candidate value, prepare to try another one

This far I haven't found a faster algorithm, ie. all other programs I've tried have been slower.
Back to top
View user's profile Send private message
Merri

Joined: 02 Aug 2005
Posts: 44
:

Items
PostPosted: Sun Aug 28, 2005 12:36 am    Post subject: Reply with quote

Source code is now available over at VBForums. You can also find other solvers from there.

Won the contest Smile
Back to top
View user's profile Send private message
dukuso

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

Items
PostPosted: Sun Aug 28, 2005 7:06 am    Post subject: Reply with quote

I tried to make it more exact. I hope, I understood everything correctly.


Code:


(01) fill in the clues;
(02) make the candiates array, which lists for each cell
       the possible numbers which can go there;
(03) set filled=number of clues;
(04) look for naked singles;
(05) if success then place it; increase filled; goto (04);
(06) look for hidden singles;
(07) if success then place it; increase filled; goto (04);
(08) look for naked subset;
(09) if success then update the candidates list; goto (04);
(10) if solved return True;

(11) pick a cell with least candidates and make it cell(clues);
        [if there is a tie, maybe refine the search !]
(12) set pointer(clues) to the first candiate for that cell;
(13) if no more candidates are available for cell(clues) then goto (27);
(14) select the next possible candidate for cell(clues) addressed by
        pointer(clues);
(15) place it there;
(16) increase pointer(clues);
(17) look for naked singles;
(18) if success place it, increase filled; goto (17);
(19) perform Nishio testing ;
(20) if negative goto (27);
(21) look for hidden singles;
(22) if success then place it; increase filled; goto (17);
(23) look for naked subset;
(24) if success then update the candidates array; goto (17);
(25) if solved (filled=81) then return True;
(26) goto (11)
(27) (backtrack): wipe out the last number;
(28) restore the candidates array;
(29) decrease filled;
(30) if filled>clues goto (13);
(31) return false (invalid sudoku);

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