/// <summary>
        /// Mutate the specified individual.
        /// Shifted line
        /// </summary>
        /// <param name="individual">The individual.</param>
        /// <param name="mutation_probabilty">The probability to mutate each indiviudal.</param>
        public override void Mutate(IIndividual individual, float mutation_probabilty)
        {
            var indexes = RandomizationRnd.GetInts(1, 0, individual.Length);

            foreach (var index in indexes)
            {
                var oldGene = individual.GetGene(index);

                // line endPoints shift
                var shift1 = RandomizationRnd.GetInt(-shift, shift);
                var shift2 = RandomizationRnd.GetInt(-shift, shift);
                var shift3 = RandomizationRnd.GetInt(-shift, shift);
                var shift4 = RandomizationRnd.GetInt(-shift, shift);

                // gene
                LineSegment2D line = (LineSegment2D)oldGene.Value;

                // shifted gene
                var p1 = new Point(line.P1.X + shift1, line.P1.Y + shift2);
                var p2 = new Point(line.P2.X + shift3, line.P2.Y + shift4);

                // sets new gene
                individual.ReplaceGene(index, new Gene(new LineSegment2D(p1, p2)));
            }
        }
        public override Gene GenerateGene()
        {
            var sX = RandomizationRnd.GetInt(0, Width);
            var sY = RandomizationRnd.GetInt(0, Height);

            var shifts = RandomizationRnd.GetInts(2, 0, 30);

            //  return new Gene(new ShapeLine(sX, sY, sX + shifts[0], sY + shifts[1]));
            return(new Gene(new LineSegment2D(new Point(sX, sY), new Point(sX + shifts[0], sY + shifts[1]))));
        }
示例#3
0
        /// <summary>
        /// Cross the specified parents generating the children.
        /// </summary>
        /// <param name="parents">The parents</param>
        /// <returns>The offspring (children) of the parents.</returns>
        public override IList <IIndividual> Cross(IList <IIndividual> parents)
        {
            // same length
            if (parents[0].Length != parents[1].Length)
            {
                return(parents);
            }

            int swapPoint = RandomizationRnd.GetInt(1, parents[0].Length - 2);

            var firstChild  = CreateChild(parents[0], parents[1], swapPoint);
            var secondChild = CreateChild(parents[1], parents[0], swapPoint);

            return(new List <IIndividual>()
            {
                firstChild, secondChild
            });
        }
示例#4
0
 /// <summary>
 /// Generates the gene.
 /// </summary>
 /// <param name="geneIndex">Index of the gene.</param>
 /// <returns>The new Gene.</returns>
 public override Gene GenerateGene()
 {
     return(new Gene(Color.FromArgb(RandomizationRnd.GetInt(0, 256), RandomizationRnd.GetInt(0, 256), RandomizationRnd.GetInt(0, 256))));
 }