Skip to main content

Generating Chessboards With K-Independant Vertex Sets

After looking at Julio Peironcely's poster on generating chemical structures, where he describes using Canonical Path Augmentation (I think due to Brendan McKay) I went looking for more about it. One thing I found was this talk/slideshow by Mathieu Dutour Sikirić - incidentally coauthor of a nice book on Chemical Graphs.

Anyway; that's the context. Now : about chessboards? Well one of the examples given for augmentation (or 'orderly') schemes of independent vertex sets. I'm not sure what made me think of chessboards for this, but I think it's a fairly standard simple toy example. Let me show an example for 3x3 boards:

So, these are all the three by three boards where no two black squares share an edge. In other words, if the board is considered as a grid-shaped graph, then these are the k-independent vertex sets. So the question is : how to generate these?

The simple way, of course, is just to fill in every square and eliminate those boards that have pairs of black squares across an edge. This is the 'brute force' approach, and scales badly : there are 29 boards but we only want 20 of these, or just 3%. For 4x4 boards, this fraction is even smaller - 131 of 216 boards which is only 0.19%. This is 0.0026% for 5x5 boards.

So, the number of boards increases rapidly as the size increases and any way of decreasing this large search space is essential. The approach outlined in Mathieu's talk is quite simple : only try sets (boards) that are the minimal representative in their orbit. Ok, so maybe that doesn't sound so simple :) but look at this:

Here are 3x3 boards, with a numbering (any one will do), the equivalence classes of the cells, and a set of orbits. Lets say we've just generated {0, 4, 6} : how do we check if it is the minimal representative? Well, so long as we have the automorphism group of the board we just apply each permutation in the group to the set of numbers and check to see if any are smaller. In this case, {0, 2, 4} is smaller, so we don't consider {0, 4, 6}.

It's really as simple as that. Of course, we have to check each newly added cell to make sure it is not adjacent, but that can be done without consideration of previously generated boards. This means we don't have to store solutions, which means it can be done in parallel without communication. See how many there are just for 5x5 boards:

I suppose that one last question about all this is : so what? Does this have anything to do with chemistry? Well, actually, it does. Consider the bond order assignment problem : the second image shows all the possible assignments, which you may notice has duplicates (3, 5, 10, and 12 for example). Also consider the line graph approach to double bond systems where again the second image shows a pair of colorings of line graphs. In fact, these are k-independent sets...

Oh, and there is code here


Anonymous said…
interesting work.

Lemma: When you generate the next solution state, you could ignore previous state.

So this means previous state checks are reduced.

Now the number of solutions are not effected, right?
gilleain said…
Missed this comment, sorry!

Yes, this is exactly right - you can break up the problem into parts, and do each independently.

So, the second post on this topic about graphs should really mention that you can start with a graph on n vertices, and generate all the children on (n+1) vertices.

This can be done for different parents on completely different machines, and you would still get the same number of children.

Popular posts from this blog

How many isomers of C4H11N are there?

One of the most popular queries that lands people at this blog is about the isomers of C4H11N - which I suspect may be some kind of organic chemistry question on student homework. In any case, this post will describe how to find all members of a small space like this by hand rather than using software.

Firstly, lets connect all the hydrogens to the heavy atoms (C and N, in this case). For example:

Now eleven hydrogens can be distributed among these five heavy atoms in various ways. In fact this is the problem of partitioning a number into a list of other numbers which I've talked about before. These partitions and (possible) fragment lists are shown here:

One thing to notice is that all partitions have to have 5 parts - even if one of those parts is 0. That's not strictly a partition anymore, but never mind. The other important point is that some of the partitions lead to multiple fragment lists - [3, 3, 2, 2, 1] could have a CH+NH2 or an NH+CH2.

The final step is to connect u…

The Gale-Ryser Theorem

This is a small aside. While reading a paper by Grüner, Laue, and Meringer on generation by homomorphism they mentioned the Gale-Ryser (GR) theorem. As it turns out, this is a nice small theorem closely related to the better known Erdős-Gallai (EG).

So, GR says that given two partitions of an integer (p and q) there exists a (0, 1) matrixA iff p*dominatesq such that the row sum vector r(A) = p and the column sum vector c(A) = q.

As with most mathematics, that's quite terse and full of terminology like 'dominates' : but it's relatively simple. Here is an example:

The partitions p and q are at the top left, they both sum to 10. Next, p is transposed to get p* = [5, 4, 1] and this is compared to q at the bottom left. Since the sum at each point in the sequence is greater (or equal) for p* than q, the former dominates. One possible matrix is at the top left with the row sum vector to the right, and the column sum vector below.

Finally, the matrix can be interpreted as a bi…

Havel-Hakimi Algorithm for Generating Graphs from Degree Sequences

A degree sequence is an ordered list of degrees for the vertices of a graph. For example, here are some graphs and their degree sequences:

Clearly, each graph has only one degree sequence, but the reverse is not true - one degree sequence can correspond to many graphs. Finally, an ordered sequence of numbers (d1 >= d2 >= ... >= dn > 0) may not be the degree sequence of a graph - in other words, it is not graphical.

The Havel-Hakimi (HH) theorem gives us a way to test a degree sequence to see if it is graphical or not. As a side-effect, a graph is produced that realises the sequence. Note that it only produces one graph, not all of them. It proceeds by attaching the first vertex of highest degree to the next set of high-degree vertices. If there are none left to attach to, it has either used up all the sequence to produce a graph, or the sequence was not graphical.

The image above shows the HH algorithm at work on the sequence [3, 3, 2, 2, 1, 1]. Unfortunately, this produce…