This month is the hardest day, because my mentor and I were fighting for Siggraph in the last days of my internship at Shenzhen Advanced Research Institute, I also hope to publish my previous paper at the undergraduate level, haha.
In addition, I will share with you the information about a tree used in the study.AlgorithmRight. The goal of this algorithm is to remove the intermediate node of the tree and retain the branch node. As required:
Conversion:
It is generated by http://www.graphviz.org/doc/info/lang.html
AttachedCode:
View plaincopy to clipboardprint?
- DefReduced_graph (subtree, V, graph ):
- N = graph [subtree]
- IfLen (n) =0:
- V [subtree] = []
- Return[Subtree]
- ElifLen (n) =1:# One child
- R = reduced_graph (N [0], V, graph)
- V [subtree] = r
- IfLen (V [n [0]) =1:
- DelV [n [0]
- ReturnV [subtree]
- Else:
- Next_sub = []
- ForCInN:
- R = reduced_graph (C, V, graph)
- Next_sub.append (R [0])
- IfLen (V [c]) =1:
- DelV [c]
- V [subtree] = next_sub
- Return[Subtree]
Call method:
View plaincopy to clipboardprint?
- V = {}
- Graph = {0:[1],1:[2],2:[3,4],3:[5],4:[6],5:[7,8],6:[9],9: [],7:[11],11: [],8: []}
- Root =0
- Reduced_graph (root, V, graph)
The graph representation method is the adjacent matrix representation.
Why is this Python code very strange? Because the reduced_graph function also returns the value. In fact, the parameter V also returns the value. After the project is over, I hope to refactor this wonderful code.
During the process, we also found Len (n) = 0 without N = [] efficiency. I also tested the code of the two, which is n times faster, it may be because the function call overhead is relatively large.
----------------- Create high-qualityArticleFor more information, thank you ---------------
To create high-quality articles, pleaseRecommendationCome on .... Thank you. Please pay attention to my subsequent articles, which will be even better.
Sina Weibo: http://weibo.com/baiyang26
The wine ghost official blog: http://www.ibaiyang.org [recommended to use Google Reader subscription]
Pour wine into the official Douban: http://www.douban.com/people/baiyang26/
If you want to repost this blog,Please specify the source
If you have any comments or suggestions on this article,Leave a message