Exemple #1
0
        /// <inheritdoc/>
        public void PerformOperation(IGenerateRandom rnd, IGenome[] parents, int parentIndex, IGenome[] offspring,
                                     int offspringIndex)
        {
            var          parent1 = (TreeGenome)parents[parentIndex];
            var          parent2 = (TreeGenome)parents[parentIndex];
            EvaluateTree eval    = parent1.Evaluator;

            var off1         = (TreeGenome)_owner.Population.GenomeFactory.Factor(parent1);
            var replacePoint = eval.SampleRandomNode(rnd, off1.Root);
            var copySource   = eval.SampleRandomNode(rnd, parent2.Root);
            var actualCopy   = copySource.Child.Copy();

            if (replacePoint.Parent == null)
            {
                off1.Root = actualCopy;
            }
            else
            {
                var idx = replacePoint.Parent.Children.IndexOf(replacePoint.Child);
                replacePoint.Parent.Children[idx] = actualCopy;
            }

            offspring[0] = off1;
        }
Exemple #2
0
        /// <inheritdoc />
        public void PerformOperation(IGenerateRandom rnd, IGenome[] parents, int parentIndex, IGenome[] offspring,
                                     int offspringIndex)
        {
            var              parent1   = (TreeGenome)parents[parentIndex];
            EvaluateTree     eval      = parent1.Evaluator;
            var              off1      = (TreeGenome)_owner.Population.GenomeFactory.Factor(parent1);
            RandomNodeResult off1Point = eval.SampleRandomNode(rnd, off1.Root);

            int            len            = rnd.NextInt(1, _maxGraftLength + 1);
            TreeGenomeNode randomSequence = eval.Grow(rnd, len);

            if (off1Point.Parent == null)
            {
                off1.Root = randomSequence;
            }
            else
            {
                int idx = off1Point.Parent.Children.IndexOf(off1Point.Child);
                off1Point.Parent.Children[idx] = randomSequence;
            }

            offspring[0] = off1;
        }