本文整理汇总了Python中unit.Unit.problem_list[i]方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.problem_list[i]方法的具体用法?Python Unit.problem_list[i]怎么用?Python Unit.problem_list[i]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit.Unit
的用法示例。
在下文中一共展示了Unit.problem_list[i]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cross
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import problem_list[i] [as 别名]
def cross(unit_list, count, paper):
"""
基因重组
"""
crossed_unit_list = []
while (len(crossed_unit_list) != count):
index_one = randint(0, len(unit_list) - 1)
index_two = randint(0, len(unit_list) - 1)
if index_one == index_two:
continue
unit_one = unit_list[index_one]
unit_two = unit_list[index_two]
cross_position = randint(0, unit_one.problem_count - 2)
score_one = unit_one.problem_list[cross_position].score + \
unit_one.problem_list[cross_position+1].score
score_two = unit_two.problem_list[cross_position].score + \
unit_two.problem_list[cross_position+1].score
if score_one == score_two:
unit_new_one = Unit()
unit_new_one.problem_list += unit_one.problem_list
unit_new_two = Unit()
unit_new_two.problem_list += unit_two.problem_list
p = random()
if p < 0.8:
for i in range(cross_position, cross_position + 2):
unit_new_one.problem_list[i] = unit_two.problem_list[i]
unit_new_two.problem_list[i] = unit_one.problem_list[i]
unit_new_one.id = len(crossed_unit_list)
unit_new_two.id = unit_new_one.id + 1
if len(crossed_unit_list) < count:
crossed_unit_list.append(unit_new_one)
if len(crossed_unit_list) < count:
crossed_unit_list.append(unit_new_two)
crossed_unit_list = list(set(crossed_unit_list))
set_kp_coverage(crossed_unit_list, paper)
set_adaptation_degree(crossed_unit_list, paper, FKPCOV, FDIFF)
return crossed_unit_list