Пример #1
0
        /// <summary>
        /// Update all individuals
        /// </summary>
        public void UpdateIndividuals()
        {
            if (AllIndividuals == null)
            {
                return;
            }

            var mPath = Path.Combine(Properties.Settings.Default.SaveLocation, SelectedGroup.GroupName);

            AllIndividuals.Clear();
            AllEvaluations.Clear();
            AllReliabilityIndices.Clear();

            try
            {
                string[] subdirectoryEntries = Directory.GetDirectories(mPath);
                foreach (string subdirectory in subdirectoryEntries)
                {
                    string[] group = subdirectory.Split('\\');
                    AllIndividuals.Add(Individual.CreateIndividual(group[group.Length - 1]));
                }
            }
            catch
            { }
        }
Пример #2
0
        public void Swap(Individual remove,
                         Individual add)
        {
            if (remove.Type == IndividualType.Cooperator)
            {
                CooperatorGroup.Remove(remove);
            }
            else
            {
                DefectorGroup.Remove(remove);
            }

            if (add.Type == IndividualType.Cooperator)
            {
                CooperatorGroup.Add(add);
            }
            else
            {
                DefectorGroup.Add(add);
            }

            var index = AllIndividuals.IndexOf(remove);

            AllIndividuals[index] = add;
        }
Пример #3
0
        public override void Perish1( )
        {
            AdjustmentRules.AdjustStep1( );

            Step1PerishCount = Utility.NextGaussianIntInRange(V.MeanPerishStep1, V.SdPerishStep1,
                                                              0, V.PopulationSize - 1);

            var survivorsCount = AllIndividuals.Count - Step1PerishCount;

            (Step1Survivors, Step1Rejects) = AllIndividuals.ChooseBy(survivorsCount, x => x.PhenotypicQuality);
            foreach (var ind in Step1Rejects)
            {
                ind.Perish( );
            }

            if (IsLoggingEnabled)
            {
                Logger.Debug("\n\nPerish 1:\n");
                Logger.Debug($"Amount to perish = {Step1PerishCount}");
                Logger.Debug("Perished Individuals:");
                Logger.Debug(Step1Rejects
                             .OrderBy(x => x.Type)
                             .ThenBy(x => x.Id)
                             .ToTable(x => new
                {
                    _Type = x.Type,
                    x.Id,
                    Qp = $"{x.PhenotypicQuality:F4}"
                }
                                      )
                             );
            }
        }
Пример #4
0
        public bool Remove(Individual individual)
        {
            AllIndividuals.Remove(individual);
            if (individual.Type == IndividualType.Cooperator)
            {
                return(CooperatorGroup.Remove(individual));
            }

            return(DefectorGroup.Remove(individual));
        }
Пример #5
0
        public void Add(Individual individual)
        {
            if (individual.Type == IndividualType.Cooperator)
            {
                CooperatorGroup.Add(individual);
            }
            else
            {
                DefectorGroup.Add(individual);
            }

            AllIndividuals.Add(individual);
        }
Пример #6
0
        public List <TIndividual> RepetitiveChooseBy(int amount,
                                                     Func <TIndividual, double> selector)
        {
            var cumulative = AllIndividuals.Select(selector).CumulativeSum( ).ToList( );
            var total      = cumulative.Last( );

            var parents = new List <TIndividual> (amount);

            for (var i = 0; i < amount; i++)
            {
                var targetAllocation = Utility.NextDouble * total;
                var index            = cumulative.BinarySearch(targetAllocation);
                if (index < 0)
                {
                    index = ~index;
                }

                parents.Add(AllIndividuals[index]);
            }

            return(parents);
        }
Пример #7
0
 public void Shuffle( )
 {
     AllIndividuals.Shuffle(Utility.Srs);
 }