Пример #1
0
    public void GenomeNodeMutation()
    {
        Genometype.NodeGenes[] nodes = new Genometype.NodeGenes[] {
            new Genometype.NodeGenes(Genometype.NodeGenes.Types.Input, _IOIndex: 0),
            new Genometype.NodeGenes(Genometype.NodeGenes.Types.Input, _IOIndex: 0),
            new Genometype.NodeGenes(Genometype.NodeGenes.Types.Output),
        };

        Genometype.ConnectionGenens[] connections = new Genometype.ConnectionGenens[] {
            new Genometype.ConnectionGenens(0, 2, 0.123f),
            new Genometype.ConnectionGenens(1, 2, 3f),
        };

        GenomeMutationController controller = new GenomeMutationController(new Genometype(nodes, connections));

        controller.MutateByInsertNodeBetweenConnection();

        for (int i = 0; i < controller.mutations.Count; i++)
        {
            Debug.Log(controller.mutations[i]);
        }
    }
Пример #2
0
        public void DoGenomeMutation()
        {
            List <WeightOptimize.GenomeScore> bestScores = new List <WeightOptimize.GenomeScore>();

            // WeightOptimize.GenomeScore bestScore = new WeightOptimize.GenomeScore(null, 0);

            // Find the best 3 genome from the weight optimizers
            for (int i = 0; i < m_weightOptimizers.Count; i++)
            {
                WeightOptimize.GenomeScore score = m_weightOptimizers[i].ExtractBestData();

                if (bestScores.Count < genomeSurviveCount)
                {
                    bestScores.Add(score);
                }
                else
                {
                    for (int e = 0; e < bestScores.Count; e++)
                    {
                        if (score.score > bestScores[e].score)
                        {
                            bestScores.Insert(e, score);
                            bestScores.RemoveAt(bestScores.Count - 1);
                            break;
                        }
                    }
                }
            }


            List <Genometype> surviveGenomes = new List <Genometype>();

            for (int i = 0; i < bestScores.Count; i++)
            {
                surviveGenomes.Add(bestScores[i].genome);
            }

            m_aliveGenomes.Clear();
            m_weightOptimizers.Clear();

            m_aliveGenomes.AddRange(surviveGenomes);

            List <Genometype> possibleMutations = new List <Genometype>();

            int genomePerGenome = (maxGenomeAtATime - m_aliveGenomes.Count) / m_aliveGenomes.Count;

            for (int i = 0; i < surviveGenomes.Count; i++)
            {
                GenomeMutationController mutateController = new GenomeMutationController(surviveGenomes[i]);
                mutateController.MutateByAddingConnection();
                mutateController.MutateByInsertNodeBetweenConnection();

                if (mutateController.mutations.Count > genomePerGenome)
                {
                    ShuffleList <Genometype>(mutateController.mutations);
                    for (int e = 0; e < genomePerGenome; e++)
                    {
                        m_aliveGenomes.Add(mutateController.mutations[e]);
                    }
                }
                else
                {
                    m_aliveGenomes.AddRange(mutateController.mutations);
                }
            }

            for (int i = 0; i < m_aliveGenomes.Count; i++)
            {
                m_weightOptimizers.Add(new WeightOptimize(this, genomeBirdCount, genomeBirdSurviveCount));
                m_weightOptimizers[i].InsertGenome(m_aliveGenomes[i], fullyRandom: false);
            }
        }