Search code examples
graphvizvertexdirectionedgesdigraphs

How do I constrain connected vertices to share a single edge?


Because of the way that information is being generated, I results that look like this:

digraph "A" {
  "a1" -> "a2";
  "a2" -> "a1";
  "a1" -> "a2";
  "a2" -> "a1";
}

enter image description here

What I would prefer to see, is:

digraph "A" {
  "a1" -> "a2"[dir=both];
}

enter image description here

Is there a way to tell the entire digraph to merge edges,
and create bidirectional edges where possible?

I'd like to keep the data as generated, but add a few lines to create the second image.


Solution

  • That's essentially what concentrate is for.

    Simply add the following line to your graph, at the beginning or the end:

    concentrate=true