/// <summary> /// Initializes a new instance of the IndividualBitmap. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="init">Initilaization genes.</param> public IndividualLines(int width, int height, int numberOfLines, bool init = true) : base(width, height, numberOfLines * 4) { this.numberOfLines = numberOfLines; // Init if (init) { int indexX1 = 0; int indexY1 = 1; int indexX2 = 2; int indexY2 = 3; for (int i = 0; i < numberOfLines; i++) { var sX = FastRandom.GetInt(0, width); var sY = FastRandom.GetInt(0, height); var shifts = FastRandom.GetInts(2, 0, 30); genes[indexX1] = sX; genes[indexY1] = sY; genes[indexX2] = sX + shifts[0]; genes[indexY2] = sY + shifts[1]; indexX1 += 4; indexY1 += 4; indexX2 += 4; indexY2 += 4; } } }
/// <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 = FastRandom.GetInts(mutateRate, 0, individual.Length); foreach (var index in indexes) { var oldGene = individual.GetGene(index); // line endPoints shift var currShift = FastRandom.GetInt(-shift, shift); // sets new gene individual.ReplaceGene(index, oldGene + currShift); } }