2009-07-09 13 views
6

Ich habe eine Reihe relativ einfacher (automatisch generierter) Graphen im graphviz dot Format. Diese zeigen den Pfad durch eine Zustandsmaschine, aber dot hat eine etwas verwirrende Angewohnheit, zu entscheiden, dass zwei Knoten auf dem gleichen Rang sein müssen, wenn der Graph in der Zustandsreihenfolge sein soll. Ich habe viele Einstellungen versucht (einschließlich der :n und :s und der weight unten aufgeführt), aber ich kann Punkt nicht überzeugen, den dritten Staat über der vierte Staat zu platzieren.Wie erzwingen Sie Rang auf einem Knoten in Punkt?

Ich habe dieses Problem mit vielen Graphen: es scheint etwas zu geben, das intern zu Punkt ist, der entscheidet, dass es besser wäre, wenn zwei Knoten auf demselben Rang sind und nichts getan werden kann, um sie zu überschreiben. Ich hatte sogar Code, der angibt, dass ein Knoten ein rank=sink sein sollte, aber dot hat entschieden, einen anderen Knoten darunter zu setzen.

Gibt es eine Möglichkeit zu sagen, dass es wichtiger ist, dass die Knoten in Ordnung sind als jede andere Einschränkung?

Der Code, der verwendet wurde, um die Grafik zu erzeugen wie folgt aussieht:

digraph { 
    ERROR [label="Error"]; 
    FirstSTATE [label="Initial State" URL="\ref FirstSTATE"]; 
    FirstSTATE -> SecondSTATE; 
    SecondSTATE [label="Second State" URL="\ref SecondSTATE"]; 
    SecondSTATE -> ThirdSTATE; 
    ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"]; 
    FourthSTATE [label="Fouth State?" shape="diamond"]; 
    ThirdSTATE:s -> FourthSTATE:n [weight=50]; 
    FourthSTATE -> FifthSTATE [label="Yes" ]; 
    FourthSTATE -> ThirdSTATE [label="No"]; 
    FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"]; 
    SixthSTATE [label="Sixth State?" shape="diamond"]; 
    SixthSTATE -> ERROR [label="Yes" ]; 
    SixthSTATE -> SeventhSTATE [label="No"]; 
    FifthSTATE -> SixthSTATE; 
    SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"]; 
    SeventhSTATE -> EighthSTATE; 
    EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"]; 
    NinthSTATE [label="Ninth State?" shape="diamond"]; 
    NinthSTATE -> TenthSTATE [label="Yes" ]; 
    NinthSTATE -> EighthSTATE [label="No"]; 
    EighthSTATE -> NinthSTATE; 
    TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"]; 
    EleventhSTATE [label="Eleventh State?" shape="diamond"]; 
    EleventhSTATE -> ERROR [label="Yes" ]; 
    EleventhSTATE -> TwelfthSTATE [label="No" ]; 
    TenthSTATE -> EleventhSTATE; 
    TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"]; 
} 

Die Grafik sieht wie folgt aus zur Zeit: Dot Graph

Antwort

10

Use "Constraint = false".

http://www.graphviz.org/doc/info/attrs.html#d:constraint

In Ihrem Diagramm:

FourthSTATE -> ThirdSTATE [label="No" constraint=false] ; 

Sie erhalten:

digraph { 
    ERROR [label="Error"]; 
    FirstSTATE [label="Initial State" URL="\ref FirstSTATE"]; 
    FirstSTATE -> SecondSTATE; 
    SecondSTATE [label="Second State" URL="\ref SecondSTATE"]; 
    SecondSTATE -> ThirdSTATE; 
    ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"]; 
    FourthSTATE [label="Fouth State?" shape="diamond"]; 
    ThirdSTATE -> FourthSTATE; 
    FourthSTATE -> FifthSTATE [label="Yes" ]; 
    FourthSTATE -> ThirdSTATE [label="No" constraint=false] ; 
    FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"]; 
    SixthSTATE [label="Sixth State?" shape="diamond"]; 
    SixthSTATE -> ERROR [label="Yes" ]; 
    SixthSTATE -> SeventhSTATE [label="No"]; 
    FifthSTATE -> SixthSTATE; 
    SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"]; 
    SeventhSTATE -> EighthSTATE; 
    EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"]; 
    NinthSTATE [label="Ninth State?" shape="diamond"]; 
    NinthSTATE -> TenthSTATE [label="Yes" ]; 
    NinthSTATE -> EighthSTATE [label="No"]; 
    EighthSTATE -> NinthSTATE; 
    TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"]; 
    EleventhSTATE [label="Eleventh State?" shape="diamond"]; 
    EleventhSTATE -> ERROR [label="Yes" ]; 
    EleventhSTATE -> TwelfthSTATE [label="No" ]; 
    TenthSTATE -> EleventhSTATE; 
    TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"]; 
} 
+0

Fantastische: danke! – DrAl

Verwandte Themen