如何可视化任意树?
例如:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
def next_available_row(wks):
str_list = list(filter(None, wks.col_values(2))) # fastest
return str(len(str_list)+1)
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('TOOL-fsbd3df3.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("Log").sheet1
next_row = next_available_row(wks)
wks.update_acell("B{}".format(next_row), "test")
wks.update_acell("C{}".format(next_row), "test")
或使用以下命令生成的
(define T1 '(and (or x1 x2)(or x3 x4 x5)))
球拍似乎有: https://docs.racket-lang.org/pict/Tree_Layout.html
用圆圈中的功能名称和参数来可视化功能树是否足够?
答案 0 :(得分:2)
您可以执行以下操作来可视化任意大小的树:
(require pict
pict/tree-layout)
(define (draw tree)
(define (viz tree)
(cond
((null? tree) #f)
((not (pair? tree))
(tree-layout #:pict (cc-superimpose
(disk 30 #:color "white")
(text (symbol->string tree)))))
((not (pair? (car tree)))
(apply tree-layout (map viz (cdr tree))
#:pict (cc-superimpose
(disk 30 #:color "white")
(text (symbol->string (car tree))))))))
(if (null? tree)
#f
(naive-layered (viz tree))))
例如,使用您提供的列表:
(define t1 '(and (or x1 x2) (or x3 x4 x5)))
(define t2 '(or (if A1 (and A1 (not (if D1 (and A0 A0) (or A0 A0)))) (or A0 A0)) D0))
答案 1 :(得分:0)