private void OnBestSolutionFound(object sender, BestSolutionEventArg arg) { BestSolution = arg.BestSolution; //if (_speciesOriginator.TestForNumberOfDoctorsRequired(arg.BestSolution)) //{ // BestSolution = arg.BestSolution; //} }
public void CalculateGeneralCost(List <Individual> individuals, int numberOfGenerations) { Parallel.ForEach(individuals, (individual) => { individual.GeneralCost = 0; foreach (var requirement in Requirements) { individual.GeneralCost += requirement.CalculateGeneralCost(individual); } #region RaiseEventIfCurrentSolutionIsBetterThanPrevious if (numberOfGenerations <= 0) { return; } bool lockTaken = false; try { spinLock.Enter(ref lockTaken); if (individual.Fitness >= _highestFitness) { _highestFitness = individual.Fitness; BestSolutionEventArg args = new BestSolutionEventArg { BestSolution = individual }; OnBestSolutionFound(args); } } finally { spinLock.Exit(); } #endregion }); }
protected virtual void OnBestSolutionFound(BestSolutionEventArg args) { EventHandler <BestSolutionEventArg> handler = BestSolutionFound; handler?.Invoke(this, args); }