| 4 | |
| 5 | |
| 6 | def plot(genotype, filename): |
| 7 | g = Digraph( |
| 8 | format='pdf', |
| 9 | edge_attr=dict(fontsize='20', fontname="times"), |
| 10 | node_attr=dict(style='filled', shape='rect', align='center', fontsize='20', height='0.5', width='0.5', penwidth='2', fontname="times"), |
| 11 | engine='dot') |
| 12 | g.body.extend(['rankdir=LR']) |
| 13 | |
| 14 | g.node("c_{k-2}", fillcolor='darkseagreen2') |
| 15 | g.node("c_{k-1}", fillcolor='darkseagreen2') |
| 16 | assert len(genotype) % 2 == 0 |
| 17 | steps = len(genotype) // 2 |
| 18 | |
| 19 | for i in range(steps): |
| 20 | g.node(str(i), fillcolor='lightblue') |
| 21 | |
| 22 | for i in range(steps): |
| 23 | for k in [2*i, 2*i + 1]: |
| 24 | op, j = genotype[k] |
| 25 | if j == 0: |
| 26 | u = "c_{k-2}" |
| 27 | elif j == 1: |
| 28 | u = "c_{k-1}" |
| 29 | else: |
| 30 | u = str(j-2) |
| 31 | v = str(i) |
| 32 | g.edge(u, v, label=op, fillcolor="gray") |
| 33 | |
| 34 | g.node("c_{k}", fillcolor='palegoldenrod') |
| 35 | for i in range(steps): |
| 36 | g.edge(str(i), "c_{k}", fillcolor="gray") |
| 37 | |
| 38 | g.render(filename, view=True) |
| 39 | |
| 40 | |
| 41 | if __name__ == '__main__': |