/// <summary> /// Returns a random hypercube using a rouleteWheel method. /// </summary> /// <returns>The number of the selected hypercube.</returns> public int RouletteWheel() { //Calculate the inverse sum double inverseSum = 0.0; foreach (int aHypercubes in hypercubes) { if (aHypercubes > 0) { inverseSum += 1.0 / (double)aHypercubes; } } //Calculate a random value between 0 and sumaInversa double random = JMetalRandom.NextDouble(0.0, inverseSum); int hypercube = 0; double accumulatedSum = 0.0; while (hypercube < hypercubes.Length) { if (hypercubes[hypercube] > 0) { accumulatedSum += 1.0 / (double)hypercubes[hypercube]; } if (accumulatedSum > random) { return(hypercube); } hypercube++; } return(hypercube); }
public static void ShuffleArray <T>(T[] array) { for (int i = array.Length; i > 1; i--) { int j = JMetalRandom.Next(i); //Swap values T tmp = array[j]; array[j] = array[i - 1]; array[i - 1] = tmp; } }
/// <summary> /// Returns a random hypercube that has more than zero solutions. /// </summary> /// <returns>The hypercube.</returns> public int RandomOccupiedHypercube() { int rand = JMetalRandom.Next(0, occupied.Length - 1); return(occupied[rand]); }