def add_binary_tree_block_4(parent_node, num_leafs): # add while nodes while_node_1 = MctsTreeNode(parent=parent_node, children=[], val=1) while_node_0 = MctsTreeNode(parent=parent_node, children=[], val=0) parent_node.children = [while_node_1, while_node_0] # add while_node_0 as leaf node num_leafs[0] += 1 # add a nodes a_node_1 = MctsTreeNode(parent=while_node_1, children=[], val=1) a_node_0 = MctsTreeNode(parent=while_node_1, children=[], val=0) while_node_1.children = [a_node_1, a_node_0] # add bc nodes bc_node_1 = MctsTreeNode(parent=a_node_0, children=[], val=1) bc_node_0 = MctsTreeNode(parent=a_node_0, children=[], val=0) a_node_0.children = [bc_node_1, bc_node_0] next_parent_nodes = [a_node_1, bc_node_1, bc_node_0] return next_parent_nodes
def add_binary_tree_block_7(parent_node): # add while nodes while_node_1 = MctsTreeNode(parent=parent_node, children=[], val=1) while_node_0 = MctsTreeNode(parent=parent_node, children=[], val=0) parent_node.children = [while_node_1, while_node_0] # add if nodes if_node_1 = MctsTreeNode(parent=while_node_1, children=[], val=1) if_node_0 = MctsTreeNode(parent=while_node_1, children=[], val=0) while_node_1.children = [if_node_1, if_node_0] next_parent_nodes = [if_node_1, if_node_0] return next_parent_nodes, [while_node_0]
def add_binary_tree_block_3(parent_node, num_leafs): # add while nodes while_node_1 = MctsTreeNode(parent=parent_node, children=[], val=1) while_node_0 = MctsTreeNode(parent=parent_node, children=[], val=0) parent_node.children = [while_node_1, while_node_0] # add while_node_0 as leaf node num_leafs[0] += 1 # add if nodes if_node_1 = MctsTreeNode(parent=while_node_1, children=[], val=1) if_node_0 = MctsTreeNode(parent=while_node_1, children=[], val=0) while_node_1.children = [if_node_1, if_node_0] next_parent_nodes = [if_node_1, if_node_0] return next_parent_nodes
def generate_bin_tree(tree_type, depth, use_subtree_flag): num_leafs = [0] # create root node root = MctsTreeNode(parent=None, children=[], val="root") # add 20 location children nodes or 1 loc node is agentloc and agentdir is fixed loc_nodes = get_loc_nodes(root, tree_type, use_subtree_flag) root.children = loc_nodes # add binary tree for each loc node for loc_node in root.children: get_tree_gen_func(tree_type)(depth=depth, parent_nodes=[loc_node], num_leafs=num_leafs) print("created tree for {}".format(loc_node.val)) return root, num_leafs[0]