public virtual void Transpose(IFitnessFunction <double[], double[]> function) { double[] newLocation; var restart = _sinceLastImprovement == _iterationsToRestart; if (restart) { newLocation = RandomGenerator.GetInstance().RandomVector(CurrentState.Location.Length, Bounds); _sinceLastImprovement = 0; } else { newLocation = GetClampedLocation(CurrentState.Location.Select((x, i) => x + Velocity[i]).ToArray()); } var newVal = function.Evaluate(newLocation); var oldBest = PersonalBest; CurrentState = new ParticleState(newLocation, newVal); if (Optimization.IsBetter(newVal, PersonalBest.FitnessValue) < 0) { PersonalBest = CurrentState; _sinceLastImprovement = 0; } else { _sinceLastImprovement++; } }
private ParticleState BestNeighborState() { ParticleState best = Neighborhood[0].PersonalBest; foreach (var particle in Neighborhood) { if (Optimization.IsBetter(particle.PersonalBest.FitnessValue, best.FitnessValue) < 0) { best = particle.PersonalBest; } } return(best); }
private bool CurrentIsBetterThanBest() { return(Optimization.IsBetter(CurrentState.FitnessValue, PersonalBest.FitnessValue) < 0); }