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   

Fishy Cycles
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
Doug

Joined: 28 May 2005
Posts: 42
:

Items
PostPosted: Thu Jun 02, 2005 5:33 am    Post subject: Fishy Cycles Reply with quote

MadOverlord-

I have looked quickly through all of AMcK's posts for an explanation. I didn't find one. But looking at his examples I think I can deduce the algorithm easily. (I need to copy down a complete example and work through it to figure it out completely.) What I have been able to figure out so far is that conjugate pairs are pairs of cells in a house that are the only ones that can contain a given digit. So if one cell contains the digit, then the other cannot and the digit must be in one of them.

Now then, his colors represent variables with potential truth values for the presence of the given digit in a cell. In each application of the algorithm he consideres only a single digit. He then finds all pairs in the graph using as few variables (colors) as possible, by first going through rows, then columns, and finally boxes.

At the row stage, all conjugate pairs get the different variables (colors).

At the column stage, some new colors may be required as well as old colors may be re-used.

Finally at the box stage, re-colorings are made and a matrix results with colors in certain cells. Finally, the digit which is being used is eliminated from other cells.

I haven't worked out the details of his recoloring rule, but I have an idea about the elimination rule. It is something like: "When a row and a column each have two variables with different values, then the cell at their intersection can have that color removed from it." (At least that seems to me to be approximately correct. I am missing part of the rule for elimination for sure, but it's certainly along those lines.)

Later I'll work out all the details of his algorithm and look for extensions of it.
_________________
Doug Bowman
www.flickr.com/photos/bistrosavage
Back to top
View user's profile Send private message Send e-mail
MadOverlord

Joined: 01 Jun 2005
Posts: 80
:
Location: Wilmington, NC, USA

Items
PostPosted: Thu Jun 02, 2005 12:48 pm    Post subject: Re: Fishy Cycles Reply with quote

Doug wrote:
MadOverlord


Doug, we know each other well enough now that you can call me by my first name, Trebor (as in, "Trebor the Mad Overlord"). Find out why at http://www.madoverlord.com/


Doug wrote:
What I have been able to figure out so far is that conjugate pairs are pairs of cells in a house that are the only ones that can contain a given digit.


That's a locked pair.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Doug

Joined: 28 May 2005
Posts: 42
:

Items
PostPosted: Thu Jun 02, 2005 1:05 pm    Post subject: Fishy Cycles Reply with quote

Trebor--

Perhaps I'm coufused.

My understanding:

To you a locked pair would be possibility sets {1,2} and {1,2} in a row with no other 1's or 2's in the row.

To him a conjugate pair would be {1,2} and {1,3,7} in a row with no other 1's in the row.

The difference being that his concept is about a single value having two exclusive possible locations in a house. In locked pairs, there are two values with the same two exclusive locations in a house.

OK. Really time for bed.

Must not check sudoku forum any more before pillow. MUST NOT>

Wizardry! Really?

Doug <-- Thinks of spiral tracks.
_________________
Doug Bowman
www.flickr.com/photos/bistrosavage
Back to top
View user's profile Send private message Send e-mail
MadOverlord

Joined: 01 Jun 2005
Posts: 80
:
Location: Wilmington, NC, USA

Items
PostPosted: Thu Jun 02, 2005 3:14 pm    Post subject: Reply with quote

No, it's me that is confused. You're right.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Doug

Joined: 28 May 2005
Posts: 42
:

Items
PostPosted: Fri Jun 03, 2005 5:35 am    Post subject: Fishy Cycles Reply with quote

I believe AMcK's algorithm is likely subsumed by Fishy Cycles, but I haven't worked out a proof of this yet.

Edit: Thinking about it a bit more, it seems quite possible that they, in fact, give equivalent information.

Edit2: I'm quite sure now that they are equivalent! The coloring rules applied to the matrix will give conjugate labels to two cells in the edge houses in Fishy Cycles. Thus it will eliminate the other entries for n in those houses, that is, from the edges in the graph. Also, the coloring algorithm is, I think, easier to code and apply. I think its preferable to Fishy Cycles. It's possible my reasoning is missing something on their equivalence, but I don't see it.

Anyway, here is his coloring algorithm. I will be using ordered pairs to represent the colors. The colors should be thought of as logical variables which can take the values T or F.

Definition. A conjugate pair is a pair of cells in a house which are the only possible locations in the permissions matrix for a particular value.

The algorithm works on a particular value at a time, say n.

1) All conjugate pairs in the rows are found. These are labeled in the following way. Let m=1. The first cell is assigned an ordered pair (m,0) and the second is given the label (m,1). They must of necessity have different truth values. (I call these conjugate labels.) m is then incremented when new pairs are found on new rows.

2) Now conjugate pairs are searched for in columns. Each conjugate pair found in a column is colored according to:

a. If neither cell in the pair already has a label, they are given next label pair not used.

b. If one of the cells is already labeled, but the other is not, then the unlabeled cell gets the conjugate label to the first one.

c. If both cells already have labels, say (p,a) and (q,b), then we re-assign the labels on the larger row in accordance with the forced conjugacy of the column pair. All cells labeled with those labels (of the larger row) in the graph are also adjusted. Example: Say in a column we find a conjugate pair with lables (3,1) and (5,0). Then all cells in the graph with the labels (5,0) are changed to (3,0) and all cells with the label (5,1) are given the label (3,1).

3) Conjugate pairs are searched for in the blocks. Again the labels are adjusted, if necessary, to preserve conjugate consistancy.

4) Finally, all houses which initially did not have conjugate pairs are searched. If two cells now have conjugate labels, then all non-labeled cells may have n removed from their permissions matrix.

Hope I haven't missed anything.
_________________
Doug Bowman
www.flickr.com/photos/bistrosavage


Last edited by Doug on Fri Jul 01, 2005 10:38 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
MadOverlord

Joined: 01 Jun 2005
Posts: 80
:
Location: Wilmington, NC, USA

Items
PostPosted: Fri Jun 03, 2005 1:24 pm    Post subject: Re: Fishy Cycles Reply with quote

Doug wrote:
I'm quite sure now that they are equivalent!


Good, less work for me!

Personally, I think Fishy Cycles is easier for a human to execute; I'd do it by circling the potential vertex groups, coloring the link squares, and using coins to mark the link squares I've used as I explore for a loop.

But that's just me.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Doug

Joined: 28 May 2005
Posts: 42
:

Items
PostPosted: Fri Jun 03, 2005 1:31 pm    Post subject: Fishy Cycles Reply with quote

Yes, I agree that FC is easier by hand. And I'm still not sure the algorithms are equivalent. If coloring is easy to code, then running a bunch of examples using only those two algorithms and comparing the eliminations should give better confidence.

Good morning!
_________________
Doug Bowman
www.flickr.com/photos/bistrosavage
Back to top
View user's profile Send private message Send e-mail
Gennadog

Joined: 03 Jun 2005
Posts: 5
:

Items
PostPosted: Sat Jun 18, 2005 1:59 am    Post subject: How to select from multiple options Reply with quote

I've been looking into implimenting this in my own program and I've come across a situation that I'm not sure how to make progress.

The original grid is:

Code:

  .2.|...|...
  ...|6..|..3
  .74|.8.|...
  -----------
  ...|..3|..2
  .8.|.4.|.1.
  6..|5..|...
  -----------
  ...|.1.|78.
  5..|..9|...
  ...|...|.4.


which can be 'solved' by the simpler techniques to become

Code:

  .26|..7|..8
  895|62.|.73
  .74|.8.|...
  -----------
  457|193|862
  983|246|517
  612|578|..4
  -----------
  2.9|.1.|78.
  548|7.9|...
  7.1|8.2|.4.


Looking at the possible 'fishy cycles', I found one involving the possible placement of the 9's as follows: (I've labelled the individual cells to the right for later discussion
Code:

  ...|9..|99.      ...|a..|bc.
  ...|...|...      ...|...|...
  ...|9..|999      ...|d..|efg
  -----------      -----------
  ...|...|...      ...|...|...
  ...|...|...      ...|...|...
  ...|...|99.      ...|...|hi.
  -----------      -----------
  ...|...|...      ...|...|...
  ...|...|...      ...|...|...
  ...|...|9.9      ...|...|j.k


If I choose (by an initial lucky - human - guess) to link the following pairs, I get a cycle that works:

ab, be, ef, fi, ih, hj, jk, kg, gd, da

This leaves 'c' out of the cycle, and therefore lets me clear the 9 from that cell (this leaves a single possibility of 5 in that cell which then leads on to the 'simple' solution for the whole puzzle).

However I have also tried to find other paths, such as

ad, dg, gk, kj, jb, bc, cf, fe, eh, hi

but that leaves me with no way to link the 'i' back to the 'a' cell. Therefore this must be an 'invalid' cycle.

My question is: given the set of '9's above, how can I use the algorithm to choose the appropriate verticies and edges for the graph. I think my problem lies in the top-right box (box 3) in selecting which cells form "pairs" and I don't think that I understand the basics of the vertex selection step in the algorithm to know how to do this correctly.

Is this something to do with the fact to R1 and C8 have an odd number of cells of interest, and that the cell I have labelled 'c' happens to be on the intersection of these?

Help please

Thanks

Susan
Back to top
View user's profile Send private message
Doug

Joined: 28 May 2005
Posts: 42
:

Items
PostPosted: Sat Jun 18, 2005 12:45 pm    Post subject: Reply with quote

The vertices are rows, columns, or blocks containing exactly two possibilities (containing two 9's in your case). In your example only possible vertices are: c4, c9, r6, r9, b2, b6, and b9.

Unfortunately, the conditions for the edges do not give any cycles here. See previous posts for definitions and examples.

BTW I believe that the AMcK's coloring algorithm described above is equivalent to Fishy Cycles. It is also easier to code, I believe. It is described in some detail in posts above.
_________________
Doug Bowman
www.flickr.com/photos/bistrosavage
Back to top
View user's profile Send private message Send e-mail
jiffle

Joined: 21 Jun 2005
Posts: 3
:

Items
PostPosted: Tue Jun 21, 2005 4:50 pm    Post subject: Re: Fishy Cycles Reply with quote

Quote:

"Simple locked set"

If a set of N squares in a group all have the same set of N possibilities, then we can eliminate those possibilities from the other squares in the group.

Example: if there are 3 squares with possibilities 1, 2 and 3, then one must be 1, one 2 and the other 3; so none of the other 6 squares in the group can be 1, 2 or 3.

A set of two squares with the same two possibilities is referred to as a "locked pair"; a set of three squares with the same three possibilities would be a "locked triplet", and so on.

"Comprehensive Locked Set"

For each row, column and block, look for a set of N squares that have exactly N possible solutions. Then those solutions must be in the N squares, and can be removed from the other squares of the group.

Since there are many possible sets of N squares, this one is computationally intensive.

This test is a more general version of Simple Locked Set.


Sorry Madoverlord, could you explain the difference please?
Back to top
View user's profile Send private message
MadOverlord

Joined: 01 Jun 2005
Posts: 80
:
Location: Wilmington, NC, USA

Items
PostPosted: Tue Jun 21, 2005 7:02 pm    Post subject: Re: Fishy Cycles Reply with quote

In a simple locked set the possibilities have to be the same, ie:

12 12 is a locked pair

123 123 123 is a locked triple

But in a comprehensive locked set things can be more complicated, ie:

12 23 13 is a locked triple.

A locked set of size N is N squares who have, between them, a total of N possibilities.
Back to top
View user's profile Send private message Visit poster's website AIM Address
gaby

Joined: 02 Jul 2005
Posts: 120
:

Items
PostPosted: Fri Jul 29, 2005 10:12 pm    Post subject: Reply with quote

Nice. Well, I've finally got round to properly thinking about fishy cycles and reading the thread through. It's not nearly as complicated as I thought it would be once I though about edges and vertices a bit better. Here's my take on fishy cycles, I'd appreciate thoughts on it:

1. For each number 1 to 9, n, do:

1.1. Create our vertex set {v} by searching each row, column
and block where n only appears twice as a candidate. Each
vertex will be a pair of coordinates, one pair for each cell
that holds n.

1.2. For every possible pair of vertices in {v}, {v1} and {v2},
check for a row, column or block that holds one number from
{v1} and one number from {v2}, but does not contain all the
numbers in both vertices.

Example: There are clearly four numbers that we need to check
the positions for; {v1:1}, {v1:2}, {v2:1} and {v2:2}. So we
should check for a row/column/block that contains any of
these sets:

a. {v1:1} and {v2:1}
b. {v1:1} and {v2:2}
c. {v1:2} and {v2:1}
d. {v1:2} and {v2:2}

However, if a row/col/block contains all four numbers in the
pair of vertices (sets a and d, or b and c) then we cannot use this
row/col/block in our graph.

If we find a row/column/block that fits this criteria, then
we can draw an edge between the two vertices, and we name the
edge by the row, column or block that we found.

Keep going until we've tried every possible combination of vertices.

1.3. Look through the graph for all cycles {c}. A cycle is a
path that you would take from vertex to vertex, along the
edges of the graph, finishing up where you started from, and
only going through each vertex once. There may be quite a few
of these cycles, you'll need to thoroughly check the graph.

1.4. For each cycle in {c}, do:

1.4.1. Being that each edge in our cycle represents a given
row, column or block, we can now remove the number n from
all the other cells in that row/col/block that aren't
in either {v1} or {v2} (from each end of the edge).

Gaby
_________________
Free daily sudoku - Online puzzle database
http://vanhegan.net/sudoku/
Back to top
View user's profile Send private message Visit poster's website
droid42

Joined: 29 Jul 2005
Posts: 20
:

Items
PostPosted: Fri Jul 29, 2005 11:22 pm    Post subject: Reply with quote

Re: Fishy algorithm...

The explanation seems awfully involved for what can easily be implemented with simple bitmaps (representing the "possibles" in a sector) and trivial bitwise operations.

My own solver has a single 200-line method that unifies the logic for detecting X-Wing, Swordfish, Swordfish4/5/6, solitary n-tuples, hidden n-tuples etc. The logic to detect them all is surprisingly similar.

Or am I missing something? (honest question, not a sarcastic one)...

Ian.

P.S. This is my first post on here after lurking for a while so "Hi" Smile
Back to top
View user's profile Send private message
gaby

Joined: 02 Jul 2005
Posts: 120
:

Items
PostPosted: Sat Jul 30, 2005 2:05 pm    Post subject: Reply with quote

I'd very much like to see that code. Would it be possible to send me a copy?
_________________
Free daily sudoku - Online puzzle database
http://vanhegan.net/sudoku/
Back to top
View user's profile Send private message Visit poster's website
AMcK

Joined: 07 Apr 2005
Posts: 89
:
Location: Cambridge

Items
PostPosted: Sun Jul 31, 2005 1:54 pm    Post subject: Reply with quote

The new supercolouring algorithm seems to solve this cleanly - without any need for a final execution of the standard 3 rules.
Here's the staring point
Code:
12   12   8    4    6    3    7    5    9   
349  49   7    8    2    5    34   1    6   
34   6    5    1    7    9    8    34   2   
8    5    1    6    349  2    349  7    34   
49   3    2    59   1459 7    149  6    8   
6    7    49   39   1349 8    5    2    134 
17   49   349  3579 359  6    2    8    134 
27   8    349  27   39   1    6    34   5   
5    12   6    23   8    4    13   9    7   

Here's the supercolour map
Code:
1a2a     1b2b     *        *        *        *        *        *        *       
3a9a     4b9b     *        *        *        *        3b4c     *        *       
3b4c     *        *        *        *        *        *        3a4b     *       
*        *        *        *        3e4f     *        9d       *        3g4h     
4b9b     *        *        5a       1b4j5b   *        1a       *        *       
*        *        4c9a     3h9j     1a3i4m9k *        *        *        1b3j     
1b7a     4c9a     3k9m     3l5b7b9n 3m5a9o   *        *        *        1a3n4b   
2b7b     *        3o4b9p   2a7a     3p9q     *        *        3b4c     *       
*        1a2a     *        2b3r     *        *        1b3s     *        *       

And here's the logical backtrace leading to the first reduction
Code:
Exclusion in {3,1} 1b excludes 3d
Conjugate in row 3 3d conjugates 3a
1b excludes 3d and 3d conjugates 3a so 1b implies 3a
Exclusion in {1,1} 1a excludes 3a
Conjugate in row 1 1a conjugates 1b
3a excludes 1a and 1a conjugates 1b so 3a implies 1b
Exclusion in {1,7} 1b excludes 4b
Conjugate in row 1 4a conjugates 4b
1b excludes 4b and 4b conjugates 4a so 1b implies 4a
Exclusion in {1,4} 4a excludes 9a
Conjugate in col 4 9a conjugates 9d
4a excludes 9a and 9a conjugates 9d so 4a implies 9d
1b implies 4a and 4a implies 9d so 1b implies 9d
Exclusion in {3,4} 3a excludes 9d
Conjugate in row 3 3d conjugates 3a
9d excludes 3a and 3a conjugates 3d so 9d implies 3d
1b implies 9d and 9d implies 3d so 1b implies 3d
3a implies 1b and 1b implies 3d so 3a implies 3d
Exclusion in {3,1} 1b excludes 3d
Conjugate in row 1 1a conjugates 1b
3d excludes 1b and 1b conjugates 1a so 3d implies 1a
3a implies 3d and 3d implies 1a so 3a implies 1a
1b implies 3a and 3a implies 1a so 1b implies 1a
Exclusion in {3,1} 1b excludes 3d
Conjugate in row 3 3d conjugates 3a
1b excludes 3d and 3d conjugates 3a so 1b implies 3a
Exclusion in {1,1} 1a excludes 3a
Conflict: 1b implies 1a and 1b implies 3a but 1a excludes 3a
Forcing: 1a=true {1,1} before=13 after=1
Reduction: 1b=false in {1,7} before=149 after=49
Reduction: 1b=false in {3,1} before=13 after=3

Regards
Andrew
Back to top
View user's profile Send private message Send e-mail
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