示例#1
0
 public Bee()
 {
     minVal   = new List <double>();
     maxVal   = new List <double>();
     position = new PointXD();
     fitness  = 0.0;
 }
示例#2
0
        public void nextStep()
        {
            this.bestAreasList = new List <Bee>();
            this.bestAreasList.Add(swarm[0]);  //В начало списка должна добавиться первая пчела

            this.sendedBees = new List <Bee>();

            foreach (Bee bee in swarm)
            {
                //Если пчела находится в пределах уже отмеченного лучшего участка, то ее положение не считаем
                if (bee.otherPatch(bestAreasList, rangeList))
                {
                    bestAreasList.Add(bee);
                    if (bestAreasList.Count == amountOfBestAreas)
                    {
                        break;
                    }
                }
            }

            othersAreasList = new List <Bee>();
            foreach (Bee bee in swarm)
            {
                if (bee.otherPatch(bestAreasList, rangeList) && bee.otherPatch(othersAreasList, rangeList))
                {
                    othersAreasList.Add(bee);
                    if (othersAreasList.Count == amountOfOthersAreas)
                    {
                        break;
                    }
                }
            }
            //Номер очередной отправляемой пчелы. 0-ую пчелу никуда не отправляем
            int beeIndex = 1;

            foreach (Bee bee in bestAreasList)
            {
                beeIndex = sendBees(bee.getPosition(), beeIndex, amountOfBestBees);
            }
            foreach (Bee bee in othersAreasList)
            {
                beeIndex = sendBees(bee.getPosition(), beeIndex, amountOfOthersBees);
            }


            //Оставшихся пчел пошлем куда попадет
            foreach (Bee bee in swarm)
            {
                if (!sendedBees.Contains(bee))
                {
                    bee.goToRandom();
                }
            }

            this.swarm.Sort((o1, o2) => o2.getFitness().CompareTo(o1.getFitness()));
            this.bestPosition = swarm[0].getPosition();
            this.bestFitness  = swarm[0].getFitness();
        }
示例#3
0
        public void goTo(PointXD newPos, List <Double> rangeList)
        {
            // Перелет в окрестность места, которое нашла другая пчела. Не в то же самое место!
            // К каждой из координат добавляем случайное значение
            for (int i = 0; i < newPos.getCoordinates().Count; i++)
            {
                position.setCoordinate(i, newPos.getCoordinate(i) + Point.generateCoordinate(-rangeList[i], rangeList[i]));
            }

            // Проверим, чтобы не выйти за заданные пределы
            checkPosition();
            // Расчитаем и сохраним целевую функцию
            calcFitness();
        }
示例#4
0
        public int sendBees(PointXD pos, int index, int count)
        {
            for (int i = 0; i < count; i++)
            {
                //Чтобы не выйти за пределы улея
                if (index == swarm.Count)
                {
                    break;
                }
                Bee bee = swarm[index];

                if (!(bestAreasList.Contains(bee) || othersAreasList.Contains(bee) || sendedBees.Contains(bee)))
                {
                    //Пчела не на лучших или выбранных позициях
                    bee.goTo(pos, rangeList);
                    sendedBees.Add(bee);
                }
                index++;
            }
            return(index);
        }
示例#5
0
        private double bestFitness;         //Лучшее здоровье пчелы

        public Hive(int scoutBees, int amountOfBestBees, int amountOfOthersBees, int amountOfBestAreas, int amountOfOthersAreas, List <Double> rangeList)
        {
            this.scoutBees           = Math.Min(scoutBees, Max_ScoutBees);
            this.amountOfBestBees    = Math.Min(amountOfBestBees, Max_BestBee);
            this.amountOfOthersBees  = Math.Min(amountOfOthersBees, Max_OthersBee);
            this.amountOfBestAreas   = amountOfBestAreas;
            this.amountOfOthersAreas = amountOfOthersAreas;
            this.bestAreasList       = new List <Bee>();
            this.othersAreasList     = new List <Bee>();
            this.rangeList           = new List <double>(rangeList);
            this.bestPosition        = null;
            this.bestFitness         = int.MinValue;
            this.amountOfBees        = scoutBees + amountOfOthersAreas * amountOfOthersBees + amountOfBestAreas * amountOfBestBees;
            this.swarm = new List <Bee>();
            for (int i = 0; i < amountOfBees; i++)
            {
                this.swarm.Add(new SphereBee());
            }
            this.swarm.Sort((o1, o2) => o2.getFitness().CompareTo(o1.getFitness()));
            this.bestPosition = this.swarm[0].getPosition();
            this.bestFitness  = this.swarm[0].getFitness();
        }
示例#6
0
        public bool otherPatch(List <Bee> beeList, List <Double> rangeList)
        {
            //Проверить находится ли пчела на том же участке, что и одна из пчел в bee_list.
            //rangeList - интервал изменения каждой из координат
            if (beeList.Count == 0)
            {
                return(true);
            }

            foreach (Bee bee in beeList)
            {
                PointXD pos = bee.getPosition();
                for (int i = 0; i < position.getCoordinates().Count; i++)
                {
                    if (Math.Abs(position.getCoordinate(i) - pos.getCoordinate(i)) > rangeList[i])
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }