static void Main(string[] args) { GameEnvironment.Initialize(20, 20, 3, 5); int genarationCount = 10; int populationSize = 50; double crossRate = 0.9; double mutateRate = 0.9; double cutoff = 0.6; try { GameEnvironment game = new GameEnvironment(); //game.Net.FindResult(new List<int>() { 1, 0, 0, 0 }); //game.Net.Print(); //Console.Out.WriteLine(game.CodeToSymbol(game.Net.Solution)); //game.Net.FindResult(new List<int>() { 0, 0, 0, 1 }); //game.Net.Print(); //Console.Out.WriteLine(game.CodeToSymbol(game.Net.Solution)); //game.Net.FindResult(new List<int>() { 0, 1, 0, 0 }); //game.Net.Print(); //Console.Out.WriteLine(game.CodeToSymbol(game.Net.Solution)); Ga ga = new Ga(genarationCount, populationSize, crossRate, mutateRate, new OnePointСrossover(), new TruncationSelection(cutoff)); ga.Start(); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
public void Cross(IIndividual parent1, IIndividual parent2) { /* Скрещивание между двумя родителями */ int crossPoint = rand.Next(1, parent1.Genes.Count); Child1 = new GameEnvironment(); Child2 = new GameEnvironment(); Child1.Genes.Clear(); Child2.Genes.Clear(); Child1.Genes.AddRange(parent1.Genes.GetRange(0, crossPoint)); Child1.Genes.AddRange(parent2.Genes.GetRange(crossPoint, parent2.Genes.Count - crossPoint)); Child2.Genes.AddRange(parent2.Genes.GetRange(0, crossPoint)); Child2.Genes.AddRange(parent1.Genes.GetRange(crossPoint, parent1.Genes.Count - crossPoint)); }