Beispiel #1
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationProbability = ParameterSet.GetValue(ParameterNames.MutationProbability);
            var mutationIntensity   = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize           = ParameterSet.GetInt(ParameterNames.BlockSize);

            int    relPos       = Random.GetInt(0, blockSize);
            double modification = Random.GetGaussian(0, mutationIntensity);

            for (int block = 0; block < length / blockSize; block++)
            {
                var rnd = Random.GetDouble(0, 1);
                if (rnd < mutationProbability)
                {
                    var position = blockSize * block + relPos;
                    var gene     = genes.Genes[position];
                    gene += modification;
                    genes.Genes[position] = gene;
                }
            }

            return(genes);
        }
Beispiel #2
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationIntensity = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize         = ParameterSet.GetInt(ParameterNames.BlockSize);

            int    relPos       = Random.GetInt(0, blockSize);
            double modification = Random.GetGaussian(0, mutationIntensity);

            for (int block = 0; block < length / blockSize; block++)
            {
                for (int position = 0; position < blockSize; position++)
                {
                    var gene = genes.Genes[blockSize * block + position];
                    if (position == relPos)
                    {
                        gene += modification;
                    }
                    genes.Genes[blockSize * block + position] = gene;
                }
            }

            return(genes);
        }
Beispiel #3
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationIntensity = ParameterSet.GetValue(ParameterNames.MutationIntensity);

            var position = Random.GetInt(0, length);
            var oldValue = genes.Genes[position];
            var newValue = Random.GetGaussian(oldValue, mutationIntensity);

            genes.Genes[position] = newValue;

            return(chromosome);
        }
Beispiel #4
0
        IEntityList SelectWithHashSet(IEntityList entities, int count)
        {
            HashSet <IEntity> result = new HashSet <IEntity>();
            var tournamentSize       = Convert.ToInt32(ParameterSet.GetValue(ParameterNames.TournamentSize));

            for (int i = 0; i < count; i++)
            {
                var selected = SelectOne(entities, tournamentSize);
                while (result.Contains(selected))
                {
                    selected = SelectOne(entities, tournamentSize);
                }
                result.Add(selected);
            }
            return(new EntityList(result));
        }
Beispiel #5
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationIntensity = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize         = ParameterSet.GetInt(ParameterNames.BlockSize);

            var block = Random.GetInt(0, length / blockSize);

            for (int position = block * blockSize; position < (block + 1) * blockSize - 1; position++)
            {
                var oldValue = genes.Genes[position];
                var newValue = Random.GetGaussian(oldValue, mutationIntensity);

                genes.Genes[position] = newValue;
            }
            return(chromosome);
        }
Beispiel #6
0
 public override IEntityList Select(IEntityList entities, int count)
 {
     if (count == 1)
     {
         var tournamentSize = Convert.ToInt32(ParameterSet.GetValue(ParameterNames.TournamentSize));
         var selected       = SelectOne(entities, tournamentSize);
         var entityList     = new EntityList(1);
         entityList.Add(selected);
         return(entityList);
     }
     //else if (count < 20)
     //{
     return(SelectWithList(entities, count));
     //}
     //else
     //{
     //    return SelectWithHashSet(entities, count);
     //}
 }
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationProbability = ParameterSet.GetValue(ParameterNames.MutationProbability);
            var mutationIntensity   = ParameterSet.GetValue(ParameterNames.MutationIntensity);

            for (int i = 0; i < length; i++)
            {
                var rnd = Random.GetDouble(0, 1);
                if (rnd < mutationProbability)
                {
                    var gene = genes.Genes[i];
                    gene           = Random.GetGaussian(gene, mutationIntensity);
                    genes.Genes[i] = gene;
                }
            }

            return(genes);
        }