Search code examples
graphgraphviz

How do I graph the Thompson's construction using graphviz?


I am trying to graph the construction of Thompson using graphviz, and I would like to know if anyone could help me graph one of the rules so that I can do the others.

I attach a reference image: https://en.wikipedia.org/wiki/Thompson%27s_construction#/media/File:Thompson-kleene-star.svg

digraph finite_state_machine {
    rankdir=LR;
    size="8,5"
    node [shape = doublecircle]; s3;
    node [shape = circle];
    s0 -> s1 [ label = "ε" ];   
    s0 -> s3 [ label = "ε" ];
    s1 -> s2 [ label = "ε" ];
    s2 -> s1 [ label = "ε" ];
    s2 -> s3 [ label = "ε" ];
}

Solution

  • Graphviz programs try to avoid placing nodes on top of other nodes. You can get the node placement by explicitly providing pos attributes for all the nodes. (Not that difficult, but a nuisance.) You can get neato to generate all straight edges, but you will have to provide the (spline) coordinates for all the arcs. Otherwise you get this: enter image description here

    As an alternative, instead of graphviz, if you use dpic or gpic, this program:

    .PS
    
    .defcolor pink rgb #FFC0CB
     circlerad=circlerad*.8
    
     ## we need to place the large oval before we place nodes on it
     Qx: circle invis ; line invis; circle invis; A: line invis; 
     ellipseht=ellipseht*2;  
     ellipsewid=ellipsewid*2
     E:ellipse at  A.c   shaded "pink" " N(s)"
    
     move to Qx.w 
    
     Q: circle "q" ; arrow "ε" "";  C1: circle ; A: line invis; C2: circle ; arrow "ε" "";  F: circle "f"; 
    
     circlerad=circlerad*.8
     F1:circle   at last circle   
    
     move to E.n; up; P1: box invis "ε"
     arc -> from C2.n to C1.n 
    
     arcrad=2
     arc -> from Q.s to F.s
    
      ### gpic version of greek chars:
      # move to E.s; down; box invis "" "\[*e]"
      ########################################
    
      ###  dpic/svg version of greek chars
      move to E.s; down; box invis "" "ε"
    
    .PE
    

    produced this: enter image description here

    gpic is part of the GNU (Linux) groff package.
    dpic can be found here: https://ece.uwaterloo.ca/~aplevich/dpic/