コード例 #1
0
        public Mutation GetMutation(MutationStrategy type)
        {
            var mutation = (Mutation)Reflection.GetObjectFromType(_mutations[type]);

            mutation.MutationType = type;
            return(mutation);
        }
コード例 #2
0
        private void PerformFlipMutation(MutationStrategy type)
        {
            if (type != MutationStrategy.Flip)
            {
                return;
            }

            var fields = GeneFieldRepository.Instance.GetFieldsFor(this);

            foreach (var f in fields)
            {
                SetFieldWithFlippedValue(f.Field);
                SetFieldWithFlippedValue(f.Field);
                SetFieldWithFlippedValue(f.Field);
            }
        }
コード例 #3
0
        private void PerformRandomMutation(MutationStrategy type)
        {
            if (type != MutationStrategy.Random)
            {
                return;
            }
            var attributes = new List <object>();

            var fields = GeneFieldRepository.Instance.GetFieldsFor(this);

            foreach (var f in fields)
            {
                SetFieldWithRandomValue(f.Field, f.Attribute.IntValues);
                SetFieldWithRandomValue(f.Field, f.Attribute.CharValues);
                SetFieldWithRandomValue(f.Field, f.Attribute.StringValues);
            }
        }
コード例 #4
0
        private void PerformBoundaryMutation(MutationStrategy type)
        {
            if (type != MutationStrategy.Boundary)
            {
                return;
            }


            var fields = GeneFieldRepository.Instance.GetFieldsFor(this);

            foreach (var f in fields)
            {
                var shouldSetToTopValue = _random.Next(0, 2) == 1;

                SetFieldWithBoundaryValue(f.Field, f.Attribute.IntValues, shouldSetToTopValue);
                SetFieldWithBoundaryValue(f.Field, f.Attribute.CharValues, shouldSetToTopValue);
                SetFieldWithBoundaryValue(f.Field, f.Attribute.StringValues, shouldSetToTopValue);
            }
        }
コード例 #5
0
 public PexEvolutionStrategyArithmeticSolver(
     string explorationName,
     bool isLoggingEnabled,
     bool isLoggingVerboseEnabled,
     int fitnessBudget,
     int populationSize,
     int offspringPopulationSize,
     RecombinationStrategy recombination,
     MutationStrategy mutation,
     bool selectFromOffspringOnly)
     : base(explorationName, isLoggingEnabled, isLoggingVerboseEnabled, fitnessBudget, "ES", null)
 {
     this.variableCount           = 0;
     this.populationSize          = populationSize;
     this.offspringPopulationSize = offspringPopulationSize;
     this.parentPopulation        = new ESSolution[this.populationSize];
     this.intermediatePopulation  = new SafeList <ESSolution>();
     this.selectFromOffspringOnly = selectFromOffspringOnly;
     this.recombination           = recombination;
     this.mutation = mutation;
 }
コード例 #6
0
        //this function will mutate the oracle's list of prophecies, and create a new oracle
        public Oracle spawnMutant(MutationStrategy strategy)
        {
            //for now, we don't do any real mutation
            switch (strategy)
            {
            case MutationStrategy.Equilibrium:
                return(new Oracle(prophecy));

            case MutationStrategy.Aggressive:
                return(new Oracle(mutateExpressionTree(expression: (LeagueStatement)this.prophecy, mutationChance: .75)));

            case MutationStrategy.Normal:
                return(new Oracle(mutateExpressionTree(expression: (LeagueStatement)this.prophecy, mutationChance: .5)));

            case MutationStrategy.Slow:
                return(new Oracle(mutateExpressionTree(expression: (LeagueStatement)this.prophecy, mutationChance: .25)));

            default:
                return(null);
            }
        }
コード例 #7
0
        public void ValidateProperties()
        {
            if (MutationRate < 0 || MutationRate > 1 || ElitismRate < 0 || ElitismRate > 1 || CrossoverRate < 0 || CrossoverRate > 1)
            {
                throw new ArgumentException("GAConfiguration rates must be between 0 and 1");
            }

            if (RetirementStrategy != Factory.Enums.RetirementStrategy.None)
            {
                if (MaxRetirement <= 1)
                {
                    throw new ArgumentException("Retirement maximum must be above 1 for this type of retirement type");
                }
            }

            if (!Enum.IsDefined(RetirementStrategy.GetType(), (int)RetirementStrategy))
            {
                throw new ArgumentException("RetirementType must be defined");
            }
            if (!Enum.IsDefined(CrossoverStrategy.GetType(), (int)CrossoverStrategy))
            {
                throw new ArgumentException("CrossoverType must be defined");
            }
            if (!Enum.IsDefined(ImmigrationStrategy.GetType(), (int)ImmigrationStrategy))
            {
                throw new ArgumentException("ImmigrationType must be defined");
            }
            if (!Enum.IsDefined(MutationStrategy.GetType(), (int)MutationStrategy))
            {
                throw new ArgumentException("MutationType must be defined");
            }
            if (!Enum.IsDefined(ParentSelectionStrategy.GetType(), (int)ParentSelectionStrategy))
            {
                throw new ArgumentException("ParentSelectionType must be defined");
            }
        }
コード例 #8
0
 private static OperationNode Prepare(QueryPlanContext context)
 {
     return(context.Operation.Definition.Operation is OperationType.Mutation
         ? MutationStrategy.Build(context)
         : QueryStrategy.Build(context));
 }
コード例 #9
0
        public void Mutate(double rate, int amount, MutationStrategy strategy, int partition = 1)
        {
            if (amount == 0)
            {
                return;
            }

            int _Treshold = (int)(FullSequence.Length - FullSequence.Length * rate);
            int _Count    = 0;


            switch (strategy)
            {
            case MutationStrategy.BinarySwap:

                for (int i = 0; i < Compontents.Count; i++)
                {
                    if (Globals.GlobalRandom.Next(0, FullSequence.Length) < _Treshold)
                    {
                        continue;
                    }

                    char[] _seq = Compontents[i].FullSequence.ToCharArray();
                    for (int j = 0; j < _seq.Length; j++)
                    {
                        if (Globals.GlobalRandom.Next(0, FullSequence.Length) > _Treshold)
                        {
                            continue;
                        }

                        _seq[j] = _seq[j] == '0' ? '1' : '0';
                        _Count++;
                    }

                    Compontents[i].FullSequence = new string(_seq);
                }

                this.FullSequence = "";

                for (int i = 0; i < Compontents.Count; i++)
                {
                    FullSequence += Compontents[i].FullSequence;
                }


                break;


            case MutationStrategy.SegmentSwap:

                int length = FullSequence.Length;

                if (Compontents.Count == 0)
                {
                    Compontents.Add(this);
                }

                for (int i = 0; i < Compontents.Count; i++)
                {
                    if (Globals.GlobalRandom.Next(0, length) < _Treshold)
                    {
                        continue;
                    }

                    string[] _seq = Compontents[i].FullSequence.GetParts(partition);
                    for (int j = 0; j < _seq.Length; j++)
                    {
                        if (Globals.GlobalRandom.Next(0, length) < _Treshold)
                        {
                            continue;
                        }

                        int    randomIndex = Globals.GlobalRandom.Next(0, _seq.Length);
                        string oldVal      = _seq[randomIndex];
                        _seq[randomIndex] = _seq[j];
                        _seq[j]           = oldVal;
                    }

                    Compontents[i].FullSequence = "";
                    for (int k = 0; k < _seq.Length; k++)
                    {
                        Compontents[i].FullSequence += _seq[k];
                    }
                }



                break;
            }


            Mutate(rate, amount - 1, strategy, partition);
        }
コード例 #10
0
 public void Mutate(MutationStrategy type)
 {
     PerformRandomMutation(type);
     PerformBoundaryMutation(type);
     PerformFlipMutation(type);
 }