Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.cs @ 2587

Last change on this file since 2587 was 2474, checked in by swagner, 15 years ago

Implemented generic EventArgs (#796)

File size: 5.6 KB
RevLine 
[1156]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
24using HeuristicLab.PluginInfrastructure;
[2474]25using HeuristicLab.Common;
[1156]26using HeuristicLab.Core;
27
[2331]28namespace HeuristicLab.GP.Algorithms {
[1156]29  public partial class OffspringSelectionGpEditor : EditorBase {
30    private ChooseOperatorDialog chooseOperatorDialog;
31
[1287]32    public OffspringSelectionGP OffspringSelectionGP {
33      get { return (OffspringSelectionGP)Item; }
[1156]34      set { base.Item = value; }
35    }
36
37    public OffspringSelectionGpEditor() {
38      InitializeComponent();
39    }
[1287]40    public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
[1156]41      : this() {
[1287]42      OffspringSelectionGP = osgp;
[1156]43    }
44
45    protected override void RemoveItemEvents() {
[2474]46      OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
[1287]47      OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
[1156]48      scopeView.Scope = null;
49      base.RemoveItemEvents();
50    }
[1287]51
[1156]52    protected override void AddItemEvents() {
53      base.AddItemEvents();
[2474]54      OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
[1287]55      OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
[1156]56      SetDataBinding();
[1287]57      scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
[1156]58    }
59
60    protected override void UpdateControls() {
61      base.UpdateControls();
[1287]62      if (OffspringSelectionGP == null) {
[1156]63        tabControl.Enabled = false;
64      } else {
65        tabControl.Enabled = true;
[1287]66        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
[1156]67      }
68    }
69
[1287]70    protected virtual void SetDataBinding() {
71      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
[1873]72      randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
[1287]73      populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGP, "PopulationSize");
74      maximumEvaluatedSolutionsTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MaxEvaluatedSolutions");
75      selectionPressureTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SelectionPressureLimit");
76      mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MutationRate");
77      elitesTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Elites");
[1156]78    }
79
80    #region Button Events
81    private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
[1287]82      IView view = OffspringSelectionGP.ProblemInjector.CreateView();
[1156]83      if(view != null)
84        PluginManager.ControlManager.ShowControl(view);
85    }
86
87    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
88      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
89      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
[1287]90        OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
91        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
[1156]92      }
93    }
94    private void executeButton_Click(object sender, EventArgs e) {
95      executeButton.Enabled = false;
96      abortButton.Enabled = true;
[1287]97      resetButton.Enabled = false;
98      OffspringSelectionGP.Engine.Execute();
[1156]99    }
100    private void abortButton_Click(object sender, EventArgs e) {
[1287]101      OffspringSelectionGP.Engine.Abort();
[1156]102    }
103    private void resetButton_Click(object sender, EventArgs e) {
[1287]104      OffspringSelectionGP.Engine.Reset();
[1156]105    }
106    private void cloneEngineButton_Click(object sender, EventArgs e) {
[1287]107      IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
[1156]108      IEditor editor = ((IEditable)clone).CreateEditor();
109      PluginManager.ControlManager.ShowControl(editor);
110    }
111    #endregion
112
113    #region Engine Events
[2474]114    private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);
115    private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
[1156]116      if (InvokeRequired)
117        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
118      else
[2474]119        Auxiliary.ShowErrorMessageBox(e.Value);
[1156]120    }
121    private void Engine_Finished(object sender, EventArgs e) {
122      if(InvokeRequired)
123        Invoke((EventHandler)Engine_Finished, sender, e);
124      else {
125        scopeView.Refresh();
126        executeButton.Enabled = true;
127        abortButton.Enabled = false;
[1287]128        resetButton.Enabled = true;
[1156]129      }
130    }
131    #endregion
132
[1287]133    private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
134      randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
135      randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
136    }
[1156]137  }
138}
Note: See TracBrowser for help on using the repository browser.