public void Epoch()
    {
        PrintStats();
        DestroyGameObjects();
        nGeneration++;

        individuals = individuals.OrderByDescending(o => o.Fitness).ToList();

        List <Individual> newIndividuals = new List <Individual>();

        newIndividuals.AddRange(CloneElite(ConfigManager.config.geneticAlgorithm.nElite));
        newIndividuals.AddRange(ReproductionHelper.Reproduce(individuals, ConfigManager.config.geneticAlgorithm.nIndividuals - ConfigManager.config.geneticAlgorithm.nElite, GetFitness()));
        MutationHelper.Mutate(newIndividuals);

        enemies = new List <List <Enemy> >();
        for (int i = 0; i < newIndividuals.Count; i++)
        {
            newIndividuals[i].Index = i;
            newIndividuals[i].CreateGameObject();

            enemies.Add(new List <Enemy>());
            float distanceOffset = 0;
            for (int j = 0; j < ConfigManager.config.nEnemies; j++)
            {
                enemies[i].Add(new Enemy(i, distanceOffset));
                distanceOffset = enemies[i][j].Distance;
            }
            newIndividuals[i].SetEnemies(enemies[i]);
        }

        individuals = new List <Individual>(newIndividuals);
        CreateGameObjects();
    }
Пример #2
0
    public void Epoch()
    {
        DestroyGameObjects();
        nGeneration++;

        int totalFitness = GetFitness();

        individuals = individuals.OrderByDescending(o => o.fitness).ToList();

        List <Individual> newIndividuals = new List <Individual>();

        newIndividuals.AddRange(CloneElite(ConfigManager.config.geneticAlgorithm.nElite));
        newIndividuals.AddRange(ReproductionHelper.Reproduce(individuals, ConfigManager.config.geneticAlgorithm.nIndividuals - ConfigManager.config.geneticAlgorithm.nElite, totalFitness));
        MutationHelper.Mutate(newIndividuals);

        for (int i = 0; i < newIndividuals.Count; i++)
        {
            newIndividuals[i].SetTile(tileMap.GetRandomTile());
        }

        PrintStats();

        individuals = new List <Individual>(newIndividuals);

        CreateGameObjects();
    }
    private static void AdvanceGeneration()
    {
        Individual[] nextPopulation     = new Individual[Config.nIndividualsPerPopulation];
        Individual[] orderedIndividuals = FitnessHelper.GetOrderedIndividuals(population);

        for (int i = 0; i < Config.nElite; i++)
        {
            nextPopulation[i]          = orderedIndividuals[i];
            nextPopulation[i].wasElite = true;
        }
        Debug.Log("ordered generation " + generationsFinished);
        Print(orderedIndividuals);

        //sacar el promedio de fitness, y hacer que la mutación pase empezando por el promedio ese dividido 2 (por ejemplo, si el fitness promedio es 4, empezás a mutar desde el frame 2)
        //y aumentás el mutationRate un toque

        Individual[] childrenIndividuals = ReproductionHelper.GetChildrenIndividuals(population, Config.nIndividualsPerPopulation - Config.nElite);
        MutationHelper.MutatePopulation(childrenIndividuals);

        for (int i = Config.nElite; i < childrenIndividuals.Length + Config.nElite; i++)
        {
            nextPopulation[i] = childrenIndividuals[i - Config.nElite];
        }

        Debug.Log("next generation " + generationsFinished + 1);
        Print(nextPopulation);


        generationsFinished++;
        individualsFinished = 0;
        population          = (Individual[])nextPopulation.Clone();
        StartIndividual(0);
    }
Пример #4
0
 void Awake()
 {
     PhraseHelper.Init();
     ReproductionHelper.Init();
     MutationHelper.Init();
     UIManager.Init();
     PopulationManager.Init();
 }
Пример #5
0
    private static void AddChildren(Individual[] nextPopulation, Individual[] population)
    {
        Individual[] childrenIndividuals = ReproductionHelper.GetChildrenIndividuals(population, Config.nIndividualsPerPopulation - Config.nElite);
        MutationHelper.MutatePopulation(childrenIndividuals);

        for (int i = Config.nElite; i < childrenIndividuals.Length + Config.nElite; i++)
        {
            nextPopulation[i] = childrenIndividuals[i - Config.nElite];
        }
    }
Пример #6
0
        protected override void OnNextStepClicked()
        {
            NumberOfSteps++;
            var reproduceItems = ReproductionHelper.ReproduceReal(Function, RealItems);
            var newItems       =
                CrossingoverHelper.MakeRealCrossingover(reproduceItems, SolutionAccuracy, CrossingoverPossibility);

            MutationHelper.MutateReal(newItems, NumberOfSteps, MaxSteps, MutationPossibility);
            RealItems = newItems;

            var minItem = RealItems.Aggregate((i, j) =>
                                              Function(i.X1, i.X2) < Function(j.X1, j.X2)
                    ? i
                    : j);

            ItemValue = $"x1: {minItem.X1}\nx2: {minItem.X2}";
            var functionValue = Function(minItem.X1, minItem.X2);

            MaxItemValueFunction = functionValue.ToString();

            // ------------------------------------------------------

            for (var i = ChartModel.Series.Count - 1; i > 0; i--)
            {
                ChartModel.Series.RemoveAt(i);
            }

            var solutions = new ScatterSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerFill = OxyColor.FromRgb(0, 0, 0xFF)
            };

            foreach (var p in RealItems)
            {
                var plotPoint = new ScatterPoint(p.X1, p.X2, 5);
                solutions.Points.Add(plotPoint);
            }

            ChartModel.Series.Add(solutions);

            var minValueSeries = new ScatterSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerFill = OxyColor.FromRgb(0xFF, 0, 0)
            };

            minValueSeries.Points.Add(new ScatterPoint(minItem.X1, minItem.X2, 7, functionValue));
            ChartModel.Series.Add(minValueSeries);

            ChartModel.InvalidatePlot(true);
        }
Пример #7
0
    public static void AdvanceGeneration()
    {
        List <Individual> newPopulation = new List <Individual>();

        FitnessHelper.CalculateFitness(population);

        newPopulation.AddRange(FitnessHelper.GetIndividualsWithHighestFitness(population, Config.nIndividualsToAdvanceAutomatically));

        UIManager.UpdateBestPhrase(newPopulation[0].dna.phrase);

        newPopulation.AddRange(ReproductionHelper.GetNewIndividuals(population, Config.nIndividuals - Config.nIndividualsToAdvanceAutomatically));
        MutationHelper.MutatePopulation(population);

        generationNumber++;

        UIManager.UpdateGenerationNumber(generationNumber);
        UIManager.UpdateFitnesses(FitnessHelper.GetFitnessInformation(population));

        ReassignPopulation(newPopulation);
    }
    public void Epoch()
    {
        Debug.Log("Finished generation " + nGeneration + " with a total fitness of " + GetFitness());
        PopulationHistory.AddIndividuals(Individuals);
        nGeneration++;
        DestroyGameObjects();

        Individuals = Individuals.OrderByDescending(o => o.Fitness).ToList();

        List <Individual> newIndividuals = new List <Individual>();

        newIndividuals.AddRange(CloneElite(ConfigManager.config.geneticAlgorithm.nElite));
        newIndividuals.AddRange(ReproductionHelper.Reproduce(Individuals, ConfigManager.config.geneticAlgorithm.nIndividuals - ConfigManager.config.geneticAlgorithm.nElite, GetFitness()));
        MutationHelper.Mutate(newIndividuals.GetRange(ConfigManager.config.geneticAlgorithm.nElite, newIndividuals.Count - ConfigManager.config.geneticAlgorithm.nElite));

        for (int i = 0; i < newIndividuals.Count; i++)
        {
            newIndividuals[i].Index = i;
        }

        Individuals = new List <Individual>(newIndividuals);
        CreateGameObjects();
    }