public void SendSoldierBee()
    {
        _sentBeeNumber = Convert.ToInt32(_soldierBtn._input);
        //Actual sending bees....

        _initialPosition = _uiManager.gameObjects[0];
        _targetPosition  = _uiManager.gameObjects[1];
        Bee _targetBee  = _targetPosition.GetComponent <Bee>();
        Bee _initialBee = _initialPosition.GetComponent <Bee>();

        if (_targetPosition.tag == "Resource")
        {
            Debug.Log("Soldiers can't be sent to the resource.");
            return;
        }
        else if (_sentBeeNumber <= _initialBee.GetSoldierBeeNumber())
        {
            _initialBee.SetSoldierBeeNumber(_initialBee.GetSoldierBeeNumber() - _sentBeeNumber);
            Debug.Log("Sent Bee number:" + _sentBeeNumber);

            _targetBee.SetSoldierBeeNumber(_targetBee.GetSoldierBeeNumber() + _sentBeeNumber);


            Debug.Log("sent bees: " + _sentBeeNumber);
        }
        else
        {
            Debug.Log("Soldier bee sent error:" + _sentBeeNumber);
        }
    }
Esempio n. 2
0
 public static void ActivateBee(Bee b)
 {
     if (!activeBees.Contains(b))
     {
         activeBees.Add(b);
     }
 }
Esempio n. 3
0
    private void AddItem(Bee bee)
    {
        //проверка в биистеарий
        var beeItem = new BeeItem(bee);

        list.Add(beeItem);
    }
Esempio n. 4
0
        public static void Detection(Bee _bee, List <Honey> _honeys)
        {
            IntersectionManager intersectionManager = new IntersectionManager();

            foreach (Sensor sensor in _bee.Sensors)
            {
                sensor.State = 0;
                foreach (Honey honey in _honeys)
                {
                    if (intersectionManager.LineIntersectsRect(sensor.Display, honey.Rectangle))
                    {
                        GeometricHelper.GetClosestDistance(sensor, CalculateDistance(new Point(sensor.Display.X1, sensor.Display.Y1), new Point(intersectionManager.IntersectionX, intersectionManager.IntersectionY)));
                        sensor.State = 1; // ==> Avec un événement ça aurait été plus propre
                        //Console.WriteLine("Distance sensor object = " + sensor.DistanceToObject +
                        //    " intersection (X;Y) = (" + intersectionManager.IntersectionX + ";" + intersectionManager.IntersectionY + ")" +
                        //    " sensorcoor (X;Y) = (" + sensor.Display.X1 + ";" + sensor.Display.Y1 + ")");
                    }
                }

                if (sensor.State == 1)
                {
                    sensor.Display.Stroke = Brushes.Red;
                }
                else
                {
                    sensor.Display.Stroke = Brushes.Black;
                    if (sensor.DistanceToObject != SensorConfig.SENSOR_LENGHT)
                    {
                        sensor.DistanceToObject = SensorConfig.SENSOR_LENGHT;
                    }
                }
            }
        }
Esempio n. 5
0
 public static void AddBee(Bee b)
 {
     if (!beeList.Contains(b))
     {
         beeList.Add(b);
     }
 }
Esempio n. 6
0
        public void AddBeeToSwarm(Bee bee)
        {
            Swarm.Add(bee);
            _interactables.RemoveInteractable(bee);

            bee.SetPlayerSkin(this);
        }
Esempio n. 7
0
 private void SetLifeStatus(ref Bee bee)
 {
     if (bee.Health < bee.HealthResistance)
     {
         bee.IsDead = true;
     }
 }
Esempio n. 8
0
    /// <summary>
    /// 主循环
    /// </summary>
    void Update()
    {
        if (this.list == null)
        {
            return;
        }
        int count = this.list.Count;

        for (int i = 0; i < count; ++i)
        {
            Bee bee = this.list[i];
            if (bee != null)
            {
                bee.vx += Random.Range(0f, 1f) * this.rangeX - this.rangeX * .5f;
                bee.vy += Random.Range(0f, 1f) * this.rangeY - this.rangeY * .5f;
                bee.vz += Random.Range(0f, 1f) * this.rangeZ - this.rangeZ * .5f;
                bee.transform.localPosition = new Vector3(bee.transform.localPosition.x + bee.vx,
                                                          bee.transform.localPosition.y + bee.vy,
                                                          bee.transform.localPosition.z + bee.vz);
                bee.vx *= this.friction;
                bee.vy *= this.friction;
                bee.vz *= this.friction;
            }
        }
    }
        public void DamageInputAmountTest1()
        {
            int damageAmount = -1;
            Bee bee          = new Bee();

            Assert.ThrowsException <System.ArgumentOutOfRangeException>(() => bee.Damage(damageAmount));
        }
 //pass a negative to take away from quantity
 public void addToBeeQuantity(Texture texture, int amount)
 {
     foreach (GameObject bee in bees)
     {
         if (bee.GetComponentInChildren <RawImage>().texture == texture)
         {
             Bee comp = bee.GetComponentInChildren <Bee>();
             int temp = comp.quantity;
             if (texture.name == "diligentWorker" || texture.name == "exoticWorker")           //infinity exceptionss
             {
                 comp.quantity = 1;
             }
             else if ((temp += amount) < 0)              //if the amount will be less than 0
             {
                 comp.quantity = 0;
             }
             else if (comp.quantity == -1 && amount > 1)            //for if >1 bees are added the first time a bee is discovered
             {
                 comp.quantity += (amount + 1);
             }
             else if (comp.quantity == -1)                //if 1 is added the first time a bee is discovered
             {
                 comp.quantity = 1;
             }
             else                   //otherwise just regularly add
             {
                 comp.quantity += amount;
             }
             DisplayBee(bee, comp);
         }
     }
 }
Esempio n. 11
0
    void OnCollisionEnter(Collision c)
    {
        if (c.transform.tag.Equals("Bee") || c.transform.tag.Equals("Wall"))
        {
            Bounce(c.relativeVelocity.magnitude);
            Bee b = c.gameObject.GetComponent <Bee>();

            if (b != null)
            {
                if (b.lastBeeHit == this)
                {
                    return;
                }

                int   p          = Mathf.FloorToInt((float)baseScore * multiplier * b.multiplier);              /// SCORE
                Score scoreSpawn = Instantiate(scorePrefab);
                scoreSpawn.transform.position = c.GetContact(0).point;
                //scoreSpawn.transform.position = transform.position;
                scoreSpawn.SetPoints(p);
                ScoreController.AddScore(p);
                AddMultiplier();

                lastBeeHit   = b;
                b.lastBeeHit = this;
            }
        }
    }
    public void addBeeToApaiary(GameObject obj)
    {
        Bee currentBee = obj.GetComponentInChildren <Bee>();

        if (currentBee.quantity > 0)
        {
            Texture texture = obj.GetComponentInChildren <RawImage>().texture;
            if (beeSlotOne.texture.name == "flowerBlue")
            {
                beeSlotOne.GetComponentInChildren <BeeSlotScript>().addBee(beeSlotOne, texture);
            }
            else if (beeSlotTwo.texture.name == "flowerBlue")
            {
                beeSlotTwo.GetComponentInChildren <BeeSlotScript>().addBee(beeSlotTwo, texture);
            }
            else
            {
                return;
            }

            //remove one from quantity and update the text
            addToBeeQuantity(obj.GetComponentInChildren <RawImage>().texture, -1);
            obj.GetComponentInChildren <Text>().text = currentBee.quantity.ToString();            //can probably use DisplayBee() here but its not super important
        }
        else
        {
            return;
        }
    }
Esempio n. 13
0
        public static UInt32 ChooseNextNode(Bee bee, UInt32 graphDimension)
        {
            List <UInt32> nodeList = new List <UInt32>();

            for (UInt32 i = 0; i < graphDimension; i++)
            {
                nodeList.Add(i);
            }

            foreach (UInt32 node in bee.path)
            {
                nodeList.Remove(node);
            }

            foreach (UInt32 node in nodeList)
            {
                Console.Write(node);
                Console.Write(", ");
            }
            Console.WriteLine("___________________");

            int index = rand.Next(0, nodeList.Count);

            UInt32 nextNode = nodeList[index];

            return(nextNode);
        }
 public void AddBeeToBackpack(string clicked)
 {
     //now remove graphic and unenable them again
     //add to quantity of bee with same texture
     if (clicked == "one")
     {
         Bee     comp = beeResultOne.GetComponentInChildren <Bee>();
         Texture text = beeResultOne.GetComponentInChildren <RawImage>().texture;
         addToBeeQuantity(text, 1);
         resultOne.enabled       = false;
         resultOneButton.enabled = false;
         //HERE TURN OFF BUTTON
         //TODO: for infinibee bug - maybe enabled is not enough, might have to unset onclick listener
     }
     else if (clicked == "two")
     {
         Bee     comp = beeResultTwo.GetComponentInChildren <Bee>();
         Texture text = beeResultTwo.GetComponentInChildren <RawImage>().texture;
         addToBeeQuantity(text, 1);
         resultTwo.enabled       = false;
         resultTwoButton.enabled = false;
     }
     else if (clicked == "three")
     {
         Bee     comp = beeResultThree.GetComponentInChildren <Bee>();
         Texture text = beeResultThree.GetComponentInChildren <RawImage>().texture;
         addToBeeQuantity(text, 1);
         resultThree.enabled       = false;
         resultThreeButton.enabled = false;
     }
 }
Esempio n. 15
0
            public Hive(int beesInactive, int beesActive, int beesScouting, int visitsMax, int iterationsMax)
            {
                _visitsMax     = visitsMax;
                _iterationsMax = iterationsMax;

                _beesInactive = beesInactive;
                _beesActive   = beesActive;
                _beesScouting = beesScouting;
                _beesTotal    = beesInactive + beesScouting + beesActive;

                _bees       = new Bee[_beesTotal];
                _bestMatrix = new Matrix();
                _bestScore  = Bee.SuperScout(_bestMatrix, double.MaxValue, 10000);

                // these bees are not active
                _indicesInactive = new int[beesInactive];

                int next = 0;

                for (int i = 0; i < beesInactive; i++)
                {
                    _bees[next++]       = NewBee(BeeState.Inactive);
                    _indicesInactive[i] = i;
                }

                for (int i = 0; i < beesActive; i++)
                {
                    _bees[next++] = NewBee(BeeState.Active);
                }

                for (int i = 0; i < beesScouting; i++)
                {
                    _bees[next++] = NewBee(BeeState.Scouting);
                }
            }
Esempio n. 16
0
 public void StartChase(Bird bird, Bee bee)
 {
     this.bird = bird;
     this.bee  = bee;
     chaseOn   = true;
     Chase(bird, bee);
 }
Esempio n. 17
0
        public void ManageOutputsOfNetwork(Bee bee)
        {
            List <double> inputs = new List <double>();

            foreach (Sensor sensor in bee.Sensors)
            {
                inputs.Add((sensor.DistanceToObject / SensorConfig.SENSOR_LENGHT)); // the division allows to keep the value between [0-100] which allows to be easely between [0-6] for a sigmoid -> ]0-1[
            }
            List <double> coord = bee.NeuralNetwork.ExecuteNetwork(inputs);

            //foreach(double d in coord)
            //{
            //    Console.WriteLine("Bee " + bee.Number + " =====> " + d);
            //}

            // coord[0] = speed
            // coord[1] = left
            // coord[2] = right

            bee.X = bee.X + Math.Cos(bee.Angle) * ApplicationConfig.SPEED_RATE * coord[0];
            bee.Y = bee.Y + Math.Sin(bee.Angle) * ApplicationConfig.SPEED_RATE * coord[0];

            // rotationRate > 0 ==> angle[T0] < angle[T] ==> on trigonometric we are going to the left
            // rotationRate < 0 ==> angle[T0] < angle[T] ==> on trigonometric we are going to the right
            double rotationRate = coord[1] - coord[2];

            bee.Angle = bee.Angle + rotationRate * Math.PI / 18;

            //Console.WriteLine("Bee angle : " + bee.Angle + ", Bee corrd[1] = " + coord[0]);
        }
Esempio n. 18
0
        public void GenerateIA()
        {
            for (int i = 0; i < ApplicationConfig.NUMBER_OF_AI; i++)
            {
                Bee bee = new Bee();

                bee.Number = i;

                bee.X = ApplicationConfig.AI_X;
                bee.Y = ApplicationConfig.AI_Y;

                bee.NeuralNetwork = new MyNeuralNetwork(NeuralNetworkConfig.NUMBER_OF_INPUTS,
                                                        NeuralNetworkConfig.NEURON_ON_EACH_LAYER,
                                                        RandomCoord);
                bee.NeuralNetwork.GenerateNeurons();
                bee.NeuralNetwork.InitWeightsOnNetwork();

                this.Bees.Add(bee);
            }

            for (int i = 0; i < ApplicationConfig.NUMBER_OF_AREA; i++)
            {
                this.Honeys.Add(new Honey(RandomCoord.NextDouble() * ApplicationConfig.MAX_WIDTH_PANEL, RandomCoord.NextDouble() * ApplicationConfig.MAX_HEIGHT_PANEL));
            }
        }
Esempio n. 19
0
    public void addWorker()
    {
        Bee bee = Instantiate(workerPrefab) as WorkerBee;

        bee.transform.SetPositionAndRotation(respawner.position, Quaternion.identity);
        createBee(bee);
    }
Esempio n. 20
0
 /// <summary>
 /// 添加蜜蜂
 /// </summary>
 /// <param name="bee">蜜蜂对象</param>
 public void addBee(Bee bee)
 {
     if (this.list.IndexOf(bee) == -1)
     {
         this.list.Add(bee);
     }
 }
Esempio n. 21
0
        public void GenerateTrainedIA()
        {
            Bee bee = new Bee();

            bee.X = ApplicationConfig.AI_X;
            bee.Y = ApplicationConfig.AI_Y;

            bee.NeuralNetwork = new MyNeuralNetwork(NeuralNetworkConfig.NUMBER_OF_INPUTS,
                                                    NeuralNetworkConfig.NEURON_ON_EACH_LAYER,
                                                    RandomCoord);
            bee.NeuralNetwork.GenerateNeurons();

            // trained weights
            List <double> weights = new List <double> {
                -0.255130714855683, -0.955834815258083, -0.783108153279455, 0.592491513394048, -0.784140992343491, 0.98408665926386, 0.967099378335802, -0.442148500328021, -0.632802178912238, -0.985582368907324, 0.734380449044695, 0.889736337070231, -0.96948987616668, -0.0441478486378434, -0.424890779622314, -0.875818291155537, -0.49081501294431, 0.928610841244744, -0.733780128757367, 0.901407715352908, 0.422541373140431, -0.859910866180393, -0.00569380400967496, -0.319530605021646, -0.153766952526647, -0.787081397039388, -0.351918173652104, 0.0480898516476573, 0.776869147912073, 0.146528345135287, 0.533762837077381, 0.653492134834403, 0.978287229769997, -0.545320124619324, 0.629172365008468, 0.701040347898863, 0.792735186774626, 0.88193937338979, -0.88227203203471, -0.593355259203052, -0.945778405268573, 0.00502261147136922, -0.613798863074649, 0.736431643709741, 0.296256835710377, -0.0655902545273259, 0.569690959793372, -0.803169875779734, 0.713029795192662, -0.809193837367554, -0.168522292826568, -0.0133588630768279, -0.776029413461699, 0.456884687513525, 0.638324160891736, -0.197333722467224, 0.305246607076957, 0.900872538285736, -0.199626027233724, -0.710890946775158, 0.953108638037512, 0.805236903394217, 0.735971083741622, 0.00928217964679104, -0.742394056982544, 0.885624664782372, 0.958955365679672, 0.866589023669525, -0.911685968708101, -0.561104091611274, 0.89031102596331, 0.953664542154253, 0.379058851571315, -0.616981185794334, -0.754791849644292, 0.801609388460223, 0.306108725865422, -0.331175773093093, -0.577235685930231, -0.485617822262281, 0.667881177583654
            };

            bee.NeuralNetwork.CopyWeightsOnNetwork(weights);

            this.Bees.Add(bee);

            for (int i = 0; i < ApplicationConfig.NUMBER_OF_AREA; i++)
            {
                this.Honeys.Add(new Honey(RandomCoord.NextDouble() * ApplicationConfig.MAX_WIDTH_PANEL, RandomCoord.NextDouble() * ApplicationConfig.MAX_HEIGHT_PANEL));
            }
        }
Esempio n. 22
0
        public static double FitnessCheck(FoodSource foodSource, Bee bee)
        {
            var geo = foodSource.Location.GeoCoordinate;

            //Console.WriteLine(string.Format("{0:0.##}, {1:0.##}", geo.Latitude, geo.Longitude));
            return(random.NextDouble());
        }
Esempio n. 23
0
 public void UpdateUI()
 {
     // Change order of pictures
     // Change order of health
     for (int i = 0; i < numBees; i++)
     {
         if (bees[i] == null)
         {
             beeNames [i].text    = "";
             beeHealths [i].text  = "";
             beeImages [i].sprite = blankSprite;
             continue;
         }
         Bee   b     = bees [i].GetComponent <Bee> ();
         float curHP = b.GetCurHealth();
         float maxHP = b.GetMaxHealth();
         beeHealths [i].text  = curHP.ToString() + "/" + maxHP.ToString();
         beeNames [i].text    = b.GetName();
         beeImages [i].sprite = bees [i].GetComponent <SpriteRenderer> ().sprite;
         if (i == curBee)
         {
             GameObject.Find("Bee" + i.ToString() + "Icon").GetComponent <RectTransform> ().sizeDelta = (new Vector2(75, 75));
         }
         else
         {
             GameObject.Find("Bee" + i.ToString() + "Icon").GetComponent <RectTransform> ().sizeDelta = (new Vector2(50, 50));
         }
     }
 }
    void _SpawnBee(Vector3 pos, int team)
    {
        Bee bee;

        if (pooledBees.Count == 0)
        {
            bee = new Bee();
        }
        else
        {
            bee = pooledBees[pooledBees.Count - 1];
            pooledBees.RemoveAt(pooledBees.Count - 1);
        }
        bee.Init(pos, team, Random.Range(minBeeSize, maxBeeSize));
        bee.velocity = Random.insideUnitSphere * maxSpawnSpeed;
        bees.Add(bee);
        teamsOfBees[team].Add(bee);

        if (beeMatrices[activeBatch].Count == beesPerBatch)
        {
            activeBatch++;
            if (beeMatrices.Count == activeBatch)
            {
                beeMatrices.Add(new List <Matrix4x4>());
                beeColors.Add(new List <Vector4>());
            }
        }
        beeMatrices[activeBatch].Add(Matrix4x4.identity);
        beeColors[activeBatch].Add(teamColors[team]);
    }
Esempio n. 25
0
            public BeePrototype _Clone()
            {
                Bee bee = new Bee(this);

                bee.gens.Clone = true;
                return(bee);
            }
Esempio n. 26
0
        /// <summary>
        /// Create an animal object of a species (Bee,Butterfly) of Insect cateogry.
        /// </summary>
        /// <param name="Species">Species: Bee, Butterfly, etc.</param>
        /// <returns>Object of the Species type.</returns>
        /// <remarks></remarks>
        public static Insect CreateInsect(InsectSpecies Species)
        {
            Insect animalObj = null;        //type not known at this time

            //type determined by late binding
            switch (Species)
            {
            case InsectSpecies.Bee:
                animalObj = new Bee();               //Late binding
                break;

            //Continue with the rest
            case InsectSpecies.Butterfly:
                animalObj = new Butterfly();        //Late binding
                break;

            default:
                Debug.Assert(false, "To be completed!");
                break;
            }

            //Set the category
            animalObj.Category = CategoryType.Insect;

            return(animalObj);     //return the created animal object.
        }
Esempio n. 27
0
 private static void GenPoisen(Hive hive, Bee bee, Flower flower)
 {
     if (bee.Health == 0)
     {
         hive.Pollen   += 0;
         flower.pollen -= 0;
     }
     else
     if (flower.pollen == 0)
     {
         hive.Pollen += 0;
     }
     else
     if (flower.poison == true)
     {
         bee.Health     = 0;
         hive.Pollen   += 0;
         flower.pollen -= 0;
     }
     else
     {
         flower.pollen -= 10;
         hive.Pollen   += 10;
     }
 }
Esempio n. 28
0
            // solve it
            public void Solve()
            {
                int progressIterations = 1000;
                int iterations         = 0;

                while (iterations < _iterationsMax)
                {
                    for (int i = 0; i < _beesTotal; i++)
                    {
                        var bee = _bees[i];

                        if (bee._state == BeeState.Active)
                        {
                            bee.DoActive(this, i);
                        }
                        else if (bee._state == BeeState.Scouting)
                        {
                            bee.DoScout(this, i);
                        }
                    }
                    iterations++;

                    // emit progress
                    if (iterations % progressIterations == 0)
                    {
                        _bestScore = Bee.SuperScout(_bestMatrix, _bestScore, 1000);

                        msg.AppendFormat("Iterations:{0} Score: {1}  ss:{2} wag:{3}\n", iterations, _bestScore, _superscoutsCount, _wagglesCount);

                        _wagglesCount     = 0;
                        _superscoutsCount = 0;
                    }
                }
            }
        public void DamageInputAmountTest5()
        {
            int damageAmount = 50;
            Bee bee          = new Bee();

            bee.Damage(damageAmount);
            Assert.AreEqual(bee.Health, 50);
        }
Esempio n. 30
0
            Bee NewBee(BeeState state)
            {
                var bee = new Bee(state);

                TestNewBest(bee._memoryMatrix, bee._memoryScore);

                return(bee);
            }
Esempio n. 31
0
        public Bee AddBee(Bee bee)
        {
            m_mongoClient.Open();

            m_mongoClient.GetCollection<Bee>(MongoCollection.BeeCollection)
                .InsertOneAsync(bee)
                .Wait();

            return bee;
        }
Esempio n. 32
0
        public Bee Map(AddBeeDto addBeeDto)
        {
            Bee bee = new Bee()
            {
                FirstName = addBeeDto.FirstName,
                LastName = addBeeDto.LastName,
                Email = addBeeDto.Email,
                Password = addBeeDto.Password,
                UserName = addBeeDto.UserName,
            };

            return bee;
        }
Esempio n. 33
0
 public static Insect CreateInsect(InsectSpecies Species)
 {
     /// <summary
     ///     Static method that creates choosen Animal, determed on the parameter Species.
     ///     Insect animalObj set to null;
     ///     <returns>animalObj with created animal object</returns>
     /// </summary
     Insect animalObj = null;
     switch (Species)
     {
         case InsectSpecies.Bee:
             animalObj = new Bee();
             break;
         case InsectSpecies.Butterfly:
             animalObj = new Butterfly();
             break;
     }
     animalObj.Category = CategoryType.Insect;
     return animalObj;
 }
Esempio n. 34
0
 private void checkRange(ref Bee tmp)
 {
     for (int i = 0; i < argCnt; i++)
     {
         tmp.point[i] = tmp.point[i] < rangeMin[i] ? rangeMin[i] : tmp.point[i];
         tmp.point[i] = tmp.point[i] > rangeMax[i] ? rangeMax[i] : tmp.point[i];
     }
 }
Esempio n. 35
0
 private double getProfit(Bee tmp)
 {
     return optOrient * func.result(argCnt, tmp.point.x);
 }
Esempio n. 36
0
 private Bee getRandBee()
 {
     Bee tmp = new Bee(argCnt);
     for (int j = 0; j < argCnt; j++)
     {
         tmp.point[j] = rand.NextDouble() * (rangeMax[j] - rangeMin[j]) + rangeMin[j];
         tmp.profit = getProfit(tmp);
     }
     return tmp;
 }
Esempio n. 37
0
 public void Copy(Bee a)
 {
     point.Copy(a.point);
     profit = a.profit;
 }
Esempio n. 38
0
        public double[] search()
        {
            List<Bee> bee = new List<Bee>();
            Bee best = new Bee(argCnt);
            List<Bee> workBee = new List<Bee>();
            List<Bee> newWorkBee = new List<Bee>();
            Bee tmp;

            //Step 2
            for (int i = 0; i < B; i++)
            {
                tmp = getRandBee();
                bee.Add(tmp);
            }
            iter = 1;
            //Step 3
            best.Copy(bee.First());
            while (T != TFinal && iter != iterMax)
            {
                newWorkBee.Clear();
                workBee.Clear();
                for (int i = 0; i < bee.Count; i++)
                {
                    if (best.profit < bee[i].profit)
                    {
                        best.Copy(bee[i]);
                    }
                }
                for (int i = 0; i < bee.Count; i++)
                {
                    if (Math.Exp(-Math.Abs(bee[i].profit - best.profit) / T) > rand.NextDouble())
                    {
                        workBee.Add(bee[i]);
                    }
                }
                workBee.Add(best);
                //Step 4
                foreach (Bee currBee in workBee)
                {
                    tmp = new Bee(argCnt);
                    for (int i = 0; i < argCnt; i++)
                    {
                        tmp.point[i] = currBee.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
                    }
                    checkRange(ref tmp);
                    tmp.profit = getProfit(tmp);
                    newWorkBee.Add(tmp);
                }
                foreach (Bee currBee in workBee)
                {
                    tmp = new Bee(argCnt);
                    for (int i = 0; i < argCnt; i++)
                    {
                        tmp.point[i] = best.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
                    }
                    checkRange(ref tmp);
                    tmp.profit = getProfit(tmp);
                    newWorkBee.Add(tmp);
                }
                newWorkBee.AddRange(workBee);
                foreach (Bee currBee in newWorkBee)
                {
                    if (best.profit < currBee.profit)
                    {
                        best.Copy(currBee);
                    }
                }
                //Step 5
                double fullProfit = 0;
                foreach (Bee currBee in newWorkBee)
                {
                    fullProfit += currBee.profit;
                }
                double d;
                double L;
                bee.Clear();
                for (int i = 0; i < newWorkBee.Count; i++)
                {
                    d = newWorkBee[i].profit / fullProfit;
                    d += getRandSign() * rand.NextDouble() * wMax;
                    d = d > 1 ? 1 : d;
                    d = d < eMax ? 0 : d;
                    L = (d - eta * fullProfit / newWorkBee.Count) < 0 ? 0 : (d - eta * fullProfit / newWorkBee.Count);
                    if (L / beta > (gamma * fullProfit / newWorkBee.Count))
                    {
                        bee.Add(newWorkBee[i]); //danced bee are added

                        tmp = new Bee(argCnt);
                        for (int j = 0; j < argCnt; j++)
                        {
                            tmp.point[j] = newWorkBee[i].point[j] + range * rand.NextDouble() - range / 2;
                        }
                        checkRange(ref tmp);
                        tmp.profit = getProfit(tmp);
                        bee.Add(tmp);
                    }
                    else
                    {
                        tmp = getRandBee();
                        bee.Add(tmp);
                    }

                }
                iter++;
                T *= alpha;
                range *= (1 - (double)iter / iterMax);
            }
            return (best.point.x);
        }
Esempio n. 39
0
        private void Init()
        {
            // tablica z liczbami dla kazdej pszczoly
            int[] initialTable = new int[n];
            for (int i = 0; i < n; i++)
            {
                initialTable[i] = i;
            }

            // tworzymy pszczoly
            bees = new Bee[nb];
            for (int i = 0; i < nb; i++)
            {
                bees[i] = new Bee((int[])initialTable.Clone());         // kazda pszczola otrzymuje swoja kopie tablicy liczb
                bees[i].FindSomeSite(n);                                // i ja losowo permutuje
            }

            // sortujemy pszczoly wedlug kosztu wyliczonego z posiadanych przez nie permutacji
            Array.Sort<Bee>(bees,Bee.Compare);
            SaveBestResult();
        }
Esempio n. 40
0
        public Hive(int totalNumberBees, int numberInactive, int numberActive, int numberScout, int maxNumberVisits, int maxNumberCycles, CitiesData citiesData, int BeginningAndEnd = 0)  
        {
            //random = new Random(0);
            this.BeginningAndEnd = BeginningAndEnd;
            this.totalNumberBees = totalNumberBees;
            this.numberInactive = numberInactive;
            this.numberActive = numberActive;
            this.numberScout = numberScout;
            this.maxNumberVisits = maxNumberVisits;
            this.maxNumberCycles = maxNumberCycles;
            //this.maxCyclesWithNoImprovement = maxCyclesWithNoImprovement;

            //this.citiesData = new CitiesData(citiesData.cities.Length); // hive's copy of problem-specific data
            this.citiesData = citiesData; // reference to CityData

            // this.probPersuasion & this.probMistake are hard-coded in class definition

            this.bees = new Bee[totalNumberBees];
            this.bestMemoryMatrix = GenerateRandomMemoryMatrix(); // alternative initializations are possible
            this.bestMeasureOfQuality = MeasureOfQuality(this.bestMemoryMatrix);

            this.indexesOfInactiveBees = new int[numberInactive]; // indexes of bees which are currently inactive

            for (int i = 0; i < totalNumberBees; ++i) // initialize each bee, and best solution
            {
                int currStatus; // depends on i. need status before we can initialize Bee
                if (i < numberInactive)
                {
                    currStatus = 0; // inactive
                    indexesOfInactiveBees[i] = i; // curr bee is inactive
                }
                else if (i < numberInactive + numberScout)
                {
                    currStatus = 2; // scout
                }
                else
                {
                    currStatus = 1; // active
                }

                SubCalendarEvent[] randomMemoryMatrix = GenerateRandomMemoryMatrix();
                double mq = MeasureOfQuality(randomMemoryMatrix);
                int numberOfVisits = 0;

                bees[i] = new Bee(currStatus, randomMemoryMatrix, mq, numberOfVisits); // instantiate current bee

                // does this bee have best solution?
                if (bees[i].measureOfQuality < bestMeasureOfQuality) // curr bee is better (< because smaller is better)
                {
                    Array.Copy(bees[i].memoryMatrix, this.bestMemoryMatrix, bees[i].memoryMatrix.Length);
                    this.bestMeasureOfQuality = bees[i].measureOfQuality;
                }
            } // each bee

        } // TravelingSalesmanHive ctor
 public MakingHoneyState(Bee bee)
     : base(bee)
 {
 }
 public GatheringNectarState(Bee bee)
     : base(bee)
 {
 }
 public ReturningToHiveState(Bee bee)
     : base(bee)
 {
 }
Esempio n. 44
0
 public Bee AddBee(Bee bee)
 {
     return m_beeRepository.AddBee(bee);
 }
Esempio n. 45
0
 public RetiredState(Bee bee)
     : base(bee)
 {
 }
Esempio n. 46
0
 private Bee GetMinimalBee(Bee[] beesArray)
 {
     Bee minBee = beesArray[0];
     for (int i = 1; i < beesArray.Length; i++)
     {
         if (Bee.Compare(minBee, beesArray[i]) > 0)
             minBee = beesArray[i];
     }
     return minBee;
 }
Esempio n. 47
0
 void Awake()
 {
     Bee.Instance = this;
 }
 public FlyingToFlowerState(Bee bee)
     : base(bee)
 {
 }
Esempio n. 49
0
 public IdleState(Bee bee)
     : base(bee)
 {
 }
Esempio n. 50
0
        public void ReleaseTheBees()
        {
            Init();
            neighbourhoodSize = (int) Math.Round(n * ngh);              // wyliczamy rozmiar sasiedztwa
            for (int iter = 0; iter < imax; iter++)
            {
                // przetwarzamy najlepsze pszczoly
                for (int bestSites = 0; bestSites < e; bestSites++)
                {
                    Bee[] nepBees = new Bee[nep];
                    for (int i = 0; i < nep; i++)
                    {
                        nepBees[i] = new Bee(bees[bestSites].Data);
                        nepBees[i].FindSomeSite(neighbourhoodSize);
                    }
                    Bee minimalBee = GetMinimalBee(nepBees);
                    if(minimalBee.Value < bees[bestSites].Value)
                        bees[bestSites] = minimalBee;
                }

                // pozostale wybrane pszczoly
                for (int selectedSites = e; selectedSites < m; selectedSites++)
                {
                    Bee[] nspBees = new Bee[selsit];
                    for (int i = 0; i < selsit; i++)
                    {
                        nspBees[i] = new Bee(bees[selectedSites].Data);
                        nspBees[i].FindSomeSite(neighbourhoodSize);
                    }
                    Bee minimalBee = GetMinimalBee(nspBees);
                    if (minimalBee.Value < bees[selectedSites].Value)
                        bees[selectedSites] = minimalBee;
                }

                // pozostale wysylamy losowo
                for (int randomSites = m; randomSites < nb; randomSites++)
                {
                    bees[randomSites].FindSomeSite(n);
                }

                // sortujemy
                Array.Sort<Bee>(bees, Bee.Compare);
                if (minimalCost > bees[0].Value)
                {
                    SaveBestResult();
                }

                //jeśli został przypisany background worker to notyfikuje go
                if (_backgroundWorker != null) _backgroundWorker.ReportProgress(minimalCost);
                if (cancel) break;
            }

            finished = true;
        }
Esempio n. 51
0
 public BeeController(Bee Form)
 {
     this.form= Form;
     Initialize();
 }