Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public List<Point> CrossbreedingTwoDots(List<Point> parents)
- {
- List<Point> newPop = new List<Point>();
- for (int i = 0; i < parents.Count; i++)
- newPop.Add(parents[i]);
- parents.Sort();
- for (int i = 0; i < parents.Count; i += 2)
- {
- int dot1 = rnd.Next(2, 27);
- int dot2 = rnd.Next(dot1, 28);
- int[] child1x = new int[29];
- int[] child1y = new int[29];
- int[] child2x = new int[29];
- int[] child2y = new int[29];
- for (int j = 0; j < dot1; j++)
- {
- child1x[j] = parents[i].GenX[j];
- child1y[j] = parents[i].GenY[j];
- child2x[j] = parents[i + 1].GenX[j];
- child2y[j] = parents[i + 1].GenY[j];
- }
- for (int j = dot1; j < dot2; j++)
- {
- child1x[j] = parents[i].GenX[j];
- child1y[j] = parents[i].GenY[j];
- child2x[j] = parents[i + 1].GenX[j];
- child2y[j] = parents[i + 1].GenY[j];
- }
- for (int j = dot2; j < 29; j++)
- {
- child1x[j] = parents[i + 1].GenX[j];
- child1y[j] = parents[i + 1].GenY[j];
- child2x[j] = parents[i].GenX[j];
- child2y[j] = parents[i].GenY[j];
- }
- Point child1 = new Point(child1x, child1y);
- Point child2 = new Point(child2x, child2y);
- if ((double)rnd.Next(1000) / 1000.0 < mut)
- {
- child1 = Mutation(child1);
- }
- child2 = Mutation(child2);
- newPop.Add(child1);
- newPop.Add(child2);
- }
- return newPop;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement