public void HardMutation()
 {
     RedColour   = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
     GreenColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
     BlueColour  = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
     AlphaColour = RandomMutation.RandomColour(Byte.MinValue, Byte.MaxValue);
 }
Beispiel #2
0
 internal Worker(GraphDatabaseService db, RandomMutation randomMutation, Monitor monitor, int numOpsPerTx)
 {
     this._db             = db;
     this._randomMutation = randomMutation;
     this._monitor        = monitor;
     this._numOpsPerTx    = numOpsPerTx;
 }
Beispiel #3
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;
            }
        }
Beispiel #4
0
 public Workload(GraphDatabaseService db, RandomMutation randomMutation, int threads)
 {
     this._threads  = threads;
     this._sync     = new SyncMonitor(threads);
     this._worker   = new Worker(db, randomMutation, _sync, 100);
     this._executor = Executors.newCachedThreadPool();
 }
        protected override GeneticAlgorithm CreateGA()
        {
            m_fitness = new WallBuilderFitness(SecondsForEvaluation / TimeScale);
            var chromosome = new WallBuilderChromosome(BricksCount, MinPosition, MaxPosition);

            var crossover = new RandomCrossover()
                            .AddCrossover(new UniformCrossover(), 0.9f)
                            .AddCrossover(new SectionCrossover(chromosome.Length / chromosome.BricksCount, true), 0.1f);

            var mutation = new RandomMutation()
                           .AddMutation(new FlipBitMutation(), .9f)
                           .AddMutation(new UniformMutation(), .1f);

            var selection  = new EliteSelection();
            var population = new Population(NumberOfSimultaneousEvaluations, NumberOfSimultaneousEvaluations, chromosome);
            var ga         = new GeneticAlgorithm(population, m_fitness, selection, crossover, mutation);

            ga.Termination  = new TimeEvolvingTermination(System.TimeSpan.FromDays(1));
            ga.TaskExecutor = new ParallelTaskExecutor
            {
                MinThreads = population.MinSize,
                MaxThreads = population.MaxSize * 2
            };
            ga.GenerationRan += delegate
            {
                m_lastPosition = Vector3.zero;
            };

            return(ga);
        }
Beispiel #6
0
        public void GaussianMutation()
        {
            PositionX += RandomMutation.GaussianRandom(AlgorithmInformation.ImageWidth);
            PositionY += RandomMutation.GaussianRandom(AlgorithmInformation.ImageHeight);

            FixPosition();
        }
Beispiel #7
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);
        }
Beispiel #9
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;
            }
        }
Beispiel #10
0
        private void GaussianMutation()
        {
            var colourOrPosition = RandomMutation.RandomIntervalIntegerInclusive(0, 1);

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

            case 1:
                MutatePosition();
                break;
            }
        }
Beispiel #11
0
        public void Test_Mutation_Chain_Fluent()
        {
            var flip     = new FlipMutation();
            var random   = new RandomMutation();
            var gaussian = new GaussianMutation();

            var chain = MutationChain.New(10)
                        .Add(() => flip, 0)
                        .Add(() => random, 4)
                        .Add(() => gaussian, 6);

            Assert.Equal(flip, chain.Mutations.ElementAt(0));
            Assert.Equal(random, chain.Mutations.ElementAt(1));
            Assert.Equal(gaussian, chain.Mutations.ElementAt(2));

            Assert.True(chain.Mutations.Count == 3);
        }
Beispiel #12
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();
        }
Beispiel #13
0
        public void Test_Mutation_Chain_Build()
        {
            MutationChain chain = new MutationChain(5);

            var flip     = new FlipMutation();
            var random   = new RandomMutation();
            var gaussian = new GaussianMutation();

            var chain1 = chain.Add(() => flip, 1);
            var chain2 = chain1.Add(random);
            var chain3 = chain2.Add(() => gaussian, 4);

            Assert.DoesNotContain(flip, chain.Mutations);
            Assert.Contains(flip, chain1.Mutations);

            Assert.DoesNotContain(random, chain1.Mutations);
            Assert.Contains(random, chain2.Mutations);

            Assert.DoesNotContain(gaussian, chain2.Mutations);
            Assert.Contains(gaussian, chain3.Mutations);
        }
        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;
            }
        }
        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 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;
            }
        }
Beispiel #17
0
 public void HardMutation()
 {
     PositionX = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageWidth);
     PositionY = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageHeight);
 }
Beispiel #18
0
 public void InitializeDNA()
 {
     PositionX = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageWidth);
     PositionY = RandomMutation.RandomPosition(0, AlgorithmInformation.ImageHeight);
 }
        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);
        }