Beispiel #1
0
        public override IEnumerable <IChromosome <TVertex, TEdge> > Breed(IChromosome <TVertex, TEdge> other)
        {
            var children = new List <IChromosome <TVertex, TEdge> >();

            foreach (var crossoverGene in CrossoverGenes(other))
            {
                bool Predicate(IWeightedEndpoint <TVertex, TEdge> gene) => !Equals(gene, crossoverGene);

                var thisChild = Genes
                                .TakeWhile(Predicate)
                                .Concat(other.Genes.SkipWhile(Predicate))
                                .ToList();

                var otherChild = other.Genes
                                 .TakeWhile(Predicate)
                                 .Concat(Genes.SkipWhile(Predicate))
                                 .ToList();

                children.Add(new PathChromosome <TVertex, TEdge>(thisChild, Adder, Comparer));
                children.Add(new PathChromosome <TVertex, TEdge>(otherChild, Adder, Comparer));
            }

            return(children);
        }