我对网格世界很陌生,我需要有关如何使用 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 的斐波那契示例,问题是我不知道为 GridFuture 设置什么,因为我在循环中有一个递归调用(我相信我不能创建尽可能多的期货我有递归调用,没有意义)。我已经搜索了更多示例,但无法将任何示例映射到我的算法。
基本上我需要将其翻译成 GridGain ......任何建议将不胜感激。