def can_generate(self, tree, da): """Check if the candidate generator can generate a given tree at all. This is for debugging purposes only. Tries if get_all_successors always returns a successor that leads to the given tree (puts on the open list only successors that are subtrees of the given tree). """ self.init_run(da) open_list = CandidateList({TreeData(): 1}) found = False tree_no = 0 while open_list and not found: cur_st, _ = open_list.pop() if cur_st == tree: found = True break for succ in self.get_all_successors(cur_st): tree_no += 1 # only push on the open list if the successor is still a subtree of the target tree if tree.common_subtree_size(succ) == len(succ): open_list.push(succ, len(succ)) if not found: log_info('Did not find tree: ' + str(tree) + ' for DA: ' + str(da) + ('(total %d trees)' % tree_no)) return False log_info('Found tree: %s for DA: %s (as %d-th tree)' % (str(tree), str(da), tree_no)) return tree_no
def can_generate(self, tree, da): """Check if the candidate generator can generate a given tree at all. This is for debugging purposes only. Tries if get_all_successors always returns a successor that leads to the given tree (puts on the open list only successors that are subtrees of the given tree). """ self.init_run(da) open_list = CandidateList({TreeData(): 1}) found = False tree_no = 0 while open_list and not found: cur_st, _ = open_list.pop() if cur_st == tree: found = True break for succ in self.get_all_successors(cur_st): tree_no += 1 # only push on the open list if the successor is still a subtree of the target tree if tree.common_subtree_size(succ) == len(succ): open_list.push(succ, len(succ)) if not found: log_info('Did not find tree: ' + unicode(tree) + ' for DA: ' + unicode(da) + ('(total %d trees)' % tree_no)) return False log_info('Found tree: %s for DA: %s (as %d-th tree)' % (unicode(tree), unicode(da), tree_no)) return tree_no
from tgen.planner import CandidateList from tgen.tree import TreeData, NodeData import random import zlib random.seed(1206) l = CandidateList() for i in xrange(10000): # l[str(i)] = random.randint(0, 100) # l[str(random.randint(0,1000))] = random.randint(0, 100) # l[(str(random.randint(0,1000)), str(random.randint(0,1000)))] = random.randint(0, 100) # tree = TreeData() # tree.create_child(0, 1, NodeData(str(random.randint(0, 1000)), str(random.randint(0, 1000)))) # l[tree] = random.randint(0, 100) tree = TreeData() for j in xrange(random.randint(1, 10)): tree.create_child( random.randint(0, len(tree) - 1), random.randint(0, 1) == 1, NodeData(str(random.randint(0, 1000)), str(random.randint(0, 1000)))) l[tree] = random.randint(0, 100) x = [] while l: x.append(l.pop()) print zlib.crc32(str(x))
from tgen.planner import CandidateList from tgen.tree import TreeData, NodeData import random import zlib random.seed(1206) l = CandidateList() for i in xrange(10000): # l[str(i)] = random.randint(0, 100) # l[str(random.randint(0,1000))] = random.randint(0, 100) # l[(str(random.randint(0,1000)), str(random.randint(0,1000)))] = random.randint(0, 100) # tree = TreeData() # tree.create_child(0, 1, NodeData(str(random.randint(0, 1000)), str(random.randint(0, 1000)))) # l[tree] = random.randint(0, 100) tree = TreeData() for j in xrange(random.randint(1, 10)): tree.create_child( random.randint(0, len(tree) - 1), random.randint(0, 1) == 1, NodeData(str(random.randint(0, 1000)), str(random.randint(0, 1000))), ) l[tree] = random.randint(0, 100) x = [] while l: x.append(l.pop()) print zlib.crc32(str(x))