private async void Run_Click(object sender, EventArgs e) { maximumChildsTextBox.Text = ""; ExcutedTimeTextBox.Text = "0"; var mainFormGettingStarted = new MinFunGettingStarted ( int.Parse(MinFuncEarlyPopulationTextBox.Text), int.Parse(MinFuncNumberOfParentsTextBox.Text), int.Parse(MinFuncNumberOfGenerationRepetitionsTextBox.Text), int.Parse(MinFuncChromosomeLength.Text), double.Parse(sigmaTextBox.Text), int.Parse(KTournamentCheckBox.Text), int.Parse(aTextBox.Text), int.Parse(bTextBox.Text), int.Parse(cTextBox.Text), FindFunctionSelected(), FindSelections(), FindRecombination(), FindMutation() ); InitializeService(mainFormGettingStarted); //Process in Handle Traner Process //var trainer = new MinPointFunctionTrain(mainFormGettingStarted, new Function1()); var trainer = new MinPointFunctionTrain(_selectionList, _reCombinationList, _mutationList, _functionList); trainer.TryChanged += Trainer_TryChanged; trainer.ParentChanged += Trainer_ParentChanged; trainer.MaximumChildChanged += Trainer_MaximumChildChanged; _timer.Start(); Run.Enabled = false; await trainer.DoTrain(mainFormGettingStarted); _timer.Stop(); MessageBox.Show($"Fitness: {trainer.ExcetedFitness.Fitness}\nTime: {_timeCount / 100}s" + $" \nChoromosome: {PrintnChoromosome(trainer.ExcetedFitness)}"); Run.Enabled = true; }
private void InitializeService(MinFunGettingStarted gettingStarted) { #region Selection Init _randomSelection = new MinFuncRandomSelection(gettingStarted.EarlyPopulation); _randomSelfAdaptionSelection = new MinFuncSelfAdaptionRandomSelection(gettingStarted.EarlyPopulation); _rouletteWeelSelection = new MinFuncRouletteWeelSelection(); _susSelection = new MinFuncStochasticSampleSelection(); _tournamentSelection = new MinFuncTournamentSelection(gettingStarted.KIndividualTornomantInit); _selectionList.Add(_randomSelection); _selectionList.Add(_randomSelfAdaptionSelection); _selectionList.Add(_rouletteWeelSelection); _selectionList.Add(_susSelection); _selectionList.Add(_tournamentSelection); #endregion #region Recombination Init _singleRecombination = new MinFuncSingleRecombination(gettingStarted.ChoromosemeLenght, 0.5); _simpleRecombination = new MinFuncSimpleRecombination(gettingStarted.ChoromosemeLenght, 0.5); _wholeRecombination = new MinFuncWholeRecombination(gettingStarted.ChoromosemeLenght, 0.5); _reCombinationList.Add(_singleRecombination); _reCombinationList.Add(_simpleRecombination); _reCombinationList.Add(_wholeRecombination); #endregion #region Mutation Init _onePerFiveMutation = new MinFuncOnePerFiveMutation(gettingStarted.ChoromosemeLenght, gettingStarted.Sigma); _selfAdaptionMutation = new MinFuncSelfAdaptionMutation(gettingStarted.ChoromosemeLenght, gettingStarted.Sigma); _mutationList.Add(_onePerFiveMutation); _mutationList.Add(_selfAdaptionMutation); #endregion #region Functions _function1 = new Function1(10); _function2 = new Function2(gettingStarted.A, gettingStarted.B, gettingStarted.C); _function3 = new Function3(); _functionList.Add(_function1); _functionList.Add(_function2); _functionList.Add(_function3); #endregion }