/// <summary>
        /// When overriden in a derived class, generates a crossover based on the parent entities.
        /// </summary>
        /// <param name="parents">The <see cref="GeneticEntity"/> objects to be operated upon.</param>
        /// <returns>
        /// Collection of the <see cref="GeneticEntity"/> objects resulting from the crossover.
        /// </returns>
        protected override IEnumerable <GeneticEntity> GenerateCrossover(IList <GeneticEntity> parents)
        {
            if (parents == null)
            {
                throw new ArgumentNullException(nameof(parents));
            }

            TreeEntityBase tree1 = (TreeEntityBase)parents[0];
            TreeEntityBase tree2 = (TreeEntityBase)parents[1];

            int crossoverLocation1 = RandomNumberService.Instance.GetRandomValue(tree1.GetSize());
            int crossoverLocation2 = RandomNumberService.Instance.GetRandomValue(tree2.GetSize());

            TreeNode swapNode1 = GetSwapNode(tree1, crossoverLocation1);
            TreeNode swapNode2 = GetSwapNode(tree2, crossoverLocation2);

            TreeHelper.Swap(swapNode1, swapNode2);

            List <GeneticEntity> geneticEntities = new List <GeneticEntity>
            {
                tree1,
                tree2
            };

            return(geneticEntities);
        }
 /// <summary>
 /// Returns the node at the specified prefix position.
 /// </summary>
 private static TreeNode GetSwapNode(TreeEntityBase tree, int nodePosition)
 {
     Debug.Assert(nodePosition < tree.GetSize(), "nodePosition must be less than the size of the tree.");
     return(tree.GetPrefixTree().Where((node, index) => index == nodePosition).FirstOrDefault());
 }