using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SIIT_lab3_task2 { public class Chromosom { public static Random rand = new Random(); public string genes; public double X, Y; public Chromosom() { genes = ""; for (int i = 0; i < 22; i++) { genes += rand.NextDouble() > 0.5 ? "1" : "0"; } DetectCoordinates(); } public Chromosom(string genes) { this.genes = genes; DetectCoordinates(); } private void DetectCoordinates() { this.X = genes[0] == '1' ? 1 : (-1) * Convert.ToInt32(genes.Substring(1, genes.Length / 2)) / 1023.0; this.Y = genes[genes.Length / 2] == '1' ? 1 : (-1) * Convert.ToInt32(genes.Substring(genes.Length / 2 + 1)) / 1023.0; } } class Program { public static Random rand = new Random(); static void NextGen(Chromosom p1, Chromosom p2) { int cutIndex = rand.Next(1, 22); Chromosom c1 = new Chromosom(p1.genes.Substring(0, cutIndex)+ p2.genes.Substring(cutIndex)); Chromosom c2 = new Chromosom(p2.genes.Substring(0, cutIndex) + p1.genes.Substring(cutIndex)); } static void Main(string[] args) { Chromosom[] generation = new Chromosom[10]; } } }