internal PolygonMutationChanges MutatePolygonPoint() { if (this.Polygons.Count > 0) { int position = random.Next(this.Polygons.Count); PolygonMutationChanges changes = new PolygonMutationChanges(); changes.OldNegativeFitness = this.NegativeFitness; Point[] oldPolygon = new Point[this.Polygons[position].Length]; Array.Copy(this.Polygons[position], oldPolygon, this.Polygons[position].Length); changes.OldPolygon = oldPolygon; changes.Index = position; int pointPosition = random.Next(oldPolygon.Length); int new_x = random.Next(originalImage.Width); int new_y = random.Next(originalImage.Height); Point newPoint = new Point(new_x, new_y); this.Polygons[position][pointPosition] = newPoint; this.NegativeFitness = computeNegativeFittness(); changes.NewNegativeFitness = this.NegativeFitness; changes.NewPolygon = this.Polygons[position]; return(changes); } return(null); }
internal void ApplyMutation(IMutationChanges changes) { if (changes == null) { return; } this.NegativeFitness = changes.NewNegativeFitness; if (changes is PolygonAndColorMutationChanges) { PolygonAndColorMutationChanges change = (PolygonAndColorMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; Brush brush = change.NewBrush; this.Polygons[index] = polygon; this.Brushes[index] = brush; } else if (changes is ColorMutationChanges) { ColorMutationChanges change = (ColorMutationChanges)changes; int index = change.Index; Brush brush = change.NewBrush; this.Brushes[index] = brush; } else if (changes is PolygonMutationChanges) { PolygonMutationChanges change = (PolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; this.Polygons[index] = polygon; } else if (changes is SubstractPolygonMutationChanges) { SubstractPolygonMutationChanges change = (SubstractPolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.OldPolygon; Brush brush = change.OldBrush; //this.Polygons.Insert(index, polygon); //this.GeneBrush.Insert(index, brush); this.Brushes.RemoveAt(index); this.Polygons.RemoveAt(index); } else if (changes is AddPolygonMutationChanges) { AddPolygonMutationChanges change = (AddPolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; Brush brush = change.NewBrush; this.Brushes.Insert(index, brush); this.Polygons.Insert(index, polygon); } }
internal PolygonMutationChanges MutatePolygon() { if (this.Polygons.Count > 0) { int position = random.Next(this.Polygons.Count); PolygonMutationChanges changes = new PolygonMutationChanges(); changes.OldNegativeFitness = this.NegativeFitness; changes.OldPolygon = this.Polygons[position]; changes.Index = position; int nrOfPoints = 3 + random.Next(RandSeed); Point[] newPolygon = getPoints(nrOfPoints); this.Polygons[position] = newPolygon; this.NegativeFitness = computeNegativeFittness(); changes.NewNegativeFitness = this.NegativeFitness; changes.NewPolygon = newPolygon; return(changes); } return(null); }