예제 #1
0
 static void Mutate(ref ga_struct member)
 {
     int tsize = GA_TARGET.Length;
     int ipos = random.Next(tsize);
     int delta = random.Next(90) + 32;
     var mutated = member.Str.ToCharArray();
     Convert.ToChar((member.Str[ipos] + delta)%123).ToString().CopyTo(0, mutated, ipos, 1);
     member.Str = mutated.ToString();
 }
예제 #2
0
 static void InitPopulation(ref ga_vector population, ref ga_vector buffer)
 {
     int tsize = GA_TARGET.Length;
     for (int i = 0; i < GA_POPSIZE; i++)
     {
         var citizen = new ga_struct(string.Empty, 0);
         
         for (int j = 0; j < tsize; j++)
         {
             citizen.Str += Convert.ToChar(random.Next(90) + 32);
         }
         population.Add(citizen);
         buffer.Add(new ga_struct(string.Empty, 0));
     }
 }
예제 #3
0
 static int FitnessSort(ga_struct x, ga_struct y)
 {
     return x.Fitness.CompareTo(y.Fitness);
 }