コード例 #1
0
        // With such approach best decision will be randomized a bit faster
        public string Mutate(string input, int lowerBound, int upperBound)
        {
            var result = input;

            for (var i = 0; i < _times; ++i)
            {
                if (!(_random.NextDouble() <= _chance))
                {
                    continue;
                }

                var index       = _random.Next(input.Length / BinaryConvertor.IntBytes);
                var replaceFrom = index * BinaryConvertor.IntBytes;
                var replaceTo   = replaceFrom + BinaryConvertor.IntBytes;
                var inner       = input.Substring(replaceFrom, BinaryConvertor.IntBytes);
                var oldValue    = Math.Abs(BinaryConvertor.BinaryStringToInts(inner)[0]);
                var newValue    = _random.Next(-oldValue, oldValue);

                result = input.Substring(0, replaceFrom) +
                         BinaryConvertor.IntsToBinaryString(newValue) +
                         input.Substring(replaceTo);
            }

            return(result);
        }
コード例 #2
0
        public string Mutate(string input, int lowerBound, int upperBound)
        {
            var newValue    = _random.Next(lowerBound, upperBound);
            var index       = _random.Next(input.Length / BinaryConvertor.IntBytes);
            var replaceFrom = index * BinaryConvertor.IntBytes;
            var replaceTo   = replaceFrom + BinaryConvertor.IntBytes;

            return(input.Substring(0, replaceFrom) +
                   BinaryConvertor.IntsToBinaryString(newValue) +
                   input.Substring(replaceTo));
        }
コード例 #3
0
        public string GenerateDecision(int lowerBound, int upperBound, int size)
        {
            var values = new int[size];

            for (var i = 0; i < size; ++i)
            {
                values[i] = _random.Next(lowerBound, upperBound);
            }

            return(BinaryConvertor.IntsToBinaryString(values));
        }