Free cookie consent management tool by TermsFeed Policy Generator

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

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

Added the possibility to use Recombination in ES (ticket #64)

  • Added ES-specific RandomSelector that creates lambda parent groups of non repeating parents
  • Added the two recombination types: discrete and intermediate for RealVector
  • Updated the ES UI
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 plusNotationButton_Click(object sender, EventArgs e) {
100      if (plusNotationButton.Text.Equals("Plus")) {
101        plusNotationButton.Text = "Comma";
102      } else {
103        plusNotationButton.Text = "Plus";
104      }
105      ES.PlusNotation = !ES.PlusNotation;
106    }
107    private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
108      IView view = ES.ProblemInjector.CreateView();
109      if (view != null)
110        PluginManager.ControlManager.ShowControl(view);
111    }
112    private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
113      IView view = ES.SolutionGenerator.CreateView();
114      if (view != null)
115        PluginManager.ControlManager.ShowControl(view);
116    }
117    private void viewMutationButton_Click(object sender, EventArgs e) {
118      IView view = ES.Mutator.CreateView();
119      if (view != null)
120        PluginManager.ControlManager.ShowControl(view);
121    }
122    private void viewEvaluationButton_Click(object sender, EventArgs e) {
123      IView view = ES.Evaluator.CreateView();
124      if (view != null)
125        PluginManager.ControlManager.ShowControl(view);
126    }
127    private void viewRecombinationButton_Click(object sender, EventArgs e) {
128      IView view = ES.Recombinator.CreateView();
129      if (view != null)
130        PluginManager.ControlManager.ShowControl(view);
131    }
132    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
133      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
134      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
135        ES.ProblemInjector = chooseOperatorDialog.Operator;
136        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
137      }
138    }
139    private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
140      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
141      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
142        ES.SolutionGenerator= chooseOperatorDialog.Operator;
143        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
144      }
145    }
146    private void setMutationButton_Click(object sender, EventArgs e) {
147      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
148      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
149        ES.Mutator = chooseOperatorDialog.Operator;
150        mutationTextBox.Text = ES.Mutator.GetType().Name;
151      }
152    }
153    private void setEvaluationButton_Click(object sender, EventArgs e) {
154      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
155      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
156        ES.Evaluator = chooseOperatorDialog.Operator;
157        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
158      }
159    }
160    private void setRecombinationButton_Click(object sender, EventArgs e) {
161      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
162      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
163        ES.Recombinator = chooseOperatorDialog.Operator;
164        recombinationTextBox.Text = ES.Recombinator.GetType().Name;
165      }
166    }
167    private void executeButton_Click(object sender, EventArgs e) {
168      executeButton.Enabled = false;
169      abortButton.Enabled = true;
170      ES.Engine.Execute();
171    }
172    private void abortButton_Click(object sender, EventArgs e) {
173      ES.Engine.Abort();
174    }
175    private void resetButton_Click(object sender, EventArgs e) {
176      ES.Engine.Reset();
177    }
178    private void cloneEngineButton_Click(object sender, EventArgs e) {
179      IEngine clone = (IEngine)ES.Engine.Clone();
180      IEditor editor = ((IEditable)clone).CreateEditor();
181      PluginManager.ControlManager.ShowControl(editor);
182    }
183    #endregion
184
185    #region Engine Events
186    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
187    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
188      if (InvokeRequired)
189        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
190      else
191        Auxiliary.ShowErrorMessageBox(e.Exception);
192    }
193    private void Engine_Finished(object sender, EventArgs e) {
194      scopeView.Refresh();
195      if (executeButton.InvokeRequired) {
196        executeButton.Invoke(new MethodInvoker(EnableExecute));
197      } else {
198        executeButton.Enabled = true;
199        abortButton.Enabled = false;
200      }
201    }
202    private void EnableExecute() {
203      executeButton.Enabled = true;
204      abortButton.Enabled = false;
205    }
206    #endregion
207
208    #region CheckBox Events
209    private void useSuccessRuleCheckBox_CheckedChanged(object sender, EventArgs e) {
210      targetSuccessRateTextBox.Enabled = useSuccessRuleCheckBox.Checked;
211    }
212    #endregion
213  }
214}
Note: See TracBrowser for help on using the repository browser.