几年前就知道graphviz,那时候我试着用它来画流程图,但是效果不理想。直到最近重学数据结构时,将graphviz与代码结合起来才显现出它的强大,特别是复杂的树类数据结构,如果没有好的可视化方法,调试代码将会非常耗时。

AVL

avl.svg

digraph {
 splines=false;
 node [style=filled,color=lightblue;];

 node0x10063b100[label="40 (h3)"]
 node0x10063b100 -> node0x10063aaf0
 node0x10063aaf0 -> node0x10063b100
 node0x10063aaf0[label="36 (h1)"]
 node0x10063aaf0 -> node0x10063ab20
 node0x10063ab20 -> node0x10063aaf0
 node0x10063ab20[label="27 (h0)"]
 rChild0x10063aaf0 [label="Null"][style = dotted]
 node0x10063aaf0 -> rChild0x10063aaf0[style = dotted]
 node0x10063b100 -> node0x10070b9c0
 node0x10070b9c0 -> node0x10063b100
 node0x10070b9c0[label="46 (h2)"]
 node0x10070b9c0 -> node0x100406ba0
 node0x100406ba0 -> node0x10070b9c0
 node0x100406ba0[label="41 (h0)"]
 node0x10070b9c0 -> node0x10063ab50
 node0x10063ab50 -> node0x10070b9c0
 node0x10063ab50[label="58 (h1)"]
 node0x10063ab50 -> node0x10063abb0
 node0x10063abb0 -> node0x10063ab50
 node0x10063abb0[label="53 (h0)"]
 node0x10063ab50 -> node0x10063b0d0
 node0x10063b0d0 -> node0x10063ab50
 node0x10063b0d0[label="69 (h0)"]
}

B-Tree

btree.svg

digraph {
 splines=false;
 node [shape = record,height=.1,style=filled,color=lightblue;];

 node0x10055a2e0 [label = " <node268> 268"]
 node0x10055a2e0:<node268>:sw -> node0x10055a060
 node0x10055a060 [label = " <node53> 53| <node56> 56| <node196> 196"]
 node0x10055a060:<node53>:sw -> node0x100559a80
 node0x100559a80 [label = " <node51> 51| <node52> 52"]
 node0x10055a060:<node53>:se -> node0x10055a310
 node0x10055a310 [label = " <node54> 54| <node55> 55"]
 node0x10055a060:<node56>:se -> node0x10055a240
 node0x10055a240 [label = " <node57> 57| <node152> 152"]
 node0x10055a060:<node196>:se -> node0x100559b10
 node0x100559b10 [label = " <node249> 249| <node266> 266"]
 node0x10055a2e0:<node268>:se -> node0x10055a290
 node0x10055a290 [label = " <node310> 310| <node468> 468"]
 node0x10055a290:<node310>:sw -> node0x10055a0b0
 node0x10055a0b0 [label = " <node299> 299| <node300> 300"]
 node0x10055a290:<node310>:se -> node0x10055a1b0
 node0x10055a1b0 [label = " <node315> 315| <node423> 423"]
 node0x10055a290:<node468>:se -> node0x10055a160
 node0x10055a160 [label = " <node484> 484| <node528> 528"]
}

红黑树

redblack.svg

digraph {
 splines=false;
 node [style=filled,color=lightblue;];

 node0x100447e00 [label="41 (h1)",color=black,fontcolor=white]
 node0x100447e00 -> node0x100447920
 node0x100447920 -> node0x100447e00
 node0x100447920 [label="36 (h0)",color=red,fontcolor=white]
 node0x100447920 -> node0x100447950
 node0x100447950 -> node0x100447920
 node0x100447950 [label="27 (h0)",color=black,fontcolor=white]
 node0x100447950 -> node0x1004479b0
 node0x1004479b0 -> node0x100447950
 node0x1004479b0 [label="6 (h-1)",color=red,fontcolor=white]
 rChild0x100447950 [label="Null"][style = dotted]
 node0x100447950 -> rChild0x100447950[style = dotted]
 node0x100447920 -> node0x100447dd0
 node0x100447dd0 -> node0x100447920
 node0x100447dd0 [label="40 (h0)",color=black,fontcolor=white]
 node0x100447dd0 -> node0x100447e30
 node0x100447e30 -> node0x100447dd0
 node0x100447e30 [label="39 (h-1)",color=red,fontcolor=white]
 rChild0x100447dd0 [label="Null"][style = dotted]
 node0x100447dd0 -> rChild0x100447dd0[style = dotted]
 node0x100447e00 -> node0x100447980
 node0x100447980 -> node0x100447e00
 node0x100447980 [label="58 (h0)",color=red,fontcolor=white]
 node0x100447980 -> node0x1004479e0
 node0x1004479e0 -> node0x100447980
 node0x1004479e0 [label="53 (h0)",color=black,fontcolor=white]
 node0x100447980 -> node0x100447da0
 node0x100447da0 -> node0x100447980
 node0x100447da0 [label="69 (h0)",color=black,fontcolor=white]
 lChild0x100447da0 [label="Null"][style = dotted]
 node0x100447da0 -> lChild0x100447da0[style = dotted]
 node0x100447da0 -> node0x100447e60
 node0x100447e60 -> node0x100447da0
 node0x100447e60 [label="76 (h-1)",color=red,fontcolor=white]
}

决策树调用过程

pro.svg

digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="petal width (cm) <= 1.65\ngini = 0.66\nsamples = 94\nvalue = [44, 43, 63]\nclass = virginica", fillcolor="#8139e52e"] ;
1 [label="petal width (cm) <= 0.8\ngini = 0.51\nsamples = 61\nvalue = [44, 42, 1]\nclass = setosa", fillcolor="#e581390b"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="gini = 0.0\nsamples = 31\nvalue = [44, 0, 0]\nclass = setosa", fillcolor="#e58139ff"] ;
1 -> 2 ;
3 [label="sepal length (cm) <= 6.05\ngini = 0.05\nsamples = 30\nvalue = [0, 42, 1]\nclass = versicolor", fillcolor="#39e581f9"] ;
1 -> 3 ;
4 [label="gini = 0.0\nsamples = 18\nvalue = [0, 27, 0]\nclass = versicolor", fillcolor="#39e581ff"] ;
3 -> 4 ;
5 [label="petal length (cm) <= 5.25\ngini = 0.12\nsamples = 12\nvalue = [0, 15, 1]\nclass = versicolor", fillcolor="#39e581ee"] ;
3 -> 5 ;
6 [label="gini = 0.0\nsamples = 11\nvalue = [0, 15, 0]\nclass = versicolor", fillcolor="#39e581ff"] ;
5 -> 6 ;
7 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]\nclass = virginica", fillcolor="#8139e5ff"] ;
5 -> 7 ;
8 [label="petal length (cm) <= 4.85\ngini = 0.03\nsamples = 33\nvalue = [0, 1, 62]\nclass = virginica", fillcolor="#8139e5fb"] ;
0 -> 8 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
9 [label="petal length (cm) <= 4.65\ngini = 0.38\nsamples = 3\nvalue = [0, 1, 3]\nclass = virginica", fillcolor="#8139e5aa"] ;
8 -> 9 ;
10 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 2]\nclass = virginica", fillcolor="#8139e5ff"] ;
9 -> 10 ;
11 [label="sepal length (cm) <= 6.05\ngini = 0.5\nsamples = 2\nvalue = [0, 1, 1]\nclass = versicolor", fillcolor="#39e58100"] ;
9 -> 11 ;
12 [label="gini = 0.0\nsamples = 1\nvalue = [0, 1, 0]\nclass = versicolor", fillcolor="#39e581ff"] ;
11 -> 12 ;
13 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]\nclass = virginica", fillcolor="#8139e5ff"] ;
11 -> 13 ;
14 [label="gini = 0.0\nsamples = 30\nvalue = [0, 0, 59]\nclass = virginica", fillcolor="#8139e5ff"] ;
8 -> 14 ;
}

森林

forest.svg

digraph {
 node [shape="box",style=filled,color="#8139e5ff"]
 edge [color="#8139e5ff",minlen="10"]
 node0x10070e2a0[label=""]
 node0x10070e2a0->node0x10070e340[dir="both"]
 {rank=same; node0x10070e2a0;node0x10070e340}
 node [shape= ellipse,style=filled,color=lightblue]
 edge [color=lightblue,minlen="1"];
 node0x10070e2a0->node0x10070e280
 node0x10070e280[label=" ^ "]
 node0x10070e280 -> node0x1006500c0
 node0x1006500c0 -> node0x10070e280
 node0x1006500c0[label=" e "]
 node0x10070e280 -> node0x10070e0a0
 node0x10070e0a0 -> node0x10070e280
 node0x10070e0a0[label=" ^ "]
 node0x10070e0a0 -> node0x100650520
 node0x100650520 -> node0x10070e0a0
 node0x100650520[label=" s "]
 node0x10070e0a0 -> node0x10070df10
 node0x10070df10 -> node0x10070e0a0
 node0x10070df10[label=" ^ "]
 node0x10070df10 -> node0x100450f40
 node0x100450f40 -> node0x10070df10
 node0x100450f40[label=" ^ "]
 node0x100450f40 -> node0x10051f3e0
 node0x10051f3e0 -> node0x100450f40
 node0x10051f3e0[label=" ^ "]
 node0x10051f3e0 -> node0x1006502a0
 node0x1006502a0 -> node0x10051f3e0
 node0x1006502a0[label=" k "]
 node0x10051f3e0 -> node0x100450ea0
 node0x100450ea0 -> node0x10051f3e0
 node0x100450ea0[label=" ^ "]
 node0x100450ea0 -> node0x10064f7b0
 node0x10064f7b0 -> node0x100450ea0
 node0x10064f7b0[label=" H "]
 node0x100450ea0 -> node0x10064f940
 node0x10064f940 -> node0x100450ea0
 node0x10064f940[label=" M "]
 node0x100450f40 -> node0x100450ef0
 node0x100450ef0 -> node0x100450f40
 node0x100450ef0[label=" ^ "]
 node0x100450ef0 -> node0x10064fb20
 node0x10064fb20 -> node0x100450ef0
 node0x10064fb20[label=" S "]
 node0x100450ef0 -> node0x10064f030
 node0x10064f030 -> node0x100450ef0
 node0x10064f030[label=" 0 "]
 node0x10070df10 -> node0x100650020
 node0x100650020 -> node0x10070df10
 node0x100650020[label=" c "]
 
 node [shape="box",style=filled,color="#8139e5ff"]
 edge [color="#8139e5ff",minlen="10"]
 node0x10070e340[label=""]
 node [shape= ellipse,style=filled,color=lightblue]
 edge [color=lightblue,minlen="1"];
 node0x10070e340->node0x10070e320
 node0x10070e320[label=" ^ "]
 node0x10070e320 -> node0x10070e190
 node0x10070e190 -> node0x10070e320
 node0x10070e190[label=" ^ "]
 node0x10070e190 -> node0x1006503e0
 node0x1006503e0 -> node0x10070e190
 node0x1006503e0[label=" o "]
 node0x10070e190 -> node0x100650570
 node0x100650570 -> node0x10070e190
 node0x100650570[label=" t "]
 node0x10070e320 -> node0x10070e1e0
 node0x10070e1e0 -> node0x10070e320
 node0x10070e1e0[label=" ^ "]
 node0x10070e1e0 -> node0x10070dfb0
 node0x10070dfb0 -> node0x10070e1e0
 node0x10070dfb0[label=" ^ "]
 node0x10070dfb0 -> node0x100450fe0
 node0x100450fe0 -> node0x10070dfb0
 node0x100450fe0[label=" ^ "]
 node0x100450fe0 -> node0x100650160
 node0x100650160 -> node0x100450fe0
 node0x100650160[label=" g "]
 node0x100450fe0 -> node0x100650340
 node0x100650340 -> node0x100450fe0
 node0x100650340[label=" m "]
 node0x10070dfb0 -> node0x1006501b0
 node0x1006501b0 -> node0x10070dfb0
 node0x1006501b0[label=" h "]
 node0x10070e1e0 -> node0x10064ff80
 node0x10064ff80 -> node0x10070e1e0
 node0x10064ff80[label=" a "]
}
posted @ 2020-06-26 10:29:48
评论加载中...

发表评论