/** * Takes a list of possible location outcomes for each agent and generates all joint location outcomes * @param locOutcomes a list of possible location outcomes * @return all joint location outcomes */ protected List<LocationSetProb> getAllLocationSets(List<List<Location2Prob>> locOutcomes){ List <LocationSetProb> sets = new ArrayList<GridGameStandardMechanics.LocationSetProb>(); Location2 [] locArray = new Location2[locOutcomes.size()]; generateAllLocationSetsHelper(locOutcomes, 0, locArray, 1., sets); return sets; }
/** * This method will recursively generate all possible joint location outcomes for a list of possible outcomes for each agent * @param locOutcomes the list of possible location outcomes for each agent * @param i the index from which to generate possible outcomes in a depth-first manner * @param locArray an array holding the current assignments for a given depth * @param stackedProb the probability of this location set occurring * @param discovered the discovered combinations thus far */ protected void generateAllLocationSetsHelper(List<List<Location2Prob>> locOutcomes, int i, Location2 [] locArray, double stackedProb, List<LocationSetProb> discovered){ if(i == locOutcomes.size()){ //bundle them up List <Location2> locs = new ArrayList<GridGameStandardMechanics.Location2>(locArray.length); Collections.addAll(locs, locArray); LocationSetProb lsp = new LocationSetProb(locs, stackedProb); discovered.add(lsp); return ; } //otherwise we're in recursive step List<Location2Prob> individualOutcomes = locOutcomes.get(i); for(Location2Prob lp : individualOutcomes){ locArray[i] = lp.l; this.generateAllLocationSetsHelper(locOutcomes, i+1, locArray, stackedProb*lp.p, discovered); } }