本文整理汇总了Python中unit.Unit.id方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.id方法的具体用法?Python Unit.id怎么用?Python Unit.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit.Unit
的用法示例。
在下文中一共展示了Unit.id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_one_unit
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import id [as 别名]
def generate_one_unit(i, paper, problem_list):
"""
随机生成一个个体
"""
unit = Unit()
unit.id = i + 1
each_type_count = paper.each_type_count
while paper.total_score != unit.sum_score:
unit.problem_list = []
for j in range(len(each_type_count)):
one_type_problem = [
p for p in problem_list
if p.type == j+1 and is_contain_points(p, paper)]
for k in range(0, each_type_count[j]):
length = len(one_type_problem)
index = randint(0, length - k - 1)
unit.problem_list.append(one_type_problem[index])
one_type_problem[index], one_type_problem[length-k-1] = \
one_type_problem[length-k-1], \
one_type_problem[index]
return unit
示例2: cross
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import id [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