public double[] GenerateRandomAntennaPositions(AntennaArray antennaArray) { double[] antennaPositions = new double[antennaArray.N_antennae]; // Always add the contant antenna in the furtherest position to the right antennaPositions[antennaPositions.Length - 1] = antennaArray.MaximumArrayPosition; bool isValidGeneration = false; Random random = new Random(); while (isValidGeneration == false) { for (int index = 0; index <= antennaPositions.Length - 2; index++) { double randomNum = random.NextDouble() * (antennaArray.MaximumArrayPosition - AntennaArray.MIN_SPACING) + AntennaArray.MIN_SPACING; antennaPositions[index] = randomNum; } // Exit clause if (antennaArray.Is_valid(antennaPositions)) { isValidGeneration = true; } } return(antennaPositions); }
private bool IsPersonalBest(double[] personalBestPosition, double[] currentPosition) { double evaluationValueForCurrent = Math.Abs(antennaArray.Evaluate(currentPosition)); double evaluationValueForBest = Math.Abs(antennaArray.Evaluate(personalBestPosition)); if (evaluationValueForCurrent > evaluationValueForBest || !antennaArray.Is_valid(currentPosition)) { return(false); } return(true); }