Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.cs @ 4071

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

Implemented generic EventArgs (#796)

File size: 5.6 KB
Line 
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;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.GP.Algorithms {
29  public partial class OffspringSelectionGpEditor : EditorBase {
30    private ChooseOperatorDialog chooseOperatorDialog;
31
32    public OffspringSelectionGP OffspringSelectionGP {
33      get { return (OffspringSelectionGP)Item; }
34      set { base.Item = value; }
35    }
36
37    public OffspringSelectionGpEditor() {
38      InitializeComponent();
39    }
40    public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
41      : this() {
42      OffspringSelectionGP = osgp;
43    }
44
45    protected override void RemoveItemEvents() {
46      OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
47      OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
48      scopeView.Scope = null;
49      base.RemoveItemEvents();
50    }
51
52    protected override void AddItemEvents() {
53      base.AddItemEvents();
54      OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
55      OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
56      SetDataBinding();
57      scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
58    }
59
60    protected override void UpdateControls() {
61      base.UpdateControls();
62      if (OffspringSelectionGP == null) {
63        tabControl.Enabled = false;
64      } else {
65        tabControl.Enabled = true;
66        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
67      }
68    }
69
70    protected virtual void SetDataBinding() {
71      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
72      randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
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");
78    }
79
80    #region Button Events
81    private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
82      IView view = OffspringSelectionGP.ProblemInjector.CreateView();
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) {
90        OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
91        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
92      }
93    }
94    private void executeButton_Click(object sender, EventArgs e) {
95      executeButton.Enabled = false;
96      abortButton.Enabled = true;
97      resetButton.Enabled = false;
98      OffspringSelectionGP.Engine.Execute();
99    }
100    private void abortButton_Click(object sender, EventArgs e) {
101      OffspringSelectionGP.Engine.Abort();
102    }
103    private void resetButton_Click(object sender, EventArgs e) {
104      OffspringSelectionGP.Engine.Reset();
105    }
106    private void cloneEngineButton_Click(object sender, EventArgs e) {
107      IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
108      IEditor editor = ((IEditable)clone).CreateEditor();
109      PluginManager.ControlManager.ShowControl(editor);
110    }
111    #endregion
112
113    #region Engine Events
114    private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);
115    private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
116      if (InvokeRequired)
117        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
118      else
119        Auxiliary.ShowErrorMessageBox(e.Value);
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;
128        resetButton.Enabled = true;
129      }
130    }
131    #endregion
132
133    private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
134      randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
135      randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
136    }
137  }
138}
Note: See TracBrowser for help on using the repository browser.