Morpheu5
Morpheu5

Reputation: 2801

How do I make this graph acyclic, with graphviz, dot?

First time DOT/GraphViz user here. I have the following graph

digraph G {
  rankdir=LR;
  "START" -> "A" -> "B" -> "A" -> "C" -> "A" -> "END"
  "START" -> "A" -> "C" -> "A" -> "B" -> "A" -> "END"
}

that gets rendered like this

enter image description here

whereas I'd like it to be rendered like this

enter image description here

How do I express that in DOT?

Upvotes: 4

Views: 981

Answers (2)

vaettchen
vaettchen

Reputation: 7659

This is exactly the same as @rakwaht suggested and you accepted already, just written more concisely - I don't think this is a nightmare:

digraph G{
    START [label="START"]; 
    A1, A2, A3 [label="A"]; 
    B1, B2 [label="B"];  
    C1, C2 [label="C"];  
    END [label="END"];
    START-> A1 -> { B1 C1 } -> A2 -> { B2 C2 } -> A3 -> END
}

Upvotes: 2

rakwaht
rakwaht

Reputation: 3967

In Graphviz you cannot have more then one state with the same ID. However you can create a graph where the IDs of the states are different but their label is the same.

In order to build the graph you want I would try with something like this:

digraph G{
    START [label="START"]; 
    A1 [label="A"]; 
    A2 [label="A"]; 
    A3 [label="A"]; 
    B1 [label="B"]; 
    B2 [label="B"]; 
    C1 [label="C"]; 
    C2 [label="C"]; 
    END [label="END"]
    START->A1
    A1->B1
    A1->C1
    B1->A2
    C1->A2
    A2->B2
    A2->C2
    B2->A3
    C2->A3
    A3->END
}

That defines different states with the same name (label) displayed. Here you can see the result: enter image description here

Upvotes: 2

Related Questions