开发者

Using GraphViz to Diagram an Extensive-Form Game

I'm attempting to diagram an extensive form game in GraphViz. Compiling the code results in a graph that is correct in all ways except one. I want the "War" label to be placed to the left of the edge it labels, such that the edge is closest to "r" and not "W".

This is my "game"开发者_JAVA技巧 or graph so far:

    digraph hierarchy_of_D  { 

            graph [rankdir ="UD"] 
            node [color=black,shape=circle]
            //splines="polyline"

     I [label="R"] 

     subgraph infoset1 
      { 
       label="whatever" 
       rank="same" 
       1 [label="C"]
       2 [label="C"]
      } 


     I -> 1 [label="War"] //fix how this floats right of the line
     I -> 2 [label="Peace"]
     1 -> 2 [style=dashed, dir=none] 

     subgraph info21 
      { 
        rank="same" 
        3 [label="(2,2)", rank=sink, shape="plaintext"]
        4 [label="(5,1)", rank=sink, shape="plaintext"]
        5 [label="(1,5)", rank=sink, shape="plaintext"]
        6 [label="(4,4)", rank=sink, shape="plaintext"]
       } 

       1 -> 3 [label="War"]
       1 -> 4 [label="Peace"]
       2 -> 5 [label="War"]
       2 -> 6 [label="Peace"]

    } 

Any ideas? I've already tried the following, which does not do what I want:

1 -> 3 [label="War/l"]

See also this question and that question, neither of which have an answer. C'mon now, this is worth triple points!


Triple points? Well then, the correct answer is that you cannot choose the placement of edge labels.

However, you may play with headlabel, labeldirection and labelangle:

digraph hierarchy_of_D  { 

node [color=black,shape=circle]

I [label="R"] 

subgraph infoset1 
{ 
   label="whatever" 
   rank="same" 
   1 [label="C"]
   2 [label="C"]
} 

I -> 1 [headlabel="War", labeldistance=3, labelangle=40]
I -> 2 [headlabel="Peace", labeldistance=3, labelangle=-40]
1 -> 2 [style=dashed, dir=none] 

subgraph info21 
{ 
    rank="same" 
    3 [label="(2,2)", rank=sink, shape="plaintext"]
    4 [label="(5,1)", rank=sink, shape="plaintext"]
    5 [label="(1,5)", rank=sink, shape="plaintext"]
    6 [label="(4,4)", rank=sink, shape="plaintext"]
} 

1 -> 3 [headlabel="War", labeldistance=3, labelangle=40]
1 -> 4 [headlabel="Peace", labeldistance=3, labelangle=-40]
2 -> 5 [headlabel="War", labeldistance=3, labelangle=40]
2 -> 6 [headlabel="Peace", labeldistance=3, labelangle=-40]
} 

Output:

Using GraphViz to Diagram an Extensive-Form Game


Just for fun, an other workaround I just found:

By forcing straight edges between nodes using splines=false and defining edges twice, the edges are drawn as if they were one single edge, but the labels of each edge get to are drawn (most of the time) on different sides of the edge.

Therefore by having one edge without a label, and the other one with a label, it is possible to influence the placement of the edge(s) label(s).

Your example:

digraph hierarchy_of_D  { 
splines=false;

node [color=black,shape=circle]

I [label="R"] 

subgraph infoset1 
{ 
   rank="same" 
   1 [label="C"]
   2 [label="C"]
} 

I -> 1 [label="War "]
I -> 1 [label="    "]
I -> 2 [label=""]
I -> 2 [label="Peace"]
1 -> 2 [style=dashed, dir=none] 

subgraph info21 
{ 
    rank="same" 
    3 [label="(2,2)", rank=sink, shape="plaintext"]
    4 [label="(5,1)", rank=sink, shape="plaintext"]
    5 [label="(1,5)", rank=sink, shape="plaintext"]
    6 [label="(4,4)", rank=sink, shape="plaintext"]
} 

1 -> 3 [label="War"]
1 -> 3 [label=""]
1 -> 4 [label=""]
1 -> 4 [label="Peace"]
2 -> 5 [label=""]
2 -> 5 [label="War "]
2 -> 6 [label=""]
2 -> 6 [label="Peace"]} 

And the output:

Using GraphViz to Diagram an Extensive-Form Game

It's not perfect, and your mileage may vary depending on the graph, but I thought it was worth mentioning it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜