本文整理汇总了Python中treelib.Tree.paths_to_leaves方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.paths_to_leaves方法的具体用法?Python Tree.paths_to_leaves怎么用?Python Tree.paths_to_leaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treelib.Tree
的用法示例。
在下文中一共展示了Tree.paths_to_leaves方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paths_to_leaves [as 别名]
#.........这里部分代码省略.........
- clone engine
- start at root
-- iterate and find next unprocessed node
-- action engine to that node parent
-- process that node
- keep processing
- with return EV
Levelling:
extremely huge iterations when many players. So
do the most probably actions only till all done.
Handling close action approximations:
"""
# logger.info('Monte Carlo started')
total_traversions_start = sum(a[2] for a in self.current_actions)
# cannot run if engine in showdown or gg
if self.engine.phase in [self.engine.PHASE_SHOWDOWN, self.engine.PHASE_GG]:
logger.warning('cannot run mc with no actions')
return
self.duration = duration
self.time_start = time.time()
self.queue = PriorityQueue()
# threads = []
# for _ in range(self.N_THREADS):
# t = MCWorker(self)
# # t.start()
# threads.append(t)
# self.traversed_focus = 0
leaves = self.tree.paths_to_leaves()
# logger.debug('leaves from tree: {}'.format(len(leaves)))
# leaves.sort(key=lambda lp: len(lp) + sum(int(lpn.split('_')[0]) for lpn in lp), reverse=True)
# # logger.debug('{} leaves are now sorted by formula'.format(len(leaves)))
# logger.debug('{}'.format(json.dumps(leaves[:3], indent=4, default=str)))
# leaves.sort(key=len)
# logger.debug('{} leaves are now sorted by length'.format(len(leaves)))
# logger.debug('{}'.format(json.dumps(leaves[:3], indent=4, default=str)))
# leaves.sort(key=lambda lp: int(lp[-1][:3]), reverse=True)
# logger.debug('{} leaves are now sorted by rank'.format(len(leaves)))
# logger.error(json.dumps(leaves, indent=4, default=str))
# input('>>')
for leaf_path in leaves:
node = self.tree[leaf_path[-1]]
item = (
1 - node.data['cum_stats'],
leaf_path,
)
self.queue.put(item)
# for t in threads:
# t.start()
#
# for t in threads:
# t.join()
# if t.error:
# raise Exception().with_traceback(t.error[2])
while self.is_time_left() and not self.queue.empty():
priority, self.leaf_path = self.queue.get_nowait()
self.run_item(self.leaf_path)
if self.queue.empty():