Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.Algorithms/3.2/StandardGpEditor.cs @ 3199

Last change on this file since 3199 was 2591, checked in by gkronber, 15 years ago

Copied refactored plugin infrastructure from branch and merged changeset r2586:2589 from branch into the trunk. #799

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