0

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}}
   }
Anindya Dutta
  • 1,972
  • 2
  • 18
  • 33
Sam Faith
  • 175
  • 5
  • I don't know if you're open to considering other parallel programming models, but this would be very easy to code in [Charm++](http://charmplusplus.org/), or for the shared-memory case, TBB or OpenMP 4.0 – Phil Miller May 29 '15 at 20:33
  • Do you means that I can keep the recursive function and then use OpenMP for example to resolve this problem in parallel ? – Sam Faith May 30 '15 at 14:01
  • Yeah, with OpenMP tasks, I think you can do fork-join style parallelism that's perfect for back-tracking recursive generation. I know you can with TBB or Charm++, using their native mechanisms. – Phil Miller May 30 '15 at 23:53
  • But I want to keep the code in java, is it possible ?! – Sam Faith May 31 '15 at 09:31
  • It's certainly possible - there are even Java MPI bindings. The difference is that you're basically on your own for both helpful software and suitable knowledge - most of the available tooling, and most of the community experience, is in C, C++, and Fotran, that have much heavier parallel computing user bases. – Phil Miller Jun 01 '15 at 19:31

0 Answers0