Exemple #1
0
 private void OnBestSolutionFound(object sender, BestSolutionEventArg arg)
 {
     BestSolution = arg.BestSolution;
     //if (_speciesOriginator.TestForNumberOfDoctorsRequired(arg.BestSolution))
     //{
     //    BestSolution = arg.BestSolution;
     //}
 }
Exemple #2
0
        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
            });
        }
Exemple #3
0
        protected virtual void OnBestSolutionFound(BestSolutionEventArg args)
        {
            EventHandler <BestSolutionEventArg> handler = BestSolutionFound;

            handler?.Invoke(this, args);
        }