示例#1
0
        public Tuple <Individual, Individual> CreateChildren(Individual parent1, Individual parent2)
        {
            var mathParent1 = parent1 as MathIndividual;
            var mathParent2 = parent2 as MathIndividual;

            var parent1Gene = ConvertDoubleToByteArray(mathParent1.X1);
            var parent2Gene = ConvertDoubleToByteArray(mathParent2.X1);

            var crossOverPoint = _random.Next(parent1Gene.Length);
            var child1Gene     = parent1Gene.Take(crossOverPoint).Concat(parent2Gene.Skip(crossOverPoint)).ToArray();
            var child2Gene     = parent2Gene.Take(crossOverPoint).Concat(parent1Gene.Skip(crossOverPoint)).ToArray();

            var child1 = new MathIndividual {
                X1 = ConvertByteArrayToDouble(child1Gene)
            };
            var child2 = new MathIndividual {
                X1 = ConvertByteArrayToDouble(child2Gene)
            };

            return(new Tuple <Individual, Individual>(child1, child2));
        }
示例#2
0
 private bool CheckIfFeasible(MathIndividual individual)
 {
     return(!(individual.X1 < 0.5 || individual.X1 > 1.5));
 }