Search code examples
graphviz

Getting GraphViz to eliminate identical duplicate edges


I have the following .dot language file for GraphViz:

digraph {
    graph [ dpi = 300 ];
    Hello -> World
    Hello -> World
    Hello -> World
}

Which renders as:

enter image description here

The code is produced programmatically, hence the duplication.

But I don't want the duplicate links i.e. I want it to render as:

enter image description here

Yes, I could add logic to the program that produces the dot file, but if there is a GraphViz parameter to do this it’d be very useful.

Thanks.

Edit: Raising the dead here, but the question of which this is marked as a duplicate has multiple connections between 2 nodes but each with different labels, so not exactly the same, although the suggestion to use the ‘strict’ keyword does work.

Edit: Again voting to reopen, as the question that someone thinks this is a duplicate of is, in fact, a different question. This is about duplicate edges and the other questions isn't. The fact that the same answer works is irrelevant, just as "What is 2+2?" and "what is 3+1?" are different questions, despite having the same answer.


Solution

  • ‘strict’ was the answer :

    strict digraph {
        graph [ dpi = 300 ];
        Hello -> World
        Hello -> World
        Hello -> World
    }
    

    Edit:

    From https://graphviz.org/doc/info/lang.html :

    A graph may also be described as strict. This forbids the creation of multi-edges, i.e., there can be at most one edge with a given tail node and head node in the directed case. For undirected graphs, there can be at most one edge connected to the same two nodes. Subsequent edge statements using the same two nodes will identify the edge with the previously defined one and apply any attributes given in the edge statement.