I'm trying to optimize a process which is to calculate all possible combinations of players to form partitions. To understand my problem, I use the following example.
For exampe we have a set of players N = {1,2,3,4,5}
, this players are regrouped like this {1,2},{3,4},{5}
. It means player 1 will play with player 2 as a single player, and so one. Each group of players has a set of strategies or choices. Each player chooses the group to which he wants to belong, for example: the group {1,2}
has these possibilities {{1,2};{1,2,3,4}}
; i.e the players {1,2}
either choose to stay together or to join the group {3,4}
. The same explanation for the rest of players:
{3,4}=>{{3,4};{3,4,5};{1,2,3,4}}
{5}=>{{5};{3,4,5}}
Now, the group of players choosing the same strategy will form a new group (coalition). For example, group {1,2}
chose the strategy {1,2,3,4}
i.e. the players {1,2}
want to form a new group with players {3,4}
. Players {3,4}
choose the strategy {3,4,5}
, player {5}
choose the strategy {3,4,5}
. The players that choose the same strategy will be grouped together to form a final partition of players like this: {1,2},{3,4,5}
; players {3,4,5}
have chosen the same strategy, so they are grouped together, players {1,2}
chose a different strategy so they stay alone. I have programmed this process as a recursive function to get all admissible partitions of players. Another problem here: my function generate all possible partitions and I get only the admissibles which takes a lot of time.
Now my question is if it is possible to resolve this problem without using a recursive function; i.e. in sequential form in order to use parallelism with JCUDA, especially when we have many players and so many partitions. What is the ideal solution here, MPI or JCUDA?
import java.util.ArrayList;
import java.util.Hashtable;
public class Partitions {
public Hashtable<ArrayList<Integer>, ArrayList<ArrayList<Integer>>> HashTab = new Hashtable<ArrayList<Integer>,ArrayList<ArrayList<Integer>>>(); // The key is the chosen strategy(coalition) and the value is the group of players have chosen the same coalition(strategy).
// create partitions combination
public void CalculStrategiesCombination (int index, ArrayList<ObjectsCoalitions> PlayerCoalitions, int K,int L) {
index = index +1;
if(index < PlayerCoalitions.size()) {
for(int j =0; j< PlayerCoalitions.get(index).Coaltions.size(); j++) {
if(!this.HashTab.containsKey(PlayerCoalitions.get(index).Coaltions.get(j))) {
ArrayList<ArrayList<Integer>> e = new ArrayList<ArrayList<Integer>>();
e.add(PlayerCoalitions.get(index).Objects);
this.HashTab.put(PlayerCoalitions.get(index).Coaltions.get(j), e);
} else {
this.HashTab.get(PlayerCoalitions.get(index).Coaltions.get(j)).add(PlayerCoalitions.get(index).Objects);
}
if(this.HashTab.size()<K) {
CalculStrategiesCombination (index, PlayerCoalitions,K,L);
}
if(this.HashTab.get(PlayerCoalitions.get(index).Coaltions.get(j)).size()==1) {
this.HashTab.remove(PlayerCoalitions.get(index).Coaltions.get(j));
} else {
this.HashTab.get(PlayerCoalitions.get(index).Coaltions.get(j)).remove(this.HashTab.get(PlayerCoalitions.get(index).Coaltions.get(j)).size()-1);
}
}
} else {
// Treatment.......
}
}
}
public class ObjectsCoalitions {
public ArrayList<Integer>Objects = new ArrayList<Integer>(); // for example Objects = {1,2}
public ArrayList<ArrayList<Integer>> Coaltions = new ArrayList<ArrayList<Integer>> (); // coalitions (strategis)={{1,2};{1,2,3,4}}
}