Improve user-facing isomorphism and canonical labelling functions, especially with colourings#49
Conversation
|
Note: this PR makes no changes to anything at the C or C++ level, nor does any of the new code directly interface with any C functions. In particular, the new methods for |
1a5aa5e to
cef726f
Compare
james-d-mitchell
left a comment
There was a problem hiding this comment.
This looks really good. There a couple of issues of consistency, and some more suggestions about the validate colouring function. Please make these corrections. There are only two non-minor issues:
-
Why don't we support multidigraphs and vertex colours? If there is a good reason for this it should be written somewhere. Maybe it is, and I overlooked it.
-
I don't think we should allow colour 0, this is confusing and probably was a mistake.
| <Attr Name="ChromaticNumber" Arg="digraph"/> | ||
| <Returns> A non-negative integer.</Returns> | ||
| <Description> | ||
| A digraph coloring is a labeling of the vertices (using precisely <A>n</A> |
There was a problem hiding this comment.
This is weird, what is n here? This is not really related to your pull request, but since you are changing this man section anyway, why not remove the statement in brackets here? I guess this was copy pasted from another manual entry where the number of colours was specified by an argument n.
There was a problem hiding this comment.
Yes this must have been copied from the documentation for DigraphColouring when the documentation for ChromaticNumber was add. I'll reword it.
| colours := DIGRAPHS_ValidateVertexPartition(n, list); | ||
| if colours = fail then | ||
| ErrorNoReturn("Digraphs: DigraphCanonicalLabelling: usage,\n", | ||
| "the argument <list> does not define a valid colouring of ", |
There was a problem hiding this comment.
"Colouring" or "coloring"? There seem to be both in this file. I'm fine with either but we should probably be consistent.
There was a problem hiding this comment.
I favour colouring. I'll aim for consistency (including local variable names).
| "the vertices of\n<digraph>. Either <list> should be a list ", | ||
| "of length <n> consisting of integers\nin the range ", | ||
| "[0 .. <n>], or <list> should be a list of non-empty ", | ||
| "disjoint\nlists whose union is the vertices of <digraph>,"); |
There was a problem hiding this comment.
I think this error message could be more helpful. What is n for example? I think it would be better to add this error message to DIGRAPHS_ValidateVertexPartitionand be more specific about what is wrong (as was previously attempted). I haven't yet looked at DIGRAPHS_ValidateVertexPartition, will comment more there.
| fi; | ||
|
|
||
| return DIGRAPH_CANONICAL_LABELING_COLORS(graph, colors); | ||
| return DIGRAPH_CANONICAL_LABELING_COLORS(digraph, colours); |
There was a problem hiding this comment.
Shouldn't this be `LABELLING' for consistency?
There was a problem hiding this comment.
Yes, I'll make this change. The only reason I didn't change the names of the C functions is because the Semigroups package called one of these directly and I didn't want to have to fiddle with that. However I'll make a PR to Semigroups to sort this out.
| local m, colour1, n, colour2, class_sizes, i; | ||
|
|
||
| if IsMultiDigraph(gr1) or IsMultiDigraph(gr2) then | ||
| ErrorNoReturn("Digraphs: IsIsomorphicDigraph: usage,\n", |
There was a problem hiding this comment.
Why is this not supported? On the face of it, isn't this just the same as the non-coloured case?
| fi; | ||
| return fail; | ||
| elif IsEmpty(partition) then | ||
| return fail; |
| <Oper Name="AutomorphismGroup" Label="for a digraph and a homogeneous list" | ||
| Arg="digraph, colors"/> | ||
| <Returns>A permutation group.</Returns> | ||
| <Returns>A permutation group, or a direct product of permutation |
There was a problem hiding this comment.
Isn't a direct product of perm groups a perm group?
There was a problem hiding this comment.
Yes. AutomorphismGroup for a multidigraph previously had its own manual section, but I combined it with the section for a digraph without multiple edges (but without colours). The returns bit for the multidigraph section said "A direct product of permutation groups", so I just kept that bit.
| If <A>digraph</A> is a digraph without multiple edges, then this function | ||
| returns the automorphism group of <A>digraph</A>, as a group of | ||
| permutations on the vertices of <A>digraph</A>. <P/> | ||
| If <A>digraph</A> is a digraph, then this attribute returns the group of |
There was a problem hiding this comment.
returns -> stores or contains maybe?
| stabiliser of the vertices in the automorphism group of the edges. These | ||
| two groups can be accessed using the operation <Ref Oper="Projection" | ||
| Label="for a domain and a positive integer" BookName="ref"/>, with the | ||
| second argument being <C>1</C> or <C>2</C>, respectively. <P/> |
There was a problem hiding this comment.
This is really good, can we say which projection corresponds to which action, and actually give an example? This would be most helpful.
There was a problem hiding this comment.
You probably like it because you wrote it :) I'll do what I can to improve it.
| A coloured digraph can be specified by its underlying digraph | ||
| <A>digraph</A> and its colouring <A>colours</A>. Let <C>n</C> be the | ||
| number of vertices of <A>digraph</A>. The colouring <A>colours</A> may | ||
| have one of the following two forms: <P/> |
There was a problem hiding this comment.
I think the <P/> here is superfluous.
|
I will modify The functions with colourings that I wrote do not support multidigraphs since the two-argument I'm happy to disallow the colour 0. Another question: for a colouring of the form |
|
I've revisted what I had written before. For consistency's sake, I still think it's right that a colouring of the form |
cafc081 to
8ddc986
Compare
|
I think I've sorted all of this out now. The main change I've made since your review was to add support for passing coloured multidigraphs to bliss. This mostly involved creating a function for constructing coloured multidigraphs for bliss, and a slightly different hook function. Coloured non-multidigraphs used one trick to encode their colours and directed edges, whilst non-coloured multidigraphs used another trick to encode their multiple edges. I just combined these things together. That means we can ask about the automorphism group and canonical labelling (and hence isomorphism) of a coloured multidigraph. It seems to work fine. |
|
@wilfwilson I agree about not missing colours, I think this is the only sensible option. |
james-d-mitchell
left a comment
There was a problem hiding this comment.
Looks good, final changes:
- minor change suggested to the big error in the validate colours thing,
- Please declare
DigraphColoringas a synonym ofDigraphColouring, and any other similar methods, for backwards compatibility. - Move the validate colouring function out of
utils
| <#Include Label="EpimorphismsDigraphs"> | ||
| <#Include Label="GeneratorsOfEndomorphismMonoid"> | ||
| <#Include Label="DigraphColoring"> | ||
| <#Include Label="DigraphColouring"> |
There was a problem hiding this comment.
I think we'll need to keep DigraphColoring too for backwards compatibility.
There was a problem hiding this comment.
The synonym already exists in grahom.gd, and there are tests using both DigraphColoring and DigraphColouring. I just changed the name of the mansection's label.
| fi; | ||
| ErrorNoReturn("Digraphs: ", method, ": usage,\n", | ||
| "the argument <partition> does not define a ", | ||
| "colouring of the vertices [1 .. ", n, "].\nTo do so, the ", |
8ddc986 to
97c9fae
Compare
|
@james-d-mitchell All sorted. |
This PR adds support for isomorphism testing, and isomorphism finding, for coloured digraphs.
Previously in the Digraphs package... you could ask for the automorphism group of a coloured digraph without multiple edges (i.e. the subgroup of the automorphism of the digraph consisting of those elements that preserve the colouring), and you could ask for the canonical labelling of a coloured digraph without multiple edges.
I've now added similar support for coloured digraphs to the operations
IsIsomorphicDigraphandIsomorphismDigraphs, for testing whether two coloured digraphs without multiple edges are isomorphic as coloured digraphs (i.e. whether there exists an isomorphism between the digraphs that respects the colourings of the vertices).In addition to these new features, I've made minor improvements to the existing code, such as checking in
IsIsomorphicDigraphwhether the two digraphs are equal before going on to compute a canonical labelling.The main change of this type is a new global function
DIGRAPHS_ValidateVertexPartition. Creating this function allows me to replace a large amount of duplicated code which existed to validate whether the "colouring" given as an argument toAutomorphismGrouporDigraphCanonicalLabellingwas indeed a valid colouring of the relevant digraph. This is now also used byIsIsomorphicDigraphandIsomorphismDigraphs.Given a non-negative integer
nand a homogeneous listpartition, thisDIGRAPHS_ValidateVertexPartitiontests whetherpartitionis a valid partition[1 .. n]. A valid partition of[1 .. n]is either:nconsisting of numbers in the range[0 .. n](so thatpartition[i]is the colour of vertexi), or[1 .. n](so thatpartition[i]is the list of those vertices with colouri).If
partitionis a valid partition of[1 .. n]then it returns the partition in form 1 (this is the form that bliss likes); otherwise it returnsfail.This is both a more and less permissive definition of colouring than existed previously.
It's more permissive, since in the first form, I now allow the colour
0to be used. This is because:[0 .. n](but not outside of this range), andCanonicalBooleanMatcalculates the canonical labelling of a particular colouring digraph which uses colours 0 and 1. Since colour 0 is not currently allowed in Digraphs, this method usesDIGRAPH_CANONICAL_LABELING_COLORS. I think it would be better if this method used the operationDigraphCanonicalLabellingfor a digraph and a colouring.It's less permissive, since in the second form, I now require the list to consist of disjoint lists. This was currently allowed, but to my mind that was a mistake, as it doesn't make sense for a vertex to have two colours.
In time, this global function should also replace the validation of the colouring given to
HomomorphismDigraphsFinder.However, the main work on this PR is an improvement to documentation all of the functions
AutomorphismGroup,DigraphCanonicalLabelling,IsIsomorphicDigraph, andIsomorphismDigraphsin the filebliss.*.The previous documentation for these functions was either incorrect, incomplete, or confusing (this confusion prompted issue #19). It certainly left me scratching my head for a while. I've tried to make the documentation as clear, as thorough, and as helpful as possible.
As an aside, since in the
bliss.xmldocumentation we talk a lot about colourings, where we simply mean a labelling, I now emphasise in the documentation forDigraphColouringandChromaticNumberthat these colourings are special in some sense -- they are proper colourings.