Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ES/ESEditor.cs @ 87

Last change on this file since 87 was 87, checked in by abeham, 16 years ago

Changed ES strategy switch from button to radiobutton as per request #76

File size: 8.5 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.PluginInfrastructure;
30using HeuristicLab.Core;
31
32namespace HeuristicLab.ES {
33  public partial class ESEditor : EditorBase {
34    private ChooseOperatorDialog chooseOperatorDialog;
35
36    public ES ES {
37      get { return (ES)Item; }
38      set { base.Item = value; }
39    }
40
41    public ESEditor() {
42      InitializeComponent();
43    }
44    public ESEditor(ES es)
45      : this() {
46      ES = es;
47    }
48
49    protected override void RemoveItemEvents() {
50      ES.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
51      ES.Engine.Finished -= new EventHandler(Engine_Finished);
52      ES.Changed -= new EventHandler(ES_Changed);
53      scopeView.Scope = null;
54      base.RemoveItemEvents();
55    }
56    protected override void AddItemEvents() {
57      base.AddItemEvents();
58      ES.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
59      ES.Engine.Finished += new EventHandler(Engine_Finished);
60      ES.Changed += new EventHandler(ES_Changed);
61      SetDataBinding();
62      scopeView.Scope = ES.Engine.GlobalScope;
63    }
64
65    void ES_Changed(object sender, EventArgs e) {
66      // neither Refresh() nor Update() work
67      muTextBox.Text = ES.Mu.ToString();
68      rhoTextBox.Text = ES.Rho.ToString();
69      lambdaTextBox.Text = ES.Lambda.ToString();
70    }
71
72    protected override void UpdateControls() {
73      base.UpdateControls();
74      if (ES == null) {
75        tabControl.Enabled = false;
76      } else {
77        tabControl.Enabled = true;
78        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
79        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
80        mutationTextBox.Text = ES.Mutator.GetType().Name;
81        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
82        recombinationTextBox.Text = ES.Recombinator.GetType().Name;
83      }
84    }
85
86    private void SetDataBinding() {
87      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", ES, "SetSeedRandomly");
88      randomSeedTextBox.DataBindings.Add("Text", ES, "Seed");
89      muTextBox.DataBindings.Add("Text", ES, "Mu");
90      rhoTextBox.DataBindings.Add("Text", ES, "Rho");
91      lambdaTextBox.DataBindings.Add("Text", ES, "Lambda");
92      maximumGenerationsTextBox.DataBindings.Add("Text", ES, "MaximumGenerations");
93      initialMutationStrengthTextBox.DataBindings.Add("Text", ES, "ShakingFactor");
94      targetSuccessRateTextBox.DataBindings.Add("Text", ES, "SuccessProbability");
95      useSuccessRuleCheckBox.DataBindings.Add("Checked", ES, "UseSuccessRule");
96    }
97
98    #region Button Events
99    private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
100      IView view = ES.ProblemInjector.CreateView();
101      if (view != null)
102        PluginManager.ControlManager.ShowControl(view);
103    }
104    private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
105      IView view = ES.SolutionGenerator.CreateView();
106      if (view != null)
107        PluginManager.ControlManager.ShowControl(view);
108    }
109    private void viewMutationButton_Click(object sender, EventArgs e) {
110      IView view = ES.Mutator.CreateView();
111      if (view != null)
112        PluginManager.ControlManager.ShowControl(view);
113    }
114    private void viewEvaluationButton_Click(object sender, EventArgs e) {
115      IView view = ES.Evaluator.CreateView();
116      if (view != null)
117        PluginManager.ControlManager.ShowControl(view);
118    }
119    private void viewRecombinationButton_Click(object sender, EventArgs e) {
120      IView view = ES.Recombinator.CreateView();
121      if (view != null)
122        PluginManager.ControlManager.ShowControl(view);
123    }
124    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
125      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
126      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
127        ES.ProblemInjector = chooseOperatorDialog.Operator;
128        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
129      }
130    }
131    private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
132      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
133      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
134        ES.SolutionGenerator= chooseOperatorDialog.Operator;
135        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
136      }
137    }
138    private void setMutationButton_Click(object sender, EventArgs e) {
139      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
140      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
141        ES.Mutator = chooseOperatorDialog.Operator;
142        mutationTextBox.Text = ES.Mutator.GetType().Name;
143      }
144    }
145    private void setEvaluationButton_Click(object sender, EventArgs e) {
146      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
147      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
148        ES.Evaluator = chooseOperatorDialog.Operator;
149        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
150      }
151    }
152    private void setRecombinationButton_Click(object sender, EventArgs e) {
153      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
154      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
155        ES.Recombinator = chooseOperatorDialog.Operator;
156        recombinationTextBox.Text = ES.Recombinator.GetType().Name;
157      }
158    }
159    private void executeButton_Click(object sender, EventArgs e) {
160      executeButton.Enabled = false;
161      abortButton.Enabled = true;
162      ES.Engine.Execute();
163    }
164    private void abortButton_Click(object sender, EventArgs e) {
165      ES.Engine.Abort();
166    }
167    private void resetButton_Click(object sender, EventArgs e) {
168      ES.Engine.Reset();
169    }
170    private void cloneEngineButton_Click(object sender, EventArgs e) {
171      IEngine clone = (IEngine)ES.Engine.Clone();
172      IEditor editor = ((IEditable)clone).CreateEditor();
173      PluginManager.ControlManager.ShowControl(editor);
174    }
175    #endregion
176
177    #region Engine Events
178    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
179    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
180      if (InvokeRequired)
181        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
182      else
183        Auxiliary.ShowErrorMessageBox(e.Exception);
184    }
185    private void Engine_Finished(object sender, EventArgs e) {
186      scopeView.Refresh();
187      if (executeButton.InvokeRequired) {
188        executeButton.Invoke(new MethodInvoker(EnableExecute));
189      } else {
190        executeButton.Enabled = true;
191        abortButton.Enabled = false;
192      }
193    }
194    private void EnableExecute() {
195      executeButton.Enabled = true;
196      abortButton.Enabled = false;
197    }
198    #endregion
199
200    #region CheckBox Events
201    private void useSuccessRuleCheckBox_CheckedChanged(object sender, EventArgs e) {
202      targetSuccessRateTextBox.Enabled = useSuccessRuleCheckBox.Checked;
203    }
204    #endregion
205
206    #region RadioButton Events
207    private void plusRadioButton_CheckedChanged(object sender, EventArgs e) {
208      if (plusRadioButton.Checked) ES.PlusNotation = true;
209    }
210
211    private void commaRadioButton_CheckedChanged(object sender, EventArgs e) {
212      if (commaRadioButton.Checked) ES.PlusNotation = false;
213    }
214    #endregion
215  }
216}
Note: See TracBrowser for help on using the repository browser.