src/GenFx/CrossoverOperator.cs
/// <summary>
/// Attempts to perform a crossover between the parent entities if a random value is within
/// the range of the <see cref="CrossoverRate"/>.
/// </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.  If no
/// crossover occurred, this collection contains the original values contained in <paramref name="parents"/>.
/// </returns>
Attempts to perform a crossover between the parent entities if a random value is within
the range of the .
Attempts to perform a crossover between the parent entities if a random value is within the range of the .
public IEnumerable<GeneticEntity> Crossover(IList<GeneticEntity> parents)
        {
            if (parents == null)
            {
                throw new ArgumentNullException(nameof(parents));
            }
            if (RandomNumberService.Instance.GetDouble() <= this.CrossoverRate)
            {
                IList<GeneticEntity> clones = parents.Select(p => p.Clone()).ToList();
                IEnumerable<GeneticEntity> result = this.GenerateCrossover(clones);
                if (result == null)
                {
                    throw new InvalidOperationException(
                        StringUtil.GetFormattedString(Resources.ErrorMsg_NullReturnValue, this.GetType(), nameof(GenerateCrossover)));
                }
                IList<GeneticEntity> crossoverOffspring = result.ToList();
                for (int i = 0; i < crossoverOffspring.Count; i++)
                {
                    crossoverOffspring[i].Age = 0;
                }
                return crossoverOffspring;
            }
            else
            {
                return parents;
            }
        }
public IEnumerable < GeneticEntity > Crossover ( IList < GeneticEntity > parents ) { if ( parents == null ) { throw new ArgumentNullException ( nameof ( parents ) ) ; } if ( RandomNumberService . Instance . GetDouble ( ) <= this . CrossoverRate ) { IList < GeneticEntity > clones = parents . Select ( p => p . Clone ( ) ) . ToList ( ) ; IEnumerable < GeneticEntity > result = this . GenerateCrossover ( clones ) ; if ( result == null ) { throw new InvalidOperationException ( StringUtil . GetFormattedString ( Resources . ErrorMsg_NullReturnValue , this . GetType ( ) , nameof ( GenerateCrossover ) ) ) ; } IList < GeneticEntity > crossoverOffspring = result . ToList ( ) ; for ( int i = 0 ; i < crossoverOffspring . Count ; i ++ ) { crossoverOffspring [ i ] . Age = 0 ; } return crossoverOffspring ; } else { return parents ; } }
Attempts to perform a crossover between the parent entities if a random value is within
the range of the .
Attempts to perform a crossover between the parent entities if a random value is within the range of the .
Collection of the  objects resulting from the crossover.  If no
crossover occurred, this collection contains the original values contained in .
Collection of the objects resulting from the crossover . If no crossover occurred this collection contains the original values contained in .
parents
IList<GeneticEntity>
The  objects to be operated upon.
The objects to be operated upon .