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.
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.
So with 3 items, and
Low = 2, 2, 2
high = 6, 6, 6
Target = 10
The result is:
2 2 4
2 3 3
2 4 2
3 2 3
3 3 2
4 2 2
Here is the method that does the work:
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);
}
}
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?
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.
For instance, instead of
L:[2,2,2] H:[6,6,6]execute