Exemple #1
0
        public void AddCreature(RatedCreature <Creature> newCreature)
        {
            if (IsBetterThanBest(newCreature))
            {
                HandleNewBest(newCreature);
            }

            if (heap.IsFull)
            {
                if (newCreature.CompareTo(heap.PeekMin()) > 0) //if newCreature is better than the worst of creatures in heap
                {
                    Creature theWorst = heap.ExtractMin().TheCreature;
                    TrySaveDisposedCreature(theWorst);

                    heap.Insert(newCreature);
                }
                else
                {
                    TrySaveDisposedCreature(newCreature.TheCreature);
                }
            }
            else
            {
                heap.Insert(newCreature);
            }
        }
Exemple #2
0
        private void ComputeOneGenaration()
        {
            IEnumerable <Creature> newGeneration = mutationManager.GetChildren();

            foreach (var child in newGeneration)
            {
                RatedCreature <Creature> evaluatedChild = EvaluateCreature(child);
                AddCreatureToSelector(evaluatedChild);
            }
        }
Exemple #3
0
        public DefaultSelector(
            NewBestCretureFoundEventDelegate <Creature> newBestFound,
            RatedCreature <Creature> foreFather, int NumberOfSurvivals,
            DisposedCreaturesStore <Creature> disposedCreatures)
        {
            NewBestCretureFound = newBestFound;
            DisposedCreatures   = disposedCreatures;

            heap = new HeapOfMaximalSize <RatedCreature <Creature> >(NumberOfSurvivals);

            bestCreature = foreFather;
            AddCreature(foreFather);
        }
Exemple #4
0
        /// <summary>
        /// Return next creature and throws exception if set is empty
        /// </summary>
        public RatedCreature <Creature> GetNextCreature()
        {
            if (IsEmpty)
            {
                throw new PoolIsEmptyException();
            }

            RatedCreature <Creature> toReturn = enumeratorOfCreatures.Current;

            IsEmpty = !enumeratorOfCreatures.MoveNext();

            return(toReturn);
        }
Exemple #5
0
 private void HandleNewBest(RatedCreature <Creature> newBestCreature)
 {
     bestCreature = newBestCreature;
     NewBestCretureFound?.Invoke(newBestCreature.TheCreature, newBestCreature.FitnessValue);
 }
Exemple #6
0
 private bool IsBetterThanBest(RatedCreature <Creature> creature)
 => bestCreature.CompareTo(creature) < 0;
Exemple #7
0
 private void AddCreatureToSelector(RatedCreature <Creature> creature)
 {
     lock (myEnvironment.Selector)
         myEnvironment.Selector.AddCreature(creature);
 }
Exemple #8
0
 public int CompareTo(RatedCreature <Creature> other) => FitnessValue.CompareTo(other.FitnessValue);