コード例 #1
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);
            }
        }
コード例 #2
0
        internal ColorMutationChanges MutateColorParam()
        {
            if (this.Brushes.Count > 0)
            {
                ColorMutationChanges changes = new ColorMutationChanges();
                changes.OldNegativeFitness = this.NegativeFitness;
                int position = random.Next(this.Brushes.Count);
                changes.Index = position;

                SolidBrush oldBrush = (SolidBrush)this.Brushes[position];
                changes.OldBrush = oldBrush;

                Color newColor = Color.FromArgb(oldBrush.Color.A,
                                                oldBrush.Color.R,
                                                oldBrush.Color.G,
                                                oldBrush.Color.B);
                int colorParamPos = random.Next(3);
                int newColorParam = random.Next(255);
                if (colorParamPos == 0)
                {
                    newColor = Color.FromArgb(oldBrush.Color.A,
                                              newColorParam,
                                              oldBrush.Color.G,
                                              oldBrush.Color.B);
                }
                else if (colorParamPos == 1)
                {
                    newColor = Color.FromArgb(oldBrush.Color.A,
                                              oldBrush.Color.R,
                                              newColorParam,
                                              oldBrush.Color.B);
                }
                else if (colorParamPos == 2)
                {
                    newColor = Color.FromArgb(oldBrush.Color.A,
                                              oldBrush.Color.R,
                                              oldBrush.Color.G,
                                              newColorParam);
                }

                SolidBrush newBrush = new SolidBrush(newColor);

                this.Brushes[position]     = newBrush;
                this.NegativeFitness       = computeNegativeFittness();
                changes.NewNegativeFitness = this.NegativeFitness;
                changes.NewBrush           = newBrush;
                return(changes);
            }
            return(null);
        }
コード例 #3
0
        internal ColorMutationChanges MutateColor()
        {
            if (this.Brushes.Count > 0)
            {
                ColorMutationChanges changes = new ColorMutationChanges();
                changes.OldNegativeFitness = this.NegativeFitness;
                int position = random.Next(this.Brushes.Count);
                changes.Index    = position;
                changes.OldBrush = this.Brushes[position];

                Brush newBrush = getRandomBrush();

                this.Brushes[position]     = newBrush;
                this.NegativeFitness       = computeNegativeFittness();
                changes.NewNegativeFitness = this.NegativeFitness;
                changes.NewBrush           = newBrush;
                return(changes);
            }
            return(null);
        }