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将是一个与运算。设定差异的分期手术会是什么?此外,我只是想知道这种类型的交叉可能是什么原因,如果这种类型的交叉与其他常见的交叉技术如单点交叉或双点交叉有优势。