Beispiel #1
0
 /// <summary>
 /// Add a food source into the scout food source queue.  Thread safe.
 /// </summary>
 /// <param name="foodSource"></param>
 public void AddFoodSource(FoodSource foodSource)
 {
     //stuff this into a queue to inspire the scouts to check it.
     lock (newFoodSourceQueueLock) {
         newFoodSourceQueue.Enqueue(foodSource);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Remove a food source from the food source list.  Thread safe.
 /// </summary>
 /// <param name="foodSource"></param>
 public void RemoveFoodSource(FoodSource foodSource)
 {
     lock (objFoodSource) {
         foodSources.Remove(foodSource);
         Bees.ForEach(x => x.RandomSolution = GetUniqueRandoms(Rand, 0, foodSources.Count));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Performs the bee primary and neighbor fitness.  (NOT Thread safe)
        /// </summary>
        /// <param name="primaryFoodSource">Primary food source.</param>
        /// <param name="bee">Bee.</param>
        /// <param name="foodSourceSelection">Food source selection.</param>
        private void PerformBeePrimaryAndNeighborFitness(FoodSource primaryFoodSource,
                                                         Bee bee, List <FoodSource> foodSourceSelection)
        {
            var        primaryFoodSourceCoordinate = primaryFoodSource.Location.GeoCoordinate;
            double     distanceLocation            = double.MaxValue;
            FoodSource neighbor = null;

            foreach (var source in foodSources)
            {
                //Ignore if the current source is the same
                if (source.ToString() == primaryFoodSource.ToString())
                {
                    continue;
                }
                //Locate the nearest neighbor that is not abandoned.
                if (source.IsAbandoned)
                {
                    continue;
                }
                double distance = source.Location.GeoCoordinate.GetDistanceTo(primaryFoodSourceCoordinate);
                if (distance < distanceLocation)
                {
                    neighbor = source;
                }
            }
            //Each employed bee goes to a food source in her memory and determines a neighbour source,
            //then evaluates its nectar amount and dances in the hive
            primaryFoodSource.FitnessValue = this.fitnessGetFunction(primaryFoodSource, bee);
            if (primaryFoodSource.FitnessValue <= 0)
            {
                primaryFoodSource.IsAbandoned = true;
            }
            primaryFoodSource.TrialsCount++;
            foodSourceSelection.Add(primaryFoodSource);
            if (neighbor != null)
            {
                neighbor.FitnessValue = this.fitnessGetFunction(neighbor, bee);
                if (neighbor.FitnessValue <= 0)
                {
                    neighbor.IsAbandoned = true;
                }
                neighbor.TrialsCount++;
                foodSourceSelection.Add(neighbor);
            }
        }