0
我想實現部分摘要問題,該算法在第35-36頁的pdf https://cise.ufl.edu/class/cap5515sp10/Ch04_DNA_mapping.pdf中給出。在隨後的頁面中給出了一個例子。部分摘要算法(PDP)
我無法得到正確的答案。
我得到的X值是[0,10,8,3,6],然後遞歸以「不好」停止。
可能是我不明白的算法或別的東西?
width = 0
def partialDigest(L):
print "partialDigest"
global width
width = max(L)
L.remove(width)
X = [0, width]
if place(L, X):
print "Ok"
else:
print "Not ok"
def place(L, X):
print "place"
print "Width is", width
print "L is ", L
print "X is ", X
if len(L) == 0:
print "Output is: ", X
return True
y = max(L)
print "Y is", y
#L.remove(y)
d = D(y, X)
print "d is ", d
if set(d).issubset(set(L)):
print "First if"
print "D is", d
print "X before is ", X
X.append(y)
print "X after is ", X
print "L before is", L
L = removeElements(d, L)
print "L after is ", L
place(L, X)
X.remove(y)
L.extend(d)
d1 = D(abs(width-y), X)
print "d1 is ", d1
if set(d1).issubset(set(L)):
print "Second if"
print "D is", d1
print "X before is ", X
X.append(abs(width-y))
print "X after is ", X
print "L before is", L
L = removeElements(d1, L)
print "L after is ", L
place(L, X)
X.remove(abs(width-y))
L.extend(d1)
return False
def D(y, X):
diff = []
for xi in X:
diff.append(abs(y-xi))
return diff
def removeElements(d, L):
for i in L:
for j in d:
if i == j:
L.remove(i)
d.remove(i)
return L
if __name__ == "__main__":
print "Python implementation of partial digetive problem PDP on page 90."
partialDigest([2, 2, 3, 3, 4, 5, 6, 7, 8, 10])
您能添加預期的正確輸出嗎?否則,其他用戶很難幫助您。 –
@MaximilianPeters所以[0,10,8,3,6]是答案之一,另一個答案是[0,10,2,7,4]。我有代碼工作,在新的代碼中,我不使用python的issubset()函數。如果您對該算法有更深入的瞭解,請讓我知道,因爲我是生物信息學的新手。 – limitlessriver