Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.ES/ESEditor.cs @ 10207

Last change on this file since 10207 was 98, checked in by abeham, 17 years ago

Added the DampeningFactor as variable as well so that Success Rule adjustment is completely configurable (ref ticket #77)

File size: 8.9 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      randomSeedTextBox.Text = ES.Seed.ToString();
68      muTextBox.Text = ES.Mu.ToString();
69      rhoTextBox.Text = ES.Rho.ToString();
70      lambdaTextBox.Text = ES.Lambda.ToString();
71      learningRateTextBox.Text = ES.LearningRate.ToString();
72    }
73
74    protected override void UpdateControls() {
75      base.UpdateControls();
76      if (ES == null) {
77        tabControl.Enabled = false;
78      } else {
79        tabControl.Enabled = true;
80        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
81        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
82        mutationTextBox.Text = ES.Mutator.GetType().Name;
83        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
84        recombinationTextBox.Text = ES.Recombinator.GetType().Name;
85      }
86    }
87
88    private void SetDataBinding() {
89      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", ES, "SetSeedRandomly");
90      randomSeedTextBox.DataBindings.Add("Text", ES, "Seed");
91      muTextBox.DataBindings.Add("Text", ES, "Mu");
92      rhoTextBox.DataBindings.Add("Text", ES, "Rho");
93      lambdaTextBox.DataBindings.Add("Text", ES, "Lambda");
94      maximumGenerationsTextBox.DataBindings.Add("Text", ES, "MaximumGenerations");
95      initialMutationStrengthTextBox.DataBindings.Add("Text", ES, "ShakingFactor");
96      targetSuccessRateTextBox.DataBindings.Add("Text", ES, "SuccessProbability");
97      learningRateTextBox.DataBindings.Add("Text", ES, "LearningRate");
98      dampeningFactorTextBox.DataBindings.Add("Text", ES, "DampeningFactor");
99      useSuccessRuleCheckBox.DataBindings.Add("Checked", ES, "UseSuccessRule");
100    }
101
102    #region Button Events
103    private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
104      IView view = ES.ProblemInjector.CreateView();
105      if (view != null)
106        PluginManager.ControlManager.ShowControl(view);
107    }
108    private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
109      IView view = ES.SolutionGenerator.CreateView();
110      if (view != null)
111        PluginManager.ControlManager.ShowControl(view);
112    }
113    private void viewMutationButton_Click(object sender, EventArgs e) {
114      IView view = ES.Mutator.CreateView();
115      if (view != null)
116        PluginManager.ControlManager.ShowControl(view);
117    }
118    private void viewEvaluationButton_Click(object sender, EventArgs e) {
119      IView view = ES.Evaluator.CreateView();
120      if (view != null)
121        PluginManager.ControlManager.ShowControl(view);
122    }
123    private void viewRecombinationButton_Click(object sender, EventArgs e) {
124      IView view = ES.Recombinator.CreateView();
125      if (view != null)
126        PluginManager.ControlManager.ShowControl(view);
127    }
128    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
129      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
130      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
131        ES.ProblemInjector = chooseOperatorDialog.Operator;
132        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
133      }
134    }
135    private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
136      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
137      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
138        ES.SolutionGenerator= chooseOperatorDialog.Operator;
139        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
140      }
141    }
142    private void setMutationButton_Click(object sender, EventArgs e) {
143      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
144      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
145        ES.Mutator = chooseOperatorDialog.Operator;
146        mutationTextBox.Text = ES.Mutator.GetType().Name;
147      }
148    }
149    private void setEvaluationButton_Click(object sender, EventArgs e) {
150      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
151      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
152        ES.Evaluator = chooseOperatorDialog.Operator;
153        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
154      }
155    }
156    private void setRecombinationButton_Click(object sender, EventArgs e) {
157      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
158      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
159        ES.Recombinator = chooseOperatorDialog.Operator;
160        recombinationTextBox.Text = ES.Recombinator.GetType().Name;
161      }
162    }
163    private void executeButton_Click(object sender, EventArgs e) {
164      executeButton.Enabled = false;
165      abortButton.Enabled = true;
166      ES.Engine.Execute();
167    }
168    private void abortButton_Click(object sender, EventArgs e) {
169      ES.Engine.Abort();
170    }
171    private void resetButton_Click(object sender, EventArgs e) {
172      ES.Engine.Reset();
173    }
174    private void cloneEngineButton_Click(object sender, EventArgs e) {
175      IEngine clone = (IEngine)ES.Engine.Clone();
176      IEditor editor = ((IEditable)clone).CreateEditor();
177      PluginManager.ControlManager.ShowControl(editor);
178    }
179    #endregion
180
181    #region Engine Events
182    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
183    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
184      if (InvokeRequired)
185        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
186      else
187        Auxiliary.ShowErrorMessageBox(e.Exception);
188    }
189    private void Engine_Finished(object sender, EventArgs e) {
190      scopeView.Refresh();
191      if (executeButton.InvokeRequired) {
192        executeButton.Invoke(new MethodInvoker(EnableExecute));
193      } else {
194        executeButton.Enabled = true;
195        abortButton.Enabled = false;
196      }
197    }
198    private void EnableExecute() {
199      executeButton.Enabled = true;
200      abortButton.Enabled = false;
201    }
202    #endregion
203
204    #region CheckBox Events
205    private void useSuccessRuleCheckBox_CheckedChanged(object sender, EventArgs e) {
206      targetSuccessRateTextBox.Enabled = useSuccessRuleCheckBox.Checked;
207      learningRateTextBox.Enabled = useSuccessRuleCheckBox.Checked;
208      dampeningFactorTextBox.Enabled = useSuccessRuleCheckBox.Checked;
209    }
210    #endregion
211
212    #region RadioButton Events
213    private void plusRadioButton_CheckedChanged(object sender, EventArgs e) {
214      if (plusRadioButton.Checked) ES.PlusNotation = true;
215    }
216
217    private void commaRadioButton_CheckedChanged(object sender, EventArgs e) {
218      if (commaRadioButton.Checked) ES.PlusNotation = false;
219    }
220    #endregion
221  }
222}
Note: See TracBrowser for help on using the repository browser.