public void CoalitionMaxTest()
        {
            Coalition c = new Coalition(5);
            ValueFunction vf = new ValueFunction();
            int[] materials = new int[5];
            int max = 0;
            materials[0] = 1;
            materials[1] = 5;
            materials[2] = 3;
            materials[3] = 8;
            materials[4] = 4;
            /*int[] materials2 = new int[3];
            materials[0] = 1;
            materials[1] = 3;
            materials[2] = 5; */
            /*int[] materials3 = new int[4];
            materials[0] = 10;
            materials[1] = 9;
            materials[2] = 3;
            materials[3] = 4;*/
            Dynamic_Games.coop.models.Player p1 = new Dynamic_Games.coop.models.Player(vf, materials);
            //Dynamic_Games.coop.models.Player p2 = new Dynamic_Games.coop.models.Player();
            //Dynamic_Games.coop.models.Player p3 = new Dynamic_Games.coop.models.Player();
            c.addPlayer(p1);
            //c.addPlayer(p2);
            //c.addPlayer(p3);
            p1.Materials = materials;
            //p2.Materials = materials2;
            //p3.Materials = materials3;

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] > max)
                {
                    max = materials[i];
                }
            }
            int res = c.calculateMaximumValue();
            Assert.AreEqual(max, res);
        }
 //returns the maximum value of a coalition structure
 private Double ValueOfCoalitionStructure(Coalition[] cs)
 {
     Double result = 0;
     foreach (var c in cs)
     {
         result += c.getMaximumValue();
     }
     return result;
 }
 //calculate l, combinations of Coalitions
 private List<Coalition>[] getCombinations(int n, Player[] players, int m)
 {
     var result = new List<Coalition>[n];
     var stack = new int[n];
     for (int i = 1; i <= n; i++)
     {
         stack[0] = -1;
         result[i - 1] = new List<Coalition>();
         int l = 0;
         while (l >= 0)
         {
             stack[l]++;
             if (stack[l] >= n)
             {
                 l--;
             }
             else
             {
                 if (l == i - 1)
                 {
                     Coalition coalition = new Coalition(m);
                     for (var j = 0; j < i; j++)
                     {
                         coalition.addPlayer(players[stack[j]]);
                     }
                     result[i - 1].Add(coalition);
                 }
                 else
                 {
                     l++;
                     stack[l] = stack[l - 1];
                 }
             }
         }
     }
     return result;
 }
 private void scanAndSearch()
 {
     //Pi = coalitions structures which contains i coalition
     var valueOfP1 = ValueOfCoalitionStructure(l[0]);
     var valueOfPn = ValueOfCoalitionStructure(l[n - 1]);
     cs = l[0];  //best coalition structure found so far
     var vcs = valueOfP1;  //value of best coalition structure found so far
     if (valueOfP1 < valueOfPn)
     {
         cs = l[n - 1];
         vcs = valueOfPn;
     }
     addtoFoundStructures();
     var maxs = new Double[n]; //maximum value of l[s]
     var avgs = new Double[n]; //average value of l[s]
     var sums = new Double[n]; //sum value of l[s]
     var vmax = Double.MinValue; //maximum of current coalitions structure formed by 2 complementary coalitions
     var xmax = 0; // index of vmax
     for (var s = 1; s <= n / 2; s++)//scan all complementary coalitions
     {
         Console.WriteLine(s);
         var s1 = s - 1;
         var s2 = (n - s) - 1;
         var end = l[s1].Length; // length of coalitions containing s player
         if (s1 == s2)//same list
         {
             end = end / 2;
         }
         maxs[s1] = Double.MinValue;
         maxs[s2] = Double.MinValue;
         sums[s1] = 0;
         for (var x = 1; x <= end; x++)
         {
             var x1 = x - 1;
             var x2 = (l[s1].Length - x + 1) - 1;
             var v1 = l[s1][x1].getMaximumValue(); //value of coalition ls1x1
             var v2 = l[s2][x2].getMaximumValue(); //value of coalition ls2x2
             if (vmax < v1 + v2)
             {
                 vmax = v1 + v2;
                 xmax = x;
             }
             if (maxs[s1] < v1)
             {
                 maxs[s1] = v1;
             }
             if (maxs[s2] < v2)
             {
                 maxs[s2] = v2;
             }
             sums[s1] += v1;
             sums[s2] += v2;
             if (stop) return;
         }
         var xmax1 = xmax - 1;
         var xmax2 = (l[s1].Length - xmax + 1) - 1;
         var currentCS = new Coalition[] { l[s1][xmax1], l[s2][xmax2] }; // create coalition Structure of the 2 complementary coalitions
         var vcurrentCS = ValueOfCoalitionStructure(currentCS);//value of currentCS
         if (vcs < vcurrentCS)// found a new best coalition structure
         {
             cs = currentCS;
             addtoFoundStructures();
             vcs = vcurrentCS;
         }
         avgs[s1] = sums[s1] / l[s1].Length;
         avgs[s2] = sums[s2] / l[s2].Length;
         if (stop) return;
     }
     setG = generateNumbersAllPartitionExcept(n, 2);
     var xxxxx = setG.Count;
     //set of possible integer partitions of n except that contains 2 parts(because we just scanned them)
     maxOfSetG = new List<Double>();
     avgOfSetG = new List<Double>();
     for (var i = 0; i < setG.Count; i++)
     {
         int[] g = (int[])setG[i];
         Double maxg = 0;
         Double avgg = 0;
         for (var j = 0; j < g.Length; j++)
         {
             maxg += maxs[g[j] - 1];
             avgg += avgs[g[j] - 1];
             if (stop) return;
         }
         maxOfSetG.Add(maxg);
         avgOfSetG.Add(avgg);
         if (stop) return;
     }
     var ub = Math.Max(vcs, maxOfSetG.Max()); //calculate upper bound
     var lb = Math.Max(vcs, avgOfSetG.Max()); //calculate lower bound
     PruneResult pruneResult = prune(setG, maxOfSetG, avgOfSetG, lb);
     setG = pruneResult.setG;
     var lx = setG.Count;
     maxOfSetG = pruneResult.maxOfSetG;
     avgOfSetG = pruneResult.avgOfSetG;
     if (vcs != 0) beta = Math.Min(n / 2, ub / vcs);
 }