6

I have a graph with two types of vertices: "boundary" vertices have degree 1, and "interior" vertices have degree 4. I've computed a planar embedding of the graph, i.e. around each vertex, I have the list of outgoing edges in (say) clockwise order, and I know that if you connect them up while respecting that ordering, the result will be planar with no edge crossings. The problem is simply to have the computer automatically draw the graph "nicely" from this existing local data.

Ideally, I want the boundary vertices to be equally spaced around the outside of a circle, with the interior vertices forming a network of connections between them without being too spaced out or too bunched up. I'm most interested in visualizing this stuff for up to a few hundred total nodes.

This seems like it should be relatively straightforward, though I am not familiar with the field of graph visualization. Abstractly it seems like one should be able to do some naive algorithm followed by a generic repulsion or similar step, but implementing anything like that on my own seems like a waste, because surely it's been done. My searches on this topic have unfortunately run into many dead ends, since I've already computed the planar embedding, and I don't want the black box drawing algorithm to do that, and I'd like the boundary vertices on a circle. If there is a more appropriate forum for this question, by all means tell me, since I was unable to find any.

My code is currently in SageMath, which does have a planar-embedded graph drawing routine, but the output is completely unusable for practical examples since it uses nearly parallel edges and bunches things up terribly. I would not mind using an external tool. It would be great if I could manipulate the resulting graphs in a GUI (e.g. these are actually oriented graphs, and I'd like to be able to manually click to toggle orientations), but that is not essential.

Mark S.
  • 25,893
  • 2
    It appears you can pin vertices (say, to fixed points on the circle) both with GraphViz and the software associated with recent work by Yu, Schumacher, and Crane (the page links this GitHub). I have no experience using either of these tools, myself. – Mark S. Apr 06 '22 at 11:30
  • 2
    Thanks for the suggestions. Graphviz does not appear to allow me to specify the edge orientations reliably--it wants to lay them out in its own way. The Yu et al work does look relevant, though the repulsion step would seem to require an initial realization of a planar embedding. I asked David Eppstein, who believed the most common way to get that realization is a method by de Fraysseix, Pach, and Pollack, though he didn't know of a separate implementation of that step. – Joshua P. Swanson Apr 08 '22 at 06:25
  • Could you provide the graph data? Have you tried using the sage spring layout - perhaps increasing the iterations? This usually leads to a planar representation. – Lev Apr 13 '22 at 22:40
  • @Lev I'm not sure you quite understand the question. I want to draw a specific, already-computed abstract planar embedding encoded as local orientations of edges around each vertex. I don't want anything that tries to find a planar embedding for me. I can provide sample data if it's helpful, though quite literally take any planar embedding of a planar graph and erase everything but little stubs of edges poking out of each vertex--that's the input. – Joshua P. Swanson Apr 14 '22 at 02:40
  • I would also be very interested in a solution - particular one that also allows for loops and multiple edges. (I guess we could get around this by adding vertices of degree 2 along the edges, however.) – Lasse Rempe Aug 23 '22 at 16:18
  • One potential way of realising these in the plane from complex analysis would be to insert additional vertices along the edges to make the graph bipartite, and then compute the realisation of this "dessin d'enfant", for which there are now some surprisingly efficient methods. This will give you a planar realisation, but a) it seems there should be more direct methods; b) some parts of the graph will tend to get very small so while they are nice and conformal embeddings, probably not the best to look at. I will try to look at the message of Fraysseix et al that you mention. – Lasse Rempe Aug 23 '22 at 16:20

1 Answers1

2

We ended up using the Tutte embedding. Concretely, we fixed the boundary vertices where we wanted them and repeatedly replaced the interior vertices with the average of their neighbors' positions until they basically converge. One could solve a system of linear equations instead.

This has the virtue of being extremely easy to code while also giving quite pleasing output the vast majority of the time. Drawbacks are that it can't handle self-loops or multiple edges, and it only provably works under the additional assumption that the graph is 3-vertex connected. Those can be corrected by adding and removing extra edges. In our application, we have yet to bother.