src/GenFx.Components/Lists/VariableSinglePointCrossoverOperator.cs
/// <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>
When overriden in a derived class, generates a crossover based on the parent entities.
When overriden in a derived class generates a crossover based on the parent entities .
protected override IEnumerable<GeneticEntity> GenerateCrossover(IList<GeneticEntity> parents)
        {
            if (parents == null)
            {
                throw new ArgumentNullException(nameof(parents));
            }
            ListEntityBase listEntity1 = (ListEntityBase)parents[0];
            ListEntityBase listEntity2 = (ListEntityBase)parents[1];
            int crossoverLocus1 = RandomNumberService.Instance.GetRandomValue(listEntity1.Length);
            int crossoverLocus2 = RandomNumberService.Instance.GetRandomValue(listEntity2.Length);
            IList<GeneticEntity> crossoverOffspring = new List<GeneticEntity>();
            List<object?> entity1Elements = GetEntityElements(listEntity1);
            List<object?> entity2Elements = GetEntityElements(listEntity2);
            ReplaceBits(listEntity1, entity2Elements, crossoverLocus1, crossoverLocus2);
            ReplaceBits(listEntity2, entity1Elements, crossoverLocus2, crossoverLocus1);
            crossoverOffspring.Add(listEntity1);
            crossoverOffspring.Add(listEntity2);
            return crossoverOffspring;
        }
protected override IEnumerable < GeneticEntity > GenerateCrossover ( IList < GeneticEntity > parents ) { if ( parents == null ) { throw new ArgumentNullException ( nameof ( parents ) ) ; } ListEntityBase listEntity1 = ( ListEntityBase ) parents [ 0 ] ; ListEntityBase listEntity2 = ( ListEntityBase ) parents [ 1 ] ; int crossoverLocus1 = RandomNumberService . Instance . GetRandomValue ( listEntity1 . Length ) ; int crossoverLocus2 = RandomNumberService . Instance . GetRandomValue ( listEntity2 . Length ) ; IList < GeneticEntity > crossoverOffspring = new List < GeneticEntity > ( ) ; List < object ? > entity1Elements = GetEntityElements ( listEntity1 ) ; List < object ? > entity2Elements = GetEntityElements ( listEntity2 ) ; ReplaceBits ( listEntity1 , entity2Elements , crossoverLocus1 , crossoverLocus2 ) ; ReplaceBits ( listEntity2 , entity1Elements , crossoverLocus2 , crossoverLocus1 ) ; crossoverOffspring . Add ( listEntity1 ) ; crossoverOffspring . Add ( listEntity2 ) ; return crossoverOffspring ; }
When overriden in a derived class, generates a crossover based on the parent entities.
When overriden in a derived class generates a crossover based on the parent entities .
Collection of the  objects resulting from the crossover.
Collection of the objects resulting from the crossover .
parents
IList<GeneticEntity>
The  objects to be operated upon.
The objects to be operated upon .