Beispiel #1
0
        static void Main(string[] args)
        {
            Population populacja = new Population(5, 6, n => n * n, new Random());
            int ilosc = 5;//ilosc pokoleń
            for (int i = 0; i < ilosc; i++)
            {

                for (int j = 0; j <= 2; i++)
                {
                    foreach (var z in populacja.Individuals)
                    {
                        foreach (var x in populacja.Individuals)
                        {
                            var crossoverOperator = new OnePointCrossover(new Random());
                            crossoverOperator.Crossover(z, x);
                        }
                    }
                }
                var lambda = new OnePointCrossover(new Random());
                var pokolenie = lambda.IndividualsLambda;

                foreach (var y in pokolenie)
                {
                    populacja.Individuals.Add(y);
                }
                var top = populacja.Individuals.OrderByDescending(x => x.Fitness).Take(5);
                populacja = null;
                populacja.Individuals.Add(top);

            }
        }
        public Population RouletteSelection()
        {
            var result = new Population(Individuals.Count, Individuals.First().Chromosome.Genes.Count, _fitnessFunction, _random);
            UpdateFitness();
            var sumOfFitness = Individuals.Sum(x => x.Fitness);
            var probabilities = Individuals.Select(x => x.Fitness / sumOfFitness);
            var distribution = new List<double>(probabilities);

            for (int i = 1; i < distribution.Count; i++)
            {
                distribution[i] += distribution[i - 1];
            }

            // TODO: parents selection

            return result;
        }
Beispiel #3
0
 public void Generationv2(Population fresh)
 {
 }
Beispiel #4
0
 static void Main(string[] args)
 {
     Population populacja = new Population(5, 3, n => n+n, new Random());
 }