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   

Forcing Chains implementation
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku
View previous topic :: View next topic  
Author Message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Fri Nov 04, 2005 2:10 am    Post subject: Reply with quote

Well, I've finally figured out what's missing in my tables implementation.

In building the implication tables, I kept the focus on the positive implications of each assertion, using the negative implications only as 'links' to the next positive implication.

This prevented me from using these to perform the double-negative verasity test. That's probably what keeps me from solving these last 4 puzzles.

Uniqueness tests 1-4 are implemented and fully operational.

I'll let you know when I've cracked these last 4.

Ruud.
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: Sat Nov 05, 2005 8:47 pm    Post subject: Reply with quote

So, to finish off this thread in terms of Sudoku Assistant, I've now got the forward and reverse logic in there that you can demonstate, and I can verify that they are, indeed, identical. Step for step, word for word identical.

Ruud, you should be able to get this implemented. If you aren't solving those last three by now, fire the puzzle into http://www.stolaf.edu/people/hansonr/sudoku, click on Solve, and then go back to see the steps. You should be able to see just where it does something that you are not doing, and that should provide your solution. It MUST be something subtle in your algorithm -- not checking for FFF? in a CELL, for example. (Row, column, block on a specific value, but also FFF? for the N values in a given cell. Maybe?)

In my case, the breakthrough was when I abandoned a piece that I THOUGHT was working but was actually introducing errors and making the solutions impossible.

Good luck. Shouldn't be long now....

Bob
_________________
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
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Mon Nov 07, 2005 8:30 pm    Post subject: Reply with quote

The last glitches in the tabling code have been fixed now.

Finally, "agressive" propagation of implications does the trick. Top870 now completely solved.

However, it works now so fine, that it does not need any verity/verasity search. Every puzzle is now solved with conflict detection only.

It would be nice to see the verity/verasity seach kick in once and a while. The routine is now not only based on T&E, it actually behaves like T&E. Horrible!

I'd like to have it collect all deductions that can be made from the tables, and then report the deduction that is either the most efficient, or has the shortest chains. This is much too slow.

Any ideas from the forum?

Ruud.
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 8:56 pm    Post subject: Reply with quote

Congratulations, Ruud! WE HAVE CONVERGENCE! Very Happy

That's really all there is to it, isn't it? How marvelous!

So, do we call this "trial and error"?

I'm assuming you mean ?FFFF --> TFFFF in terms of "agressive" propagation. Really just "that last little missing detail" I think.

Hmm. Collect all. I implemented this in Sudoku Assistant just this morning in terms of looking for magic cells. I figured that people might want all magic cells, not just the first found, so there I needed to go through all the possibilities. Yes, VERY slow. I think this is probably what xyzzy was thinking about in terms of a catalog/hypothesis program working so slowly.

I would say that a compromise position would be to deliver a "first-found" logic trail, the way Sudoku Assistant does, but then, if the user desires, and can wait the extra few seconds, allow the option of delivering the "best" or "shortest". This user is looking for something special, I think, and it is reasonable to ask them to wait.

But even with that, at least with the Medusa chains, there isn't really one "unique" cycle that is developed -- it's a grand synthesis of all the implications. So it's really not clear to me that there IS a "simplest" way. Finding the "shortest cycle" is a good challenge for some mathematician, I think. Maybe there's a "shortest path" from "a" to "z" here. Could be an interesting challenge.

I think the thing to realize is that we are talking about the REALLY difficult puzzles here. How many actual puzzles people really solve would be expected to be at this level? I suspect a very small percentage. All the "reasonable" ones fall far earlier, mostly with strong chain/weak link incompatibility issues of the sort outlined at Glenn Fowler's site.

One question: In your implementation, are you doing subset elimination, box row/column exclusion, etc. FIRST, or are you using only this logical chain analysis and simple cross-hatch scanning?

Again, congratulations,
_________________
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
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

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

Bob wrote:
I'm assuming you mean ?FFFF --> TFFFF in terms of "agressive" propagation. Really just "that last little missing detail" I think.

Yes, that was the only thing missing.
Quote:
This user is looking for something special, I think, and it is reasonable to ask them to wait.

Not really. You'd have to change to a breath-first mode at all depth levels, if you want to find the shortest implication chains. The recursive method I use now does depth-first, which is faster (and easier) to implement. However, I was thinking of reconnecting the chains when a shorter route is found later on in the search. That can easily be done.
Quote:
I think the thing to realize is that we are talking about the REALLY difficult puzzles here. How many actual puzzles people really solve would be expected to be at this level?

I think we're already aiming at this audience with our programs. Most solvers would rate the puzzles we're handling here "unsolvable". In my user-interface, I've added the option for the user to "try" a candidate and see how the implications propagate with green (T) and red (F) colored candidates. This is a nice tool. It took me some headaches to let it work with differenct sources, the "user" marks and the solver's own remaining candidates, but it allows me to see very quickly which candidates can be eliminated.
Quote:
One question: In your implementation, are you doing subset elimination, box row/column exclusion, etc. FIRST, or are you using only this logical chain analysis and simple cross-hatch scanning?

My solver applies the techniques in the following order, where each technique except singles can be "turned off" by a user option:

1. Singles
2. Line-Box Interactions
3. Subsets (naked and hidden)
4. Remote pairs
5. X-Wing, swordfish, etc.
6. XY-Wing, XYZ-Wing
7. Multi-coloring
8. Single-digit Templates
9. Uniqueness test 1, 2, 3, and 4.
10. Tables (with aggressive search)
11. Full backtracking solver, one of the following:
- a. Dancing Links (the best)
- b. Multi-digit Templates
- c. Recursive row-by-row solver (like Sherlocking, but compares any number of rows)
- d. Raw T&E. No tables, just save, try and restore when failed. Slow but effective.

The solver always resets to 1 when candidates are eliminated, thus trying to find the path of least resistance.

Quote:
I implemented this in Sudoku Assistant just this morning in terms of looking for magic cells

I'm aready considering changing this piece of the code. There are other ways to find the shortest solving path, and magic cells play a role, but you do not need to present them to the user.

Consider this: Find a magic cell, then find the shortest way to set this candidate to TRUE, by finding proof to eliminate either all other candidates for that cell, or all competing cells in the same row, column or box. The shortest of those proofs are then reported and the puzzle will be solved without further tabling. To go all the way, check all magic cells and find the shortest path between them. That would be slow, but it would reduce the long chains of proof to the minimum, making your solver look much smarter.

Ruud.
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 10:33 pm    Post subject: Reply with quote

what fun!
_________________
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
Bob Hanson

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

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

Quote:
1. Singles
2. Line-Box Interactions
3. Subsets (naked and hidden)
4. Remote pairs
5. X-Wing, swordfish, etc.


3 and 5 are the "same thing", but I like to separate out the
subset stuff from the X-Wing anyway as well.

2 falls in Medusa in the weak link check. (Remote pairs are sets of short strong chains with weak or strong links. The standard check:

Code:

 
  69*===6*9
   \\    \ \
   |69====6 9*
   |      | |
  (w)     | |
   |      6 |
   9---(w)--9   

(this from http://www.scanraid.com/RemotePairs.htm)

Setting the lower right 9 FALSE we have the chain:

(lower right) 9---9*---9-6*---6-9*
allows for the elimination of that lower left 9, because we have
an even number of nodes in the overall chain.

The pairing is kind of cool, because it allows transmission of the
strongness regardless of what else is in the puzzle. (Either the
6 or the 9 must be true, so either one transmitts the connection.

My guess is that there are all sorts of things like this waiting to be discovered.

Quote:

6. XY-Wing, XYZ-Wing
7. Multi-coloring
8. Single-digit Templates


Ah, OK! These 6-8, along with 2, are subsets of the Medusa strong chain/weak link thing. In constructing the chains and identifying the weak
nodes and links, all these plus many more would be identified.

Quote:
9. Uniqueness test 1, 2, 3, and 4.


Unnecessary -- but cool! Very Happy (Limits one to "valid" Sudoku, of course.

So what does your solver do with that example of a nonunique puzzle:

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

?


Quote:
10. Tables (with aggressive search)

This should be the end. All solved -- or not unique.

Right?

Quote:
11. Full backtracking solver, one of the following:
- a. Dancing Links (the best)
- b. Multi-digit Templates
- c. Recursive row-by-row solver (like Sherlocking, but compares any number of rows)
- d. Raw T&E. No tables, just save, try and restore when failed. Slow but effective.

None of these should be necessary after 10. But if I understand
correctly, you can turn various methods on and off. Is that right?
_________________
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
rubylips

Joined: 07 Apr 2005
Posts: 62
:
Location: London

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

Ruud wrote:
Bob wrote:
I'm assuming you mean ?FFFF --> TFFFF in terms of "agressive" propagation. Really just "that last little missing detail" I think.

Yes, that was the only thing missing.

Please explain what ?FFFF --> TFFFF means. Thanks.
_________________
Java 5.0 Solver/Composer Applet: http://act365.com/sudoku
GPL Source Code: http://sf.net/projects/sudoku
Back to top
View user's profile Send private message Visit poster's website
rubylips

Joined: 07 Apr 2005
Posts: 62
:
Location: London

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

Ruud wrote:
I'd like to have it collect all deductions that can be made from the tables, and then report the deduction that is either the most efficient, or has the shortest chains.

Why not print the forcing chains suggested by our solvers for some difficult puzzles to see whose is shortest?
_________________
Java 5.0 Solver/Composer Applet: http://act365.com/sudoku
GPL Source Code: http://sf.net/projects/sudoku
Back to top
View user's profile Send private message Visit poster's website
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Tue Nov 08, 2005 12:07 am    Post subject: Reply with quote

Bob wrote:
So what does your solver do with that example of a nonunique puzzle

With 11a enabled, it says: "The puzzle has 25 solutions"
Quote:
This should be the end. All solved -- or not unique.

Correctamundo.
Quote:
None of these should be necessary after 10. But if I understand
correctly, you can turn various methods on and off. Is that right?

True. It is possible to disable the backtracking solver alltogether. When an invalid puzzle is presented, the backtracking solver is the only one that can determine how many solutions there are. The other methods just say: "The puzzle cannot be solved"

rubylips wrote:
Please explain what ?FFFF --> TFFFF means.

It means that, while propagating implications, when N-1 candidates for a cell or a digit in a row/column/box are set to FALSE, the last remaining candidate can be set to TRUE, from where the implication tree can be further expanded.
Quote:
Why not print the forcing chains suggested by our solvers for some difficult puzzles to see whose is shortest?

I'd like my solver to determine the shortest path before it prints anything. Because of the way I've constructed the solver - after each elimination it goes back to checking singles - I must choose only one elimination. To shorten the overall solving path, it must select both the most effective (minimizing the number of times tabling is revisited) and the shortest chains, thus producing the most effective solving log, from which my program picks the "hints".
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: Tue Nov 08, 2005 12:06 pm    Post subject: Reply with quote

shortest path: I think there are two issues here.

1) shortest path for a specific elimination

--should not be too difficult; Medusa chains provide the complete set of
all possible "routes" from one end to the other leading to a specific
elimination. So a quick run though the possibilities should give the
shortest route. I think this would be very very quick.

2) shortest path for ANY possible elimination

--much slower -- must do (1) for each possible elimination each time.

One could provide (1) or (2) as an option and let the user decide which is more important.
_________________
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
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Tue Nov 08, 2005 1:24 pm    Post subject: Reply with quote

There are actually 3 issues here:

1. Shortest path for a specific elimination
2. Shortest path for any possible elimination (at a given state)
3. Shortest path to the complete solution

If we want these techniques to be more than just 'T&E renamed', we should exploit the fact that we've gathered so much information about the state of the puzzle.

1. Is easy indeed.

2. Is more difficult, but doable. My program first scans for errors, but it should also scan for verities in the remaining candidates. This would be a lot more complicated than comparing errors to errors and verities to verities.

3. Is the real challenge. Not only would we have to compare the path length, but sometimes you would sacrifice a shorter chain in favor of a longer chain that gives you an easier path to the final solution. In some of the more difficult puzzles, the solver needs to revisit the tables 7 times or more. It would show true intelligence if it can find a single chain that may be a little longer, but allows solving the remainder of the puzzle with singles only.
Back to top
View user's profile Send private message Visit poster's website
xyzzy

Joined: 24 Aug 2005
Posts: 80
:

Items
PostPosted: Fri Nov 11, 2005 12:05 am    Post subject: Reply with quote

It's not that hard to do this. Check out some AI text on finding shortest paths, this is an old problem. What you want to do is use an A* search. I already wrote this kind of search to see if it was faster than a depth first search (it's not).
Back to top
View user's profile Send private message Visit poster's website
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Fri Nov 11, 2005 5:21 pm    Post subject: Reply with quote

I'm not sure I really want to know what an A* search is....

My tabling/forced chains implementation has now entered a new stage. I've rewritten the code in such a way that the DLX nodes are dynamically updated by the other solving methods, when they eliminate candidates, force or pin cells, etc.

This now allows me to use the DLX nodes to do the tabling. Because this piece of code is so extremely fast, it can build the tables much faster than the method I've used so far. (I think)

Has anyone been on this path? If so, what are the pitfalls that I can expect? Also: I'd like to visualise the DLX process, so I can follow it's progress. Any ideas?

Ruud.
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: Fri Nov 11, 2005 5:48 pm    Post subject: Reply with quote

can you describe in SIMPLE terms the Dancing Links process?
_________________
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
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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