1
我遵循遺傳算法的方法來解決揹包問題here。我知道他們使用直接值編碼方案而不是二進制表示法。交叉功能如下:遺傳算法:交叉0-1揹包
def cxSet(ind1, ind2):
"""Apply a crossover operation on input sets. The first child is the
intersection of the two sets, the second child is the difference of the
two sets.
"""
temp = set(ind1) # Used in order to keep type
ind1 &= ind2 # Intersection (inplace)
ind2 ^= temp # Symmetric Difference (inplace)
return ind1, ind2
如果我要編碼揹包問題的二進制表示的染色體,inersection將是一個與運算。設定差異的分期手術會是什麼?此外,我只是想知道這種類型的交叉可能是什麼原因,如果這種類型的交叉與其他常見的交叉技術如單點交叉或雙點交叉有優勢。