예제 #1
0
        public CrossingResult Cross(Individual other)
        {
            var first = this.Genom.Take(Genom.Length / 2).ToList();

            for (int i = 0; i < Genom.Length - (Genom.Length / 2); i++)
            {
                first.Add(other.Genom.First(x => !first.Contains(x)));
            }

            var second = other.Genom.Take(other.Genom.Length / 2).ToList();

            for (int i = 0; i < other.Genom.Length - (other.Genom.Length / 2); i++)
            {
                second.Add(Genom.First(x => !second.Contains(x)));
            }

            return(new CrossingResult()
            {
                First = new TspIndividual(_fitnessFunc, first.ToArray(), _randomProvider),
                Second = new TspIndividual(_fitnessFunc, second.ToArray(), _randomProvider)
            });
        }