コード例 #1
0
        public Particles[] UpdateParticles(Particles[] particles)
        {
            Random rd        = new Random();
            int    direction = 0;

            for (int j = 0; j < Particles.PopulationSize; j++)
            {
                for (int i = 0; i < Particles.Size; i++)
                {
                    direction = Direction(particles[j].Times[i], Reference.Time[i]);

                    if (particles[j].Times[i] >= 1 && particles[j].Times[i] <= 32 && rd.NextDouble() > 0.9)
                    {
                        particles[j].Times[i] = (int)Math.Pow(2, ((int)Math.Log(particles[j].Times[i], 2) + direction));
                    }

                    direction = Direction(particles[j].Notes[i], Reference.Note[i]);

                    if (particles[j].Notes[i] <= 'g' && particles[j].Notes[i] >= 'a' && rd.NextDouble() > 0.9)
                    {
                        particles[j].Notes[i] = Particles.NoteNames[(Particles.NoteNames.IndexOf(particles[j].Notes[i]) + direction)];
                    }
                }
                particles[j] = Particles.FitnessCalculate(particles[j]);
            }
            return(particles);
        }
コード例 #2
0
    public static Particles[] CreatePopulation(Particles[] population)
    {
        for (int i = 0; i < population.Length; i++)
        {
            population[i] = new Particles();
            population[i].Initiate();
            population[i]          = Particles.FitnessCalculate(population[i]);
            population[i].PFitness = population[i].Fitness;
            population[i].PTimes   = population[i].Times;
            population[i].PNotes   = population[i].Notes;
        }

        return(population);
    }