Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. static public List<Point> CrossbreedingTwoDots(List<Point> parents)
  2. {
  3. List<Point> newPop = new List<Point>();
  4. for (int i = 0; i < parents.Count; i++)
  5. newPop.Add(parents[i]);
  6. parents.Sort();
  7. for (int i = 0; i < parents.Count; i += 2)
  8. {
  9. int dot1 = rnd.Next(2, 27);
  10. int dot2 = rnd.Next(dot1, 28);
  11. int[] child1x = new int[29];
  12. int[] child1y = new int[29];
  13. int[] child2x = new int[29];
  14. int[] child2y = new int[29];
  15. for (int j = 0; j < dot1; j++)
  16. {
  17. child1x[j] = parents[i].GenX[j];
  18. child1y[j] = parents[i].GenY[j];
  19. child2x[j] = parents[i + 1].GenX[j];
  20. child2y[j] = parents[i + 1].GenY[j];
  21. }
  22. for (int j = dot1; j < dot2; j++)
  23. {
  24. child1x[j] = parents[i].GenX[j];
  25. child1y[j] = parents[i].GenY[j];
  26. child2x[j] = parents[i + 1].GenX[j];
  27. child2y[j] = parents[i + 1].GenY[j];
  28. }
  29. for (int j = dot2; j < 29; j++)
  30. {
  31. child1x[j] = parents[i + 1].GenX[j];
  32. child1y[j] = parents[i + 1].GenY[j];
  33. child2x[j] = parents[i].GenX[j];
  34. child2y[j] = parents[i].GenY[j];
  35. }
  36. Point child1 = new Point(child1x, child1y);
  37. Point child2 = new Point(child2x, child2y);
  38.  
  39. if ((double)rnd.Next(1000) / 1000.0 < mut)
  40. {
  41. child1 = Mutation(child1);
  42. }
  43.  
  44. child2 = Mutation(child2);
  45. newPop.Add(child1);
  46. newPop.Add(child2);
  47. }
  48. return newPop;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement