예제 #1
0
        private void MutatePentagonShapePosition()
        {
            var position = RandomMutation.RandomIntervalIntegerInclusive(0, PositionsShape.Count - 1);

            switch (AlgorithmInformation.MutationType)
            {
            case MutationType.SOFT:
                PositionsShape[position].SoftMutation();
                break;

            case MutationType.MEDIUM:
                PositionsShape[position].MediumMutation();
                break;

            case MutationType.GAUSSIAN:
                PositionsShape[position].GaussianMutation();
                break;

            case MutationType.HARD:
                for (int i = 0; i < PositionsShape.Count; i++)
                {
                    PositionsShape[i].HardMutation();
                }
                break;
            }
        }
예제 #2
0
        private void MutateSquareShapePosition()
        {
            var position = RandomMutation.RandomIntervalIntegerInclusive(0, PositionsShape.Count - 1);

            switch (AlgorithmInformation.MutationType)
            {
            case MutationType.SOFT:
                PositionsShape[position].SoftMutation();
                break;

            case MutationType.MEDIUM:
                PositionsShape[position].MediumMutation();
                break;

            case MutationType.GAUSSIAN:
                PositionsShape[position].GaussianMutation();
                break;

            case MutationType.HARD:
                PositionsShape[0].HardMutation();
                PositionsShape[1].PositionY = PositionsShape[0].PositionY;
                PositionsShape[3].PositionX = PositionsShape[0].PositionX;

                PositionsShape[2].HardMutation();
                PositionsShape[1].PositionX = PositionsShape[2].PositionX;
                PositionsShape[3].PositionY = PositionsShape[2].PositionY;
                break;
            }

            if (AlgorithmInformation.MutationType != MutationType.HARD)
            {
                switch (position)
                {
                case 0:
                    PositionsShape[1].PositionY = PositionsShape[position].PositionY;
                    PositionsShape[3].PositionX = PositionsShape[position].PositionX;
                    break;

                case 1:
                    PositionsShape[0].PositionY = PositionsShape[position].PositionY;
                    PositionsShape[2].PositionX = PositionsShape[position].PositionX;
                    break;

                case 2:
                    PositionsShape[1].PositionX = PositionsShape[position].PositionX;
                    PositionsShape[3].PositionY = PositionsShape[position].PositionY;
                    break;

                case 3:
                    PositionsShape[0].PositionX = PositionsShape[position].PositionX;
                    PositionsShape[2].PositionY = PositionsShape[position].PositionY;
                    break;
                }
            }
        }
        protected bool WillMutate()
        {
            if (AlgorithmInformation.MutationChance <= 0)
            {
                AlgorithmInformation.MutationChance = 1;
            }

            if (RandomMutation.RandomIntervalIntegerInclusive(0, 100 - AlgorithmInformation.MutationChance) == 0)
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        public void MediumMutation()
        {
            var point = RandomMutation.RandomIntervalIntegerInclusive(0, 1);

            switch (point)
            {
            case 0:
                PositionX = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageWidth);
                break;

            case 1:
                PositionY = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageHeight);
                break;
            }
        }
예제 #5
0
        private void GaussianMutation()
        {
            var colourOrPosition = RandomMutation.RandomIntervalIntegerInclusive(0, 1);

            switch (colourOrPosition)
            {
            case 0:
                ColourShape.GaussianMutation();
                break;

            case 1:
                MutatePosition();
                break;
            }
        }
예제 #6
0
        public void SoftMutation()
        {
            var point = RandomMutation.RandomIntervalIntegerInclusive(0, 1);

            switch (point)
            {
            case 0:
                PositionX = RandomMutation.RandomPosition(PositionX - AlgorithmInformation.SmallDeltaValue(), PositionX + AlgorithmInformation.SmallDeltaValue());
                break;

            case 1:
                PositionY = RandomMutation.RandomPosition(PositionY - AlgorithmInformation.SmallDeltaValue(), PositionY + AlgorithmInformation.SmallDeltaValue());
                break;
            }

            FixPosition();
        }
        public void GaussianMutation()
        {
            var colourMutation = RandomMutation.RandomIntervalIntegerInclusive(0, 4);

            switch (colourMutation)
            {
            case 1:
                RedColour += (byte)RandomMutation.GaussianRandom(Byte.MaxValue);
                break;

            case 2:
                GreenColour += (byte)RandomMutation.GaussianRandom(Byte.MaxValue);
                break;

            case 3:
                BlueColour += (byte)RandomMutation.GaussianRandom(Byte.MaxValue);
                break;

            case 4:
                AlphaColour += (byte)RandomMutation.GaussianRandom(Byte.MaxValue);
                break;
            }
        }
        public void MediumMutation()
        {
            var colourMutation = RandomMutation.RandomIntervalIntegerInclusive(0, 4);

            switch (colourMutation)
            {
            case 0:
                RedColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
                break;

            case 1:
                GreenColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
                break;

            case 2:
                BlueColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
                break;

            case 3:
                AlphaColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
                break;
            }
        }
        public void SoftMutation()
        {
            var colourMutation = RandomMutation.RandomIntervalIntegerInclusive(0, 4);

            switch (colourMutation)
            {
            case 0:
                RedColour = RandomMutation.RandomColour((byte)(RedColour - AlgorithmInformation.SmallDeltaValue()), (byte)(RedColour + AlgorithmInformation.SmallDeltaValue()));
                break;

            case 1:
                GreenColour = RandomMutation.RandomColour((byte)(GreenColour - AlgorithmInformation.SmallDeltaValue()), (byte)(GreenColour + AlgorithmInformation.SmallDeltaValue()));
                break;

            case 2:
                BlueColour = RandomMutation.RandomColour((byte)(BlueColour - AlgorithmInformation.SmallDeltaValue()), (byte)(BlueColour + AlgorithmInformation.SmallDeltaValue()));
                break;

            case 3:
                AlphaColour = RandomMutation.RandomColour((byte)(BlueColour - AlgorithmInformation.SmallDeltaValue()), (byte)(BlueColour + AlgorithmInformation.SmallDeltaValue()));
                break;
            }
        }
        private Individual Reproduct(Individual mother, Individual father)
        {
            var individualChild = new Individual();

            // triangle shapes
            for (int i = 0; i < mother.TriangleShapes.Count; i++)
            {
                if (RandomMutation.RandomIntervalIntegerInclusive(0, 1) == 0)
                {
                    individualChild.TriangleShapes.Add(mother.TriangleShapes[i].CloneShapeChromosome());
                }
                else
                {
                    individualChild.TriangleShapes.Add(father.TriangleShapes[i].CloneShapeChromosome());
                }

                if (WillMutate())
                {
                    individualChild.TriangleShapes[i].MutateChromosome();
                }
            }

            // square shapes
            for (int i = 0; i < mother.SquareShapes.Count; i++)
            {
                if (RandomMutation.RandomIntervalIntegerInclusive(0, 1) == 0)
                {
                    individualChild.SquareShapes.Add(mother.SquareShapes[i].CloneShapeChromosome());
                }
                else
                {
                    individualChild.SquareShapes.Add(father.SquareShapes[i].CloneShapeChromosome());
                }

                if (WillMutate())
                {
                    individualChild.SquareShapes[i].MutateChromosome();
                }
            }

            // elipse shapes
            for (int i = 0; i < mother.ElipseShapes.Count; i++)
            {
                if (RandomMutation.RandomIntervalIntegerInclusive(0, 1) == 0)
                {
                    individualChild.ElipseShapes.Add(mother.ElipseShapes[i].CloneShapeChromosome());
                }
                else
                {
                    individualChild.ElipseShapes.Add(father.ElipseShapes[i].CloneShapeChromosome());
                }

                if (WillMutate())
                {
                    individualChild.ElipseShapes[i].MutateChromosome();
                }
            }

            // pentagon shapes
            for (int i = 0; i < mother.PentagonShapes.Count; i++)
            {
                if (RandomMutation.RandomIntervalIntegerInclusive(0, 1) == 0)
                {
                    individualChild.PentagonShapes.Add(mother.PentagonShapes[i].CloneShapeChromosome());
                }
                else
                {
                    individualChild.PentagonShapes.Add(father.PentagonShapes[i].CloneShapeChromosome());
                }

                if (WillMutate())
                {
                    individualChild.PentagonShapes[i].MutateChromosome();
                }
            }

            return(individualChild);
        }