本文整理汇总了Python中common.Common.is_power2方法的典型用法代码示例。如果您正苦于以下问题:Python Common.is_power2方法的具体用法?Python Common.is_power2怎么用?Python Common.is_power2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.Common
的用法示例。
在下文中一共展示了Common.is_power2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: optional_clafer_toggle
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import is_power2 [as 别名]
def optional_clafer_toggle(z3inst, module, num_split, order="random"):
'''
only considers clafers with card = [0,1], AND numInstances = 1
num_split must be a power of 2
'''
assert(Common.is_power2(num_split))
initial_num_split = num_split
opts = []
for i in z3inst.cfr_sorts:
claferSort = z3inst.cfr_sorts[i]
lowerCard = claferSort.lowerCardConstraint
upperCard = claferSort.upperCardConstraint
if lowerCard == 0 and upperCard == 1 and claferSort.numInstances == 1 and not claferSort.element.isAbstract:
opts.append(claferSort)
if order == "random":
random.shuffle(opts)
else:
pairs = []
for i in opts:
pairs.append((i, len(i.parentStack)))
pairs.sort(key=operator.itemgetter(1))
if order == "top":
pairs.reverse()
opts = [i for (i, _) in pairs]
constraints = [True]
try:
while num_split != 1:
num_split = num_split // 2
currSort = opts.pop(0)
newConstraints = []
for i in constraints:
newConstraints.append(mAnd(i, currSort.instances[0] == 0))
for i in constraints:
newConstraints.append(mAnd(i, currSort.instances[0] == 1))
constraints = newConstraints
except:
return safe_raise_heuristic_failure_exception(order + "_optional_clafer_toggle#" + str(initial_num_split) + " failed.")
if num_split != 1:
return safe_raise_heuristic_failure_exception(order + "_optional_clafer_toggle#" + str(initial_num_split) + " failed.")
return constraints