public List <String> run() { List <HarSegment> memory; HarSegment trial; int iter, d; Random rand = new Random(); memory = initMemory(hsm); for (iter = 0; iter < iteration; iter++) { //trial = memory[rand.Next(0, hsm - 1)]; trial = new HarSegment(); for (d = 0; d < 2; d++) { if (rand.NextDouble() < hmcr) { trial = memory[rand.Next(0, hsm - 1)]; if (rand.NextDouble() < par) { if (d == 0) { // var x = rand.NextDouble() * (1 + 1) - 1; trial.x1 = trial.x1 + ((rand.NextDouble() * (1 + 1) - 1) * bw); } else { trial.x2 = trial.x2 + ((rand.NextDouble() * (1 + 1) - 1) * bw); } } } else { if (d == 0) { trial.x1 = min + (max - min) * rand.NextDouble(); } else { trial.x2 = min + (max - min) * rand.NextDouble(); } } } memory = fitness(memory, trial); } ret = new List <string>(); ret.Add(memory[0].x1.ToString()); ret.Add(memory[0].x2.ToString()); ret.Add(memory[0].wynik.ToString()); Console.WriteLine("Harmonia:"); Console.WriteLine("Minimum: " + memory[0].wynik); //Console.WriteLine("Iteracja: " + minIter); return(ret); }
private List <HarSegment> fitness(List <HarSegment> memory, HarSegment trial) { var temp = memory.OrderBy(x => x.wynik).ToList(); if (temp[hsm - 1].wynik > trial.wynik) { temp[hsm - 1] = trial; } return(temp); }