Beispiel #1
0
        internal PolygonAndColorMutationChanges MutatePolygonAndColor()
        {
            if (this.Polygons.Count > 0)
            {
                int position = random.Next(this.Polygons.Count);
                PolygonAndColorMutationChanges changes = new PolygonAndColorMutationChanges();
                changes.OldNegativeFitness = this.NegativeFitness;
                changes.OldBrush           = this.Brushes[position];
                changes.OldPolygon         = this.Polygons[position];
                changes.Index = position;

                int     nrOfPoints = 3 + random.Next(RandSeed);
                Point[] newPolygon = getPoints(nrOfPoints);
                Brush   newBrush   = getRandomBrush();

                this.Polygons[position]    = newPolygon;
                this.Brushes[position]     = newBrush;
                this.NegativeFitness       = computeNegativeFittness();
                changes.NewNegativeFitness = this.NegativeFitness;

                changes.NewPolygon = newPolygon;
                changes.NewBrush   = newBrush;

                return(changes);
            }
            return(null);
        }
Beispiel #2
0
        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);
            }
        }