public double[] Evaluate(double[] x) { var state = new ParticleState(x, Calculate(x)); if (BestEvaluation == null || _optimization.IsBetter(state.FitnessValue, BestEvaluation.FitnessValue) < 0) { BestEvaluation = state; } EvaluationsCount++; return(state.FitnessValue); }
private bool _conditionCheck() { var currentBest = GetCurrentBest(); if (_optimizer.IsBetter(currentBest.FitnessValue, _globalBest.FitnessValue) < 0) { _iterationsSinceImprovement = 0; _globalBest = new ParticleState(currentBest.Location, currentBest.FitnessValue); } else { _iterationsSinceImprovement++; } return ((!_parameters.IterationsLimitCondition || _iteration++ < _parameters.Iterations) && (!_parameters.TargetValueCondition || !(_optimizer.AreClose(new [] { _parameters.TargetValue }, _fitnessFunction.BestEvaluation.FitnessValue, _parameters.Epsilon))) && _iterationsSinceImprovement < _parameters.PsoIterationsToRestart ); }