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); }
public SwarmController(RandomValidPositionGenerator randomValidPositionGenerator, AntennaArray antennaArray, double[] initialGlobalBest) { this.randomValidPositionGenerator = randomValidPositionGenerator; this.antennaArray = antennaArray; globalBestPosition = initialGlobalBest; globalBestEvaluationValue = antennaArray.Evaluate(globalBestPosition); swarm = new List <Particle>(); random = new Random(); }
public void InitialiseSwarm(int numberOfParticlesInSwarm, AntennaArray antennaArray) { for (int index = 0; index <= numberOfParticlesInSwarm - 1; index++) { double[] initialPosition = randomValidPositionGenerator.GenerateRandomAntennaPositions(antennaArray); double[] initialGoalPosition = randomValidPositionGenerator.GenerateRandomAntennaPositions(antennaArray); double[] initialVelocity = GenerateInitialVelocity(initialPosition, initialGoalPosition); swarm.Add(new Particle(initialPosition, initialVelocity, initialPosition)); UpdateGlobalBestFromPersonalBest(initialPosition); } }
public void RunApplication() { AntennaArray antennaArray = new AntennaArray(3, 90); RandomValidPositionGenerator antennaPlacementGenerator = new RandomValidPositionGenerator(antennaArray); SwarmController swarmController = new SwarmController(antennaPlacementGenerator, antennaArray, antennaPlacementGenerator.GenerateRandomAntennaPositions(antennaArray)); swarmController.InitialiseSwarm(1000, antennaArray); var now = DateTime.Now; while (DateTime.Now < now.AddMilliseconds(timeToExecuteFor)) { swarmController.UpdateSwarm(); } }
public RandomValidPositionGenerator(AntennaArray antennaArray) { AntennaArray = antennaArray; }