7:我们创建一个带有布尔值的数组(显然,这在论文中没有解释)。我们将当前值 (value = index) 赋值为“true”
18:此时,我们可以有一个数组,其中所有值都可以为“真”并达到 k = len(parents) 的条件 19-22:这将创建一个无限循环
我错过了什么吗?
论文:组合优化问题的部分映射交叉的多父扩展。Chuan-Kang Tinga, , , Chien-Hao Sub, , Chung-Nan Leeb,
http://www.sciencedirect.com/science/article/pii/S0957417409006800
//编辑:这是我的代码 Python-2.6
def MappingListDetermination(parents):
mapping_list = []
startparent = parents[random.sample(xrange(0, len(parents)), 1)[0]]
ptr = random.sample(xrange(0, len(startparent)), 1)[0]
temp_value = startparent[ptr]
boolean = [False] * listSize
for j in xrange(0,len(startparent)):
mapping_list.append(temp_value)
boolean[temp_value-1] = True
arr = random.sample(xrange(0, n), n)
if arr[0] == parents.index(startparent):
arr[0] = arr[random.sample(xrange(1, len(arr)), 1)[0]]
endparent = parents[arr[0]]
ptr = endparent.index(temp_value)
k = 0
while((boolean[startparent[ptr]-1] is True) and (k is not len(parents)-1)):
k = k + 1
startparent = parents[arr[k]]
if((boolean[startparent[ptr]-1] is True) and (k is len(parents)-1)):
while(boolean[startparent[ptr]-1] is True ):
startparent = parents[random.sample(xrange(0, len(parents)), 1)[0]]
ptr = startparent[random.sample(xrange(0, len(startparent)), 1)[0]]-1
temp_value = startparent[ptr]ere