我正在尝试使用邻域算法来实现子集和问题。这是伪代码:
1. Generate a random solution for the problem and call it S
2. Compute the neighborhood of S and choose S' as the best solution in the neighborhood
3. If S' is better than S then go to step 4, else go to step 6
4. S = S'
5. Go to step 2
6. Return S as the best solution encountered
给定一个包含 10 个元素(+ve 和 -ve)的集合 X,我必须找到 X 的一个子集,使得总和尽可能接近 0。
按照伪代码,我生成了一个随机解 S,但在构建邻域 S 时遇到了一些困难。
如何计算 S 的邻域?S附近是什么地方?
例如
X = [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9]
S = [x1, x7, x2, x3]
S附近是什么地方?