コード例 #1
0
 static public int CompareClass(ClassOfTimetable a, ClassOfTimetable b)
 {
     if (a.idTime < b.idTime)
     {
         return(-1);
     }
     else if (a.idTime > b.idTime)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
コード例 #2
0
ファイル: DNA.cs プロジェクト: linhmiyano99/Genetic-Algorithm
        /*
         * int size: length of genes
         * Random random: random to crossover
         * Func<T> getRandomeGene: auto generate a gene
         * fitnessFunction:
         * bool shouldInitGenes: decide generate genes or not
         * */
        public DNA(int size, Random random, Func <ClassOfTimetable> getRandomGene, Func <int, float> fitnessFunction, bool shouldInitGenes = true)
        {
            Genes                = new ClassOfTimetable[size];
            this.random          = random;
            this.getRandomGene   = getRandomGene;
            this.fitnessFunction = fitnessFunction;

            if (shouldInitGenes)
            {
                for (int i = 0; i < Genes.Length; i++)
                {
                    Genes[i] = getRandomGene();
                }
            }
        }