Пример #1
0
        private void HandleNewPopulationFound(SearchResult searchResult)
        {
            double Average(double average, double add)
            {
                return((average * _measureCount + add) / (_measureCount + 1));
            }

            var fitnessRating = searchResult.FitnessRating;

            _fitnessMeasure.Minimum = Average(_fitnessMeasure.Minimum, fitnessRating[fitnessRating.Count - 1].Fitness);
            _fitnessMeasure.Maximum = Average(_fitnessMeasure.Maximum, fitnessRating[0].Fitness);
            _fitnessMeasure.Value   = Average(_fitnessMeasure.Value, fitnessRating.Average(x => x.Fitness));
            _fitnessMeasure.Time    = Generation;

            var simplicityRating = searchResult.SimplicityRating;

            _complexityMeasure.Minimum = Average(_complexityMeasure.Minimum, simplicityRating[0].Complexity);
            _complexityMeasure.Maximum = Average(_complexityMeasure.Maximum,
                                                 simplicityRating[simplicityRating.Count - 1].Complexity);
            _complexityMeasure.Value = Average(_complexityMeasure.Value, simplicityRating.Average(x => x.Complexity));
            _complexityMeasure.Time  = Generation;

            if (FitnessGraph.Count == 0 || ++_measureCount > 20)
            {
                FitnessGraph.Add(_fitnessMeasure);
                ComplexityGraph.Add(_complexityMeasure);
                _measureCount = 0;
            }

            var newWinner           = searchResult.FitnessRating[0];
            var newWinnerEvaluation = XorNetworkSearch.EvaluateWinner(newWinner, IsRecurrent);

            if (_leaderOfRun == null || IsBetterFitness(_leaderOfRun.ParetoFrontPoint, newWinner))
            {
                _leaderOfRun = new WinnerViewModel(
                    newWinner,
                    newWinnerEvaluation,
                    Run, Generation);
            }

            if (Leader == null || Leader.ParetoFrontPoint != newWinner)
            {
                Leader = new WinnerViewModel(
                    newWinner,
                    newWinnerEvaluation,
                    Run, Generation);
                this.RaisePropertyChanged(nameof(Leader));
            }

            if (WinnerByFitnessFromAllRuns == null ||
                IsBetterFitness(WinnerByFitnessFromAllRuns.ParetoFrontPoint, Leader.ParetoFrontPoint))
            {
                WinnerByFitnessFromAllRuns = Leader;
                this.RaisePropertyChanged(nameof(WinnerByFitnessFromAllRuns));
            }

            ++Generation;
            this.RaisePropertyChanged(nameof(Generation));
        }
Пример #2
0
        private void HandleFinishSearchRun()
        {
            WinnerByFitness = _leaderOfRun;
            this.RaisePropertyChanged(nameof(WinnerByFitness));

            if (WinnerBySimplicityFromAllRuns == null ||
                IsBetterComplexity(WinnerBySimplicityFromAllRuns.ParetoFrontPoint, WinnerByFitness.ParetoFrontPoint))
            {
                WinnerBySimplicityFromAllRuns = WinnerByFitness;
                this.RaisePropertyChanged(nameof(WinnerBySimplicityFromAllRuns));
            }

            FitnessGraph.Add(_fitnessMeasure);
            ComplexityGraph.Add(_complexityMeasure);
            _leaderOfRun  = null;
            _measureCount = 0;
        }