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