public Individual Step() { if (xBest == null) { xBest = _individuals[rnd.Next(nt - 1)]; } var x0 = xBest; if (T > Tf) { for (int i = 0; i < nt; i++) { var x = _individuals[rnd.Next(nt - 1)]; delta = x.Z - x0.Z; if (delta < 0) { if (x.Z < xBest.Z) { xBest = x; } } else { r = (float)rnd.NextDouble(); if (r < Math.Exp(-delta / T)) { x0 = x; } } } T *= alpha; Distance(); } return xBest; }
public Graph() { Individuals = new List<Individual>(); bestIndividual = null; }
private void NextIndividuals() { int count = NumberOfIndividuals; if (bestIndividual != null) { count = NumberOfIndividuals - 1; bestIndividual.Id = count; Individuals.Add(bestIndividual); //UpdatePoints(count, bestIndividual); //points.Positions.Update(count, 1, new float[] { bestIndividual.X, bestIndividual.Y, bestIndividual.Z }); } Random random = new Random(); for (int i = 0; i < count; i++) { var x = (float)NextDouble(random, newXmin, newXmax); var y = (float)NextDouble(random, newYmin, newYmax); if (OnlyIntegers) { x = (float)Math.Round(x); y = (float)Math.Round(y); } TestFunctions testFunctions = new TestFunctions(); var z = RealizeMethod(new double[] { x, y }); Individual individual = new Individual { Id = i, X = x, Y = y, Z = z }; Individuals.Add(individual); //UpdatePoints(i, individual); //points.Positions.Update(i, 1, new float[] { individual.X, individual.Y, individual.Z }); } }
private void UpdatePoints(int startColumn, Individual individual) { points.Positions.Update(startColumn, 1, new float[] { individual.X, individual.Y, individual.Z }); }
public void SetIndividuals() { switch (Algorithm) { case Algorithms.None: bestIndividual = null; Reset(); Individuals.Clear(); NextIndividuals(); break; case Algorithms.BlindSearch: bestIndividual = GetBestIndividual(); Individuals.Clear(); NextIndividuals(); break; case Algorithms.SimulatedAnnealing: simulatedAnnealing.Set(Individuals, Min, Max); bestIndividual = simulatedAnnealing.Step(); newXmin = simulatedAnnealing.newXmin; newXmax = simulatedAnnealing.newXmax; newYmin = simulatedAnnealing.newYmin; newYmax = simulatedAnnealing.newYmax; Individuals.Clear(); NextIndividuals(); break; case Algorithms.DifferentialEvolution: differentialEvolution.Step(Individuals, MethodInfo, Min, Max); Individuals.Clear(); Individuals = differentialEvolution.newIndividuals; break; case Algorithms.SOMA: soma.Step(Individuals, MethodInfo, Min, Max); Individuals.Clear(); Individuals = soma.newIndividuals; break; } if (Individuals.Any()) { var i = 0; foreach (var item in Individuals) { UpdatePoints(i++, item); } } ToFitness(); }