.
Focused eliminations now work also for z-chains (typed or not). I just made this available on GitHub.
I plan to extend it progressively to all the generic chain rules (except t-whips, for technical reasons).
As of now, it works for the following rules (in both their speed and memory versions):
- Code: Select all
bivalue-chains (typed or not, blocked or not)
z-chains (typed or not)
oddagons
whips (untyped)
braids (untyped)
g-whips (untyped)
g-braids (untyped)
forcing-whips, forcing-braids, forcing-g-whips, forcing-g-braids (where the focus is not applied to eliminated or asserted candidates but to the bivalue starting points).
Remember that t-whips (typed or not) may not be active.
In my previous post, I took Mith's "Han Solo First" as an example:
http://forum.enjoysudoku.com/post300904.html#p300904:
- Code: Select all
..9......8....97...7..6..5..5..4..6.9....38....2.......6..5.17.2....84......1....
Now, let me make all this more precise.
Let me first recall that the semi-standard SudoRules solution is available here:
http://forum.enjoysudoku.com/han-shot-first-ser-7-1-t38695.html#p300710. Because Mith makes puzzles with many Subsets, it tries to make the best of it by finding as many Subsets as possible before trying other rules.
However, in order to somehow follow the fad for one-step solutions, I recently introduced in CSP-Rules the possibilities of searching for T-anti-backdoors and for focused eliminations.
Here, T can be any resolution theory with the confluence property. But in practice, it willl be BRT (i.e. Singles), W1 (i.e. Singles + intersections) or S (i.e. W1 + all Subsets). It could also be Sk (i.e.W1 + Subsets restricted to length k).
For this puzzle, I decided to choose T = W1, i.e. the following settings in the config file:
- Code: Select all
(bind ?*Whips[1]* TRUE)
(bind ?*Anti-Backdoors* TRUE)
W1-anti-backdoors are found by the command:
- Code: Select all
(find-sudoku-anti-backdoors "..9......8....97...7..6..5..5..4..6.9....38....2.......6..5.17.2....84......1....")
giving the following result:
- Code: Select all
13 W1-ANTI-BACKDOORS FOUND: (892 388 985 982 182 979 879 968 865 944 843 834 818)
This means that, if any of these candidates were eliminated, the solution could be found in W1, i.e. using only Singles and whips[1] (i.e. intersections).
If we want a one-step solution (modulo W1), we now only have to check which of these W1-anti-backdoors can be eliminated with some pattern in CSP-Rules.
Here again, we can choose what type of elimination we are looking for. And the new possibilities for focused eliminations enlarge the choices.
How to do?Now that we have found all the W1-anti-backdoors, we launch a new instance of CLIPS and we select in the config file the rules we want to use. Whatever we choose, the command for checking if a candidate can be eliminated by them will be the same: first init the puzzle, then try-to-eliminate the candidate (say xxx)
- Code: Select all
(init-sudoku-string "..9......8....97...7..6..5..5..4..6.9....38....2.......6..5.17.2....84......1....")
(try-to-eliminate-candidates xxx)
We shall do this for the 13 W1-anti-backdoors and for 3 choices of rules:
1) Let's first assume we allow only bivalue-chains. Among the above 13 candidates, we find that 7 lead to a single step solution (modulo W1):
- Code: Select all
892: biv-chain[4]: c8n8{r9 r1} - c5n8{r1 r6} - c5n9{r6 r8} - b7n9{r8c2 r9c2} ==> r9c2 ≠ 8, r9c8 ≠ 9
879: biv-chain[4]: r3n8{c9 c4} - c5n8{r1 r6} - c5n9{r6 r8} - r7n9{c4 c9} ==> r7c9 ≠ 8, r3c9 ≠ 9
865: biv-chain[3]: c2n8{r6 r9} - b7n9{r9c2 r8c2} - c5n9{r8 r6} ==> r6c5 ≠ 8
944: biv-chain[3]: r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} ==> r4c4 ≠ 9
843: biv-chain[6]: r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} - c8n8{r1 r9} - c2n8{r9 r6} ==> r4c3 ≠ 8, r9c2 ≠ 8
834: biv-chain[5]: r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} ==> r3c4 ≠ 8, r6c5 ≠ 8
818: biv-chain[6]: r3n8{c9 c4} - r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} ==> r1c8 ≠ 8, r1c9 ≠ 8, r3c4 ≠ 8
2) Let's now assume we allow only z-chains (and the particular case of bivalue-chains). Among the above 13 candidates, we find that 10 lead to a single step solution (modulo W1):
- Code: Select all
892: biv-chain[4]: c8n8{r9 r1} - c5n8{r1 r6} - c5n9{r6 r8} - b7n9{r8c2 r9c2} ==> r9c2 ≠ 8
985: z-chain[6]: c2n9{r8 r9} - c2n8{r9 r6} - r4n8{c3 c4} - c4n9{r4 r6} - c8n9{r6 r9} - r7n9{c9 .} ==> r8c5 ≠ 9
979: z-chain[4]: r7n8{c9 c3} - r4n8{c3 c4} - r4n9{c4 c7} - r3n9{c7 .} ==> r7c9 ≠ 9
879: biv-chain[4]: r3n8{c9 c4} - c5n8{r1 r6} - c5n9{r6 r8} - r7n9{c4 c9} ==> r7c9 ≠ 8
968: z-chain[5]: c5n9{r6 r8} - c2n9{r8 r9} - c2n8{r9 r6} - r4n8{c3 c4} - r4n9{c4 .} ==> r6c8 ≠ 9
865: biv-chain[3]: c2n8{r6 r9} - b7n9{r9c2 r8c2} - c5n9{r8 r6} ==> r6c5 ≠ 8
944: biv-chain[3]: r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} ==> r4c4 ≠ 9
843: biv-chain[6]: r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} - c8n8{r1 r9} - c2n8{r9 r6} ==> r4c3 ≠ 8
834: biv-chain[5]: r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} ==> r3c4 ≠ 8
818: biv-chain[6]: r3n8{c9 c4} - r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} - c5n9{r8 r6} - c5n8{r6 r1} ==> r1c8 ≠ 8
Notice that the previous chains are unchanged, but they could have been. This will be shown by the third case.
3) Let's now assume we allow whips (plus the special cases of z-chains and bivalue-chains). Among the above 13 candidates, we find that 11 lead to a single step solution (modulo W1), i;e. only one more than without whips. But we can also see that some of the solutions which whips are shorter than the solutions with bivalue-chains or z-chains:
- Code: Select all
892: biv-chain[4]: c8n8{r9 r1} - c5n8{r1 r6} - c5n9{r6 r8} - b7n9{r8c2 r9c2} ==> r9c2 ≠ 8, r9c8 ≠ 9
985: whip[5]: r7n9{c4 c9} - c8n9{r9 r6} - r4n9{c9 c4} - r4n8{c4 c3} - r7n8{c3 .} ==> r8c5 ≠ 9
982: whip[4]: c5n9{r8 r6} - c8n9{r6 r9} - c8n8{r9 r1} - c5n8{r1 .} ==> r8c2 ≠ 9
979: z-chain[4]: r7n8{c9 c3} - r4n8{c3 c4} - r4n9{c4 c7} - r3n9{c7 .} ==> r7c9 ≠ 9
879: biv-chain[4]: r3n8{c9 c4} - c5n8{r1 r6} - c5n9{r6 r8} - r7n9{c4 c9} ==> r7c9 ≠ 8, r3c9 ≠ 9
968: whip[4]: r4n9{c9 c4} - r7n9{c4 c9} - r7n8{c9 c3} - r4n8{c3 .} ==> r6c8 ≠ 9
865: biv-chain[3]: c2n8{r6 r9} - b7n9{r9c2 r8c2} - c5n9{r8 r6} ==> r6c5 ≠ 8
944: biv-chain[3]: r4n8{c4 c3} - r7n8{c3 c9} - r7n9{c9 c4} ==> r4c4 ≠ 9
843: whip[5]: c2n8{r6 r9} - c8n8{r9 r1} - c5n8{r1 r6} - c5n9{r6 r8} - c2n9{r8 .} ==> r4c3 ≠ 8
834: whip[4]: c5n8{r1 r6} - c2n8{r6 r9} - c2n9{r9 r8} - c5n9{r8 .} ==> r3c4 ≠ 8
818: whip[4]: c5n8{r1 r6} - c2n8{r6 r9} - c2n9{r9 r8} - c5n9{r8 .} ==> r1c8 ≠ 8
Note that for chains that have a blocked version (here bivalue-chains), not only the candidates focused on are eliminated, but also the other targets of the SAME chain. This is a deliberate choice. If you want to eliminate only the candidates on focus, choose the non-blocked version of these rules.
A final remark: with the focused elimination, the simplest-first strategy still applies.