Minimizing number of crossings in a bipartite graph

后端 未结 2 920
一向
一向 2021-02-14 04:47

The following algorithm problem occurred to me while drawing a graph for something unrelated:

\"enter

2条回答
  •  余生分开走
    2021-02-14 05:33

    Peter de Rivaz pointed that it is NP-Hard, but still if you are fine with some approximation you can go with the following solution.

    My initial thought was to use some force-based algorithm for graph layouting, but it can be bit tedious to implement. But hey, there is this wonderful program graphviz.org, that can make the whole work for you.

    So after installing just prepare a file with your graph:

    graph G{
       {rank=same A B C D E}
       {rank=same F G H K I J}
    
        A -- F;
        A -- G;
        A -- K;
        A -- I;
        A -- H;
        A -- J;
    
        B -- G;
    
        C -- G;
        C -- J;
    
        D -- K;
        D -- I;
    }
    

    Run: dot -Tpng yourgraph -o yourgraph.png

    and get something like that for free :-):

    enter image description here

提交回复
热议问题