2014-06-30 37 views
0

我对网格世界相当陌生,我需要关于如何使用GridGain处理算法的指导,该算法是递归TravellingSalesman问题。将递归算法转换为GridGain

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 ...任何建议将不胜感激。

回答

0

创建期货以发起递归计算没有问题。我认为你应该创造一个人的未来,因为你有调用,你可以在循环中做到这一点。你试过了吗?

GridGain斐波那契示例在这里完全是正确的方法。