-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IsPlanarDigraph and related #156
Conversation
Thanks, I'll review once there are tests and documentation and the CI passes. |
Interestingly, this almost works ;) |
Also I will split the PR into 2 commits, one adding all the files in the subpackage and the other with the changes to Digraphs itself |
Also @wilfwilson any chance you can merge stable-0.14 into master? So I can rebase on that? |
Merged! |
Super thanks! |
23fa2eb
to
105a467
Compare
105a467
to
a45a3c0
Compare
I think this is more or less good to go. I'm just going to valgrind, and if the CI passes, then this is ready for review. |
Oh wait I forgot, I don't know how to valgrind GAP, I committed some files that are generated by mistake will remove them now. |
a45a3c0
to
6946673
Compare
Ready to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @james-d-mitchell, thanks for doing this. In my review I've asked a few questions, and otherwise my comments basically amount to some tweaks to the documentation.
doc/planar.xml
Outdated
<Description> | ||
An <E>outer planar</E> digraph is a digraph that can be embedded in the | ||
plane in such a way that its edges do not intersect, and all vertices | ||
belong to the unbounded face of the embedding. A digraph is planar if and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A digraph is planar or outer planar?
doc/planar.xml
Outdated
<Description> | ||
<C>KuratowskiPlanarSubdigraph</C> returns the list of out-neighbours | ||
of a (not necessarily induced) subdigraph of the digraph <A>digraph</A> | ||
that witness the fact that <A>digraph</A> is not planar, or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
witness -> witnesses
doc/planar.xml
Outdated
<K>fail</K> if <A>digraph</A> is planar. In other words, | ||
<C>KuratowskiPlanarSubdigraph</C> returns the out-neighbours of a | ||
subdigraph of <A>digraph</A> that is homeomorphic to the complete graph | ||
with four vertices, or to the complete bipartite graph with vertex sets of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you mean K_5 and K_3,3 and not K_4 and K_2,3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that here you talk about the complete graph with four vertices
whereas above you talk about the complete graph on <C>4</C> vertices
- it's not vital but I'd recommend to use the same wording.
doc/planar.xml
Outdated
If <A>digraph</A> is a planar digraph, then | ||
<C>PlanarEmbedding</C> returns the list of out-neighbours | ||
of a subdigraph of <A>digraph</A> such that each vertex's | ||
neighbors are given in clockwise order. If <A>digraph</A> is not planar, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use neighbours for consistency with the rest of the documentation/sentence please.
<Attr Name="PlanarEmbedding" Arg="digraph"/> | ||
<Returns>A list or <K>fail</K>.</Returns> | ||
<Description> | ||
If <A>digraph</A> is a planar digraph, then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this documentation properly conveys what's happening here. The point is that if the vertices are drawn as suggested by the returned list, then you can fill in the edges without edges crossing. I feel like the connection between this clockwise property and planarity could be elucidated a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could be clearer, I have not been able to find any description of the return value of this method (from the edge-addition-planarity-suite), so I basically copied what is written here from the corresponding manual entry from Sage see here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I appreciate the explanation. To me, this bit of documentation is pretty much meaningless (as is the Sage entry) – I don't actually know whether the description "The point is that..." that I gave above is correct. If you think you can work out and write a better description, please do, but otherwise it won't stop me merging.
the complete bipartite graph with vertex sets of sizes <C>2</C> and | ||
<C>3</C>; the complete bipartite graph with vertex sets of sizes <C>3</C> | ||
and <C>3</C>; or the complete graph with <C>4</C> vertices. If | ||
<A>digraph</A> has no such subdigraphs, then <K>fail</K> is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe emphasise the point that a digraph is planar/outer planar if and only if it has no such sub digraph?
Why does SubdigraphHomeomorphicToK5
not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a link to the doc for IsPlanarDigraph
and IsOuterPlanarDigraph
, rather than repeating the doc here again.
Why does SubdigraphHomeomorphicToK5 not exist?
Because it isn't implemented in the edge-addition-planarity-suite, and it isn't clear to me how to do this (at least in any good way). I did have a version of this PR where I had a function called SubdigraphHomeomorphicTo(digraph, subdigraph)
but I abandoned it as too complicated in the first instance (it would only have worked for digraphs homeomorphic to K_4, K_{2, 3}, and K_{3, 3}, anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I'm surprised that it doesn't contain a K_5 thing, but that it does contain the other three, but then again I have no idea what the suite is doing!
@@ -384,14 +384,10 @@ InstallMethod(OutNeighbours, "for a digraph", | |||
[IsDigraph], | |||
function(digraph) | |||
local out; | |||
if IsBound(digraph!.adj) then | |||
return digraph!.adj; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change included here? And what is the explanation for its deletion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we remove the component adj
from all digraphs at some point in the not too distant past? This was originally used to hold the OutNeighbours
for access in the C code, but if I recall this was unnecessary, and I think you removed it. I believe this code is a remnant of the older code, and I noticed it when writing tests for MaximalAntiSymmetricSubdigraph
(it was not covered by any tests, and removing it seems to have no effect). Perhaps it should be in another PR, but it is in a separate commit at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, no problem. I'm not sure if I did the changes, but yes this the adj
component is removed, and certainly if these lines are not being covered by tests then it's not needed. I'm not normally against a PR changing unrelated things, but my default assumption when reviewing a PR is that the changes are related, and so I was confused at this point because I couldn't work out what the relation was here.
n := DigraphNrVertices(D); | ||
if n <= 1 | ||
or (HasIsAntisymmetricDigraph(D) and IsAntisymmetricDigraph(D)) then | ||
return D; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If n <= 1
or the digraph is already antisymmetric, it's possible that there are still multiple edges, which the documentation forbids!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, I swapped the clauses around here.
gap/oper.gi
Outdated
@@ -1005,13 +1005,13 @@ function(digraph, edge) | |||
end); | |||
|
|||
InstallMethod(IsDigraphEdge, "for a digraph, pos int, pos int", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the string please to agree with the args
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry,
gap/oper.gi
Outdated
function(digraph, u, v) | ||
local n; | ||
|
||
n := DigraphNrVertices(digraph); | ||
|
||
if u > n or v > n then | ||
if u > n or v > n or u < 0 or v < 0 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to allow 0
? Vertices are currently restricted to [1..n]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double sorry my bad. BTW the reason for this change was that I want to call IsDigraphEdge
in the C code, and there, sometimes GAP integers don't seem belong to IsPosInt
even though they are positive and would satisfy IsPosInt
in GAP.
I am also a bit wary of including a whole library. But if it seems to work, then let's do it. If it causes problems for us or other users in the future, then we can deal with this then. |
Thanks @wilfwilson I’ll try to update the pr today |
I agree with you @wilfwilson, on the other hand, we already rely on Bliss, so maybe it's not that bad either. I'll update the PR just now. |
6946673
to
ccc9e27
Compare
Updated! Off to Paris now, will check in again tomorrow. Thanks for the review @wilfwilson ! |
@@ -22,6 +22,7 @@ DeclareProperty("IsReflexiveDigraph", IsDigraph); | |||
DeclareProperty("IsStronglyConnectedDigraph", IsDigraph); | |||
DeclareProperty("IsSymmetricDigraph", IsDigraph); | |||
DeclareProperty("IsAntisymmetricDigraph", IsDigraph); | |||
DeclareSynonym("IsAntiSymmetricDigraph", IsAntisymmetricDigraph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be DeclareSynonymAttr
.
I hope you remembered your yellow vest @james-d-mitchell! |
@james-d-mitchell I just thought about licensing issues. Is the license of digraphs compatible with the suite, and vice versa? Do we need to include a copy of their license or something? |
From https://github.com/graph-algorithms/edge-addition-planarity-suite/blob/master/LICENSE.TXT:
Fair enough. At the top of all the new files you've retained
But I think it would be a good idea to actually include that |
I had to tweak it ever so slightly to get it to work, so this is not exactly version 3.0.0.5.
ccc9e27
to
ba19a25
Compare
hi @wilfwilson finally back at my keyboard. i thought I did include a copy of the |
This PR adds functionality to Digraphs to check whether a digraph is planar, and some related functionality. This is essentially just a wrapper around the C library edge-addition-planarity-suite, plus a little bit more.
It is currently missing:
Things to keep in mind:
This makes Digraphs dependent on an external C-library (which appears to work well as an autohell subpackage). A copy of the library is included in this PR. I'm not completely sure this is desirable.
It might be the case that at some point in the future edge-addition-planarity-suite stops working on some platforms or is no longer maintained. At that point, we can introduce a configure flag
--disable-edge-addition-planarity-suite
to disable these features. I don't really want to add the flag now, because then we have to test with and without the flag and everything gets more complex.