コード例 #1
0
        public void UpdatePopulation(bool saveFitnessLog = false)
        {
            if (saveFitnessLog)
            {
                GlobalBestLog = new List <double>();
            }

            for (int i = 0; i < Bee.FoodSourceList.Count; i++)
            {
                EmployedParticleList[i].DeployFoodSourceForParticle(i);
                ScoutParticleList[i].DeployFoodSourceForParticle(i);
            }

            for (int i = 0; i < Parameters.ITERATION_AMOUNT; i++)
            {
                Bee.CalculateFoodSourceFitness();
                Bee.CalculateFoodSourceProbability();
                Bee.SortFoodSourceByProbability();

                EmployedParticleList.ForEach(x =>
                {
                    x.SendEmployedBees();
                    x.UpdateFitness();
                });

                OnlookerParticleList.ForEach(x =>
                {
                    x.SendOnlookerBees();
                    x.UpdateFitness();
                });

                ScoutParticleList.ForEach(x =>
                {
                    x.SendScoutBees();
                });

                if (saveFitnessLog)
                {
                    GlobalBestLog.Add(Bee.GlobalBestFitness);
                }

                Console.WriteLine(i + " " + Bee.GlobalBestFitness);
            }
        }
コード例 #2
0
        public Swarm(EFunction function)
        {
            Bee.ClearStaticFields();

            int employedBees = (Parameters.PARTICLE_AMOUNT * Parameters.EMPLOYED_BEE_AMOUNT / 100);

            employedBees = Math.Min(Parameters.INITIAL_FOOD_SOURCES, employedBees);

            int scoutBees = (Parameters.PARTICLE_AMOUNT * Parameters.SCOUT_BEE_AMOUNT / 100);

            scoutBees = Math.Min(Parameters.INITIAL_FOOD_SOURCES, scoutBees);

            int onlookerBees = Parameters.PARTICLE_AMOUNT - employedBees - scoutBees;

            OnlookerParticleList = Bee.CreateSwarm(function, EBee.Onlooker, onlookerBees);
            ScoutParticleList    = Bee.CreateSwarm(function, EBee.Scout, scoutBees);
            EmployedParticleList = Bee.CreateSwarm(function, EBee.Employed, employedBees);

            Bee.CreateRandomFoodSources();
        }