是否有可能分配一个递归算法? [英] Is it possible to distribute a recursive algorithm?

查看:95
本文介绍了是否有可能分配一个递归算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能确定如何分配递归程序。现在它的递归和运行作为一个单独的程序,但我的目标是发布这个程序,其他机器谁只生成数据的一个子集。

I’m unsure how to distribute a recursive program. Right now its recursive and runs as a single program but my goal is distribute this program to other machines who only generate a subset of the data.

下面的背景上的程序。予给它一个目标(在本例10)中,用最小/最大的权重的项目的列表和它返回每个的组合

Here’s background on the program. I give it a target (in this case 10) and a list of items with min/max weights and it returns the combinations of each.

因此​​,与3项,以及

So with 3 items, and

Low = 2, 2, 2
high = 6, 6, 6
Target = 10

结果是:

2 2 4
2 3 3
2 4 2
3 2 3
3 3 2
4 2 2

下面是做工作的方法:

void distribute (int i, int [] low, int [] high, final int rest, int [] sizes) {
    // System.out.println (i + " " + rest + " " + sizes);
    if (i == sizes.length - 1) {
        if (rest < high [i]) {
            sizes[i] = rest;
            result.add (Arrays.copyOf (sizes, sizes.length));
        }
    }
    else
        for (int c = 0;
             c <= java.lang.Math.min (high [i] - low [i], rest);
             ++c) {
            sizes [i] = c;
            distribute (i + 1, low, high, rest - c, sizes);
        }
}

我想知道如果任何人有一个如何分配输出,所以任何想法,在上面的例子中,如果我有3台服务器每个服务器只生成,而不必产生整个事情两个独特的条目。再说,事先我知道会有6条结果,并希望2分发给每一个机器,我怎么能做到这一点。是否有可能,如果是什么逻辑?

I’m wondering if anyone has any ideas of how to distribute the output so, in the example above, if I have 3 servers each server only generates 2 unique entries instead of having to generate the entire thing. Say, in advance I know there will be 6 results and want 2 to be distributed to each machine how can I do that. Is it possible and if so what’s the logic?

如果有帮助,这里的整个程序: http://pastebin.com/RikqPgKh

If it helps, here's the entire program: http://pastebin.com/RikqPgKh

推荐答案

我想你想在几台机器上运行的算法,然后团结的结果。你只需要拆分的执行。这应该不是太难的参数已经限制结果。

I figure you want to run the algorithm on several machines and then unite the results. You just have to split the execution. This should not be too hard as the parameters already limit the results.

有关实例,而不是 L:[2,2,2] H:[6,6,6] 执行

L:[2,2,2] H:[3,6,6]
L:[4,2,2] H:[5,6,6]
L:[6,2,2] H:[6,6,6]

这篇关于是否有可能分配一个递归算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆