Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
0
 /// <summary>
 ///     Construct a tree factory.
 /// </summary>
 /// <param name="theEval">The evalator.</param>
 public TreeGenomeFactory(EvaluateTree theEval)
 {
     _eval = theEval;
 }
Пример #4
0
 /// <summary>
 ///     Construct a tree factory.
 /// </summary>
 /// <param name="theEval">The evalator.</param>
 public TreeGenomeFactory(EvaluateTree theEval)
 {
     _eval = theEval;
 }
Пример #5
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="theEvaluator">The evaluator.</param>
 public TreeGenome(EvaluateTree theEvaluator)
 {
     _evaluator = theEvaluator;
 }
Пример #6
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="theEvaluator">The evaluator.</param>
 public TreeGenome(EvaluateTree theEvaluator)
 {
     _evaluator = theEvaluator;
 }