我对网格世界很陌生,我需要有关如何使用GridGain处理算法的指导,该算法是递归的TravellingSalesmanProblem。
TSP看起来像这样:
public int tsp(int hops, byte[] path, int length, int minimum,
DistanceTable distance) {
int city, dist, me;
int NTowns = distance.dist.length;
// stop searching, this path is too long...
if (length + distance.lowerBound[NTowns - hops] >= minimum) {
return minimum;
}
if (hops == NTowns) {
/* Found a full route better than current best route,
* update minimum. */
return length;
}
/* "path" really is a partial route.
* Call tsp recursively for each subtree. */
me = path[hops - 1]; /* Last city of path */
/* Try all cities that are not on the initial path,
* in "nearest-city-first" order. */
for (int i = 0; i < NTowns; i++) {
city = distance.toCity[me][i];
if (city != me && !present(city, hops, path)) {
dist = distance.dist[me][i];
int min;
path[hops] = (byte) city;
min = tsp(hops + 1, path, length + dist, minimum, distance);
minimum = minimum < min ? minimum : min;
}
}
return minimum;
}
我相信我需要进行聚合,就像GG的Fibonacci示例一样,问题是我不知道要设置什么到GridFuture,因为我在循环中有一个递归调用(我相信我不能创建为许多期货作为我的递归调用,没有意义)。我已经搜索了更多示例,但我无法将任何示例映射到我的算法。
基本上我需要将其翻译成GridGain ...任何建议都将受到高度赞赏。
答案 0 :(得分:0)
创建期货以启动递归计算没有问题。我认为你应该创建为人类期货,因为你有调用,你可以在循环中做到这一点。你试过试试吗?
GridGain Fibonacci的例子就是这里的正确方法。