Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 2D-layout algorithm for DAGs that allows the positions on one axis to be fixed?

I've got a DAG of around 3.300 vertices which can be laid out quite successfully by dot as a more or less simple tree (things get complicated because vertices can have more than one predecessor from a whole different rank, so crossovers are frequent). Each vertex in the graph came into being at a specific time in the original process and I want one axis in the layout to represent time: An edge relation like a -> v, b -> v means that a and b came into being at some specific time before v.

Is there a layout algorithm for DAGs which would allow me to specify the positions (or at least the distances) on one axis and come up with an optimal layout regarding edge crossovers on the other?

like image 442
user2722968 Avatar asked Sep 22 '16 16:09

user2722968


People also ask

What is Kahn's algorithm?

Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG.

Can a DAG have more than one topological sort?

Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time. Topological sorting has many applications especially in ranking problems such as feedback arc set. Topological sorting is possible even when the DAG has disconnected components.

Is Kahn's algorithm BFS?

IIRC, Kahn's algorithm is effectively a BFS.

Which of the following algorithm is used for topological sorting?

Algorithm to find Topological Sorting: We recommend to first see the implementation of DFS. We can modify DFS to find Topological Sorting of a graph. In DFS, we start from a vertex, we first print it and then recursively call DFS for its adjacent vertices. In topological sorting, we use a temporary stack.


2 Answers

You can make a topological sorting of the DAG to have the vertices sorted in a way that for every edge x->y, vertex x comes before than y.

Therefore, if you have a -> v, b -> v, you will get something like a, b, v or b, a, v.

Using this you can easily represents DAGs like this:

topological sorting

like image 79
Arturo Menchaca Avatar answered Sep 21 '22 19:09

Arturo Menchaca


Yes, as @Arturo-Menchaca said a topological sorting may help to reduce overlapping count of edges. But it may be not optimal. There is no good algorithm for edge crossing minimization. Problem for crossing minimization is NP-complete. The heuristics are applied for solving this problem.

This StackOverflow link may help you: Drawing Directed Acyclic Graphs: Minimizing edge crossing?

I suppose your problem is related to an aesthetically pleasing way of the graph layout. Some heuristics are described in the articles Overview of algorithms for graph drawing, Force-Directed Drawing Algorithms. May be information about planar graph or almost planar graph can help you also.

Some review of the algorithms for checking and drawing planar graphs are described in the Wiki pages Planar graph, Crossing number (graph theory). The libraries and algorithms for planar graph drawing are described in the StackOverflow question How to check if a Graph is a Planar Graph or not? For example the author in the article GA for straight-line grid drawings of maximal planar graphs uses genetic algorithms for straight-line grid drawing.

Good descriptions for almost planar graphs are given in the articles Straight-Line Drawability of a Planar Graph Plus an Edge, On the Crossing Number of Almost Planar Graphs.

Try to modify the original algoritms using your condition with one axis alignment.

like image 25
Didgeridoo Avatar answered Sep 20 '22 19:09

Didgeridoo