Exemplo n.º 1
0
        /// <summary>
        /// Recursivly modify the genotype by mixing 50/50 the parents genetic material.
        /// </summary>
        /// <param name="child">The current extension of the child</param>
        /// <param name="parentA">The current extension of the parent a</param>
        /// <param name="parentB">The current extension of the parent b</param>
        private void recombinaison(Extension child, Extension parentA, Extension parentB)
        {
            // The structure recombination is done only for the first level.
            IEnumerator<Extension> t1 = (IEnumerator<Extension>)parentA.GetEnumerator();
            IEnumerator<Extension> t2 = (IEnumerator<Extension>)parentB.GetEnumerator();

            while (t1.MoveNext() && t2.MoveNext())
            {
                Extension e;
                if (Probability.Test(0.5))
                    e = (Extension)t1.Current.LocalClone();
                else
                    e = (Extension)t2.Current.LocalClone();

                child.AddExtension(e);

                recombinaison(e, t1.Current, t2.Current);
            }
        }