Repository navigation
Add utility to extract faces from PlanarEmbedding - #8512
Conversation
dschult
left a comment
There was a problem hiding this comment.
Thanks for this!
Big picture comments:
Can you provide a reference for this algorithm? Is there a publication/wikipedia page where facial boundary walks are discussed or used?
How would you see the result being used? Is a list of sets a convenient data structure for the result?
I guess it would be possible to make this a method of the class, but I like this function interface. It's not complicated code -- so I suppose the user could put it together themselves, but it takes a fair amount of thinking, and it requires close knowledge of the embedding data class. So it seems reasonable to have a separate function.
As far as where this function goes/lives, the tests would traditionally live in the test_planarity.py module. Is there a reason you put them separately? Thoughts?
|
Voicing support for this PR though I haven't gone over it in detail -- it's something I was going to need to add for #8489 anyway. The algorithm is bog-standard and will appear (or be taken for granted) in any reference that mentions the algorithm implemented in
No, it should be a list of lists (perhaps lazier and less mutable; an iterable of tuples?) -- facial walks can visit nodes multiple times, and it's important to know what order that happens in. |
|
Thanks for the insight @boothby - a quick API question: IYO is this better suited as a method of the Function
Method
I have no strong opinion, but since you've been thinking about this already it'd be great to hear what you'd want the UX to be! |
|
Great question, Ross. I'm not personally married to the notion that classes shouldn't have methods, but I think the line should be "don't make a standalone function that must depend on the guts of a class." And in this case, * specifically if we adopt a different representation of embeddings that can handle surfaces other than the plane, one might want to find facial walks and making such a class conform to the |
|
Having looked in detail; if Dan's objections are satisfied I think this is good |
|
@dschult About the Big Picture This function is about finding faces of a graph when the embedding is planar. To put it in context: there are three cases actually. The number of faces of a graph depends on the embedding. Embedding can be planar or non-planar. And if it is non-planar, the manifold onto which the graph is embedded can be either orientable or non-orientable. (If it is planar, it is orientable, as all planes in \mathbb{R}^2 are orientable, so we end up with three cases.) The math here involves rotation systems (I see the Wikipedia page for it was posted). Rotation systems are a standard textbook topic. This is not research-level. Also, rotation systems can be used to find the faces in any of the three cases. This function is for the case when the graph is embedded onto a plane. It is short because embedding.neighbors_cw_order(u) gives the cyclic ordering of neighbors for the vertex u, which is essentially the rotation system for that vertex. This is contained in PlanarEmbedding. To answer @rossbar : this is not boilerplate. We need to make sure that the object is there. It is where the rotation system comes from. How I see it being used I uploaded the planar case only because my understanding is that the others could be out of the scope of NetworkX, but I have a wrapper that computes faces, whichever case it might be. Is a list of sets a convenient data structure for the result? @boothby I understand some might want a specific path traversal, but how about some other function for that? This idea could be generalized, and wanting a list of edges for all the faces given a constraint would be a specific version of a more general path traversal algorithm on a graph. Should these be functions or methods? PS. Thanks everyone for the comments |
|
Thanks everyone for the fruitful discussion! To summarize the action items to get us towards the (seemingly) forming consensus:
|
|
Gentle ping @VarandArakelian are you still planning on working on this? There's a clear path forward summarized above! |
|
@rossbar Yes. I haven't had time. The plan is to begin doing what remains here after March 15th |
dschult
left a comment
There was a problem hiding this comment.
This looks good. Thanks @VarandArakelian
rossbar
left a comment
There was a problem hiding this comment.
I took the liberty of removing some of the "helper" functions in the test suite, but otherwise LGTM. Thanks @VarandArakelian and everyone for the reviews!
* Add utility to extract faces from PlanarEmbedding * Style fixes from pre-commit * Fix typing and import order for faces_from_planar_embedding * Add faces() method to PlanarEmbedding * MAINT: Rm indirection. * Rm more indirection. * STY: Undo style changes. --------- Co-authored-by: Ross Barnowski <[email protected]>
This PR adds a small utility function,
faces_from_planar_embedding, that enumerates facial boundary walks from aPlanarEmbedding.Motivation
While NetworkX can compute planar embeddings, it does not currently provide a public helper to enumerate the faces induced by a given combinatorial embedding. Several algorithms and applications work directly at the level of the rotation system (rather than a geometric drawing) and require access to facial boundary walks.
What this adds
faces_from_planar_embedding(embedding)innetworkx.algorithms.planarityTests
New tests verify that:
PlanarEmbeddinginputs raise aTypeErrorThis change is additive and does not modify existing APIs.