Beispiel #1
0
        /// <summary>
        /// Creates a recombination between this object and other.
        /// </summary>
        /// <param name="other">The object to recombine with this object. Must be an EvolvableDoubleArray.</param>
        /// <returns>A recombination between the two objects.</returns>
        public override Evolvable SpawnRecombination(Evolvable other)
        {
            if (other.GetType() != this.GetType())
            {
                return(this);
            }
            var tempOther = (EvolvableDoubleArray)other;

            var tempDArray = new EvolvableDoubleArray(this.MutationChance, this.Random);
            var tempArray  = new double[this.Numbers.Length];

            for (int i = 0; i < this.Numbers.Length; i++)
            {
                tempArray[i] = ((this.Numbers[i] + tempOther.Numbers[i]) / 2) + (this.Random.NextDouble() - 0.5);
            }

            tempDArray.SetNumbers(tempArray);

            return(tempDArray);
        }
Beispiel #2
0
        /// <summary>
        /// Spawns a mutation of this object.
        /// </summary>
        /// <returns>A mutation of this object.</returns>
        public override Evolvable SpawnMutation()
        {
            var tempDArray = new EvolvableDoubleArray(this.MutationChance, this.Random);
            var tempArray  = new double[10];

            for (var i = 0; i < this.Numbers.Length; i++)
            {
                tempArray[i] = this.Numbers[i];

                if (this.Random.NextDouble() > this.MutationChance)
                {
                    continue;
                }

                tempArray[i] += this.Random.NextDouble() - 0.5;
            }

            tempDArray.SetNumbers(tempArray);

            return(tempDArray);
        }