Exemplo n.º 1
0
 private static List<Individual> steady(Individual a, Individual b)
 {
     List<Individual> lis = new List<Individual>();
     Random rand = new Random();
     int[] c1 = a.getIndividual().ToArray();
     int[] c2 = b.getIndividual().ToArray();
     for (int i = 0; i < a.getIndividual().Count; i++)
     {
         int point = rand.Next(0, 2);
         if (point == 0) { int temp = c1[i]; c1[i] = c2[i]; c2[i] = temp; }
     }
     a.setIndividual(c1.ToList());
     b.setIndividual(c2.ToList());
     lis.Add(a);
     lis.Add(b);
     return lis;
 }
Exemplo n.º 2
0
 private static Individual simple(Individual individual)
 {
     int[] a = individual.getIndividual().ToArray();
     if (a.Length > 1)
     {
         int[] c = new int[a.Length];
         Random rand = new Random();
         int point = rand.Next(1, a.Length - 1);
         Array.Copy(a, c, a.Length);
         int ct = c[point];
         c[point] = c[point - 1];
         c[point - 1] = ct;
         individual.setIndividual(c.ToList());
         return individual;
     }
     else
     {
         return individual;
     }
 }