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 | 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 | lambdaTextBox.Text = ES.Lambda.ToString();
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected override void UpdateControls() {
|
---|
72 | base.UpdateControls();
|
---|
73 | if (ES == null) {
|
---|
74 | tabControl.Enabled = false;
|
---|
75 | } else {
|
---|
76 | tabControl.Enabled = true;
|
---|
77 | problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
|
---|
78 | solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
|
---|
79 | mutationTextBox.Text = ES.Mutator.GetType().Name;
|
---|
80 | evaluationTextBox.Text = ES.Evaluator.GetType().Name;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void SetDataBinding() {
|
---|
85 | setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", ES, "SetSeedRandomly");
|
---|
86 | randomSeedTextBox.DataBindings.Add("Text", ES, "Seed");
|
---|
87 | muTextBox.DataBindings.Add("Text", ES, "Mu");
|
---|
88 | lambdaTextBox.DataBindings.Add("Text", ES, "Lambda");
|
---|
89 | maximumGenerationsTextBox.DataBindings.Add("Text", ES, "MaximumGenerations");
|
---|
90 | initialMutationStrengthTextBox.DataBindings.Add("Text", ES, "ShakingFactor");
|
---|
91 | targetSuccessRateTextBox.DataBindings.Add("Text", ES, "SuccessProbability");
|
---|
92 | useSuccessRuleCheckBox.DataBindings.Add("Checked", ES, "UseSuccessRule");
|
---|
93 | }
|
---|
94 |
|
---|
95 | #region Button Events
|
---|
96 | private void plusNotationButton_Click(object sender, EventArgs e) {
|
---|
97 | if (plusNotationButton.Text.Equals("Plus")) {
|
---|
98 | plusNotationButton.Text = "Point";
|
---|
99 | } else {
|
---|
100 | plusNotationButton.Text = "Plus";
|
---|
101 | }
|
---|
102 | ES.PlusNotation = !ES.PlusNotation;
|
---|
103 | }
|
---|
104 | private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
|
---|
105 | IView view = ES.ProblemInjector.CreateView();
|
---|
106 | if (view != null)
|
---|
107 | PluginManager.ControlManager.ShowControl(view);
|
---|
108 | }
|
---|
109 | private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
|
---|
110 | IView view = ES.SolutionGenerator.CreateView();
|
---|
111 | if (view != null)
|
---|
112 | PluginManager.ControlManager.ShowControl(view);
|
---|
113 | }
|
---|
114 | private void viewMutationButton_Click(object sender, EventArgs e) {
|
---|
115 | IView view = ES.Mutator.CreateView();
|
---|
116 | if (view != null)
|
---|
117 | PluginManager.ControlManager.ShowControl(view);
|
---|
118 | }
|
---|
119 | private void viewEvaluationButton_Click(object sender, EventArgs e) {
|
---|
120 | IView view = ES.Evaluator.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 executeButton_Click(object sender, EventArgs e) {
|
---|
153 | executeButton.Enabled = false;
|
---|
154 | abortButton.Enabled = true;
|
---|
155 | ES.Engine.Execute();
|
---|
156 | }
|
---|
157 | private void abortButton_Click(object sender, EventArgs e) {
|
---|
158 | ES.Engine.Abort();
|
---|
159 | }
|
---|
160 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
161 | ES.Engine.Reset();
|
---|
162 | }
|
---|
163 | private void cloneEngineButton_Click(object sender, EventArgs e) {
|
---|
164 | IEngine clone = (IEngine)ES.Engine.Clone();
|
---|
165 | IEditor editor = ((IEditable)clone).CreateEditor();
|
---|
166 | PluginManager.ControlManager.ShowControl(editor);
|
---|
167 | }
|
---|
168 | #endregion
|
---|
169 |
|
---|
170 | #region Engine Events
|
---|
171 | private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
|
---|
172 | private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
|
---|
173 | if (InvokeRequired)
|
---|
174 | Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
|
---|
175 | else
|
---|
176 | Auxiliary.ShowErrorMessageBox(e.Exception);
|
---|
177 | }
|
---|
178 | private void Engine_Finished(object sender, EventArgs e) {
|
---|
179 | scopeView.Refresh();
|
---|
180 | if (executeButton.InvokeRequired) {
|
---|
181 | executeButton.Invoke(new MethodInvoker(EnableExecute));
|
---|
182 | } else {
|
---|
183 | executeButton.Enabled = true;
|
---|
184 | abortButton.Enabled = false;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | private void EnableExecute() {
|
---|
188 | executeButton.Enabled = true;
|
---|
189 | abortButton.Enabled = false;
|
---|
190 | }
|
---|
191 | #endregion
|
---|
192 |
|
---|
193 | #region CheckBox Events
|
---|
194 | private void useSuccessRuleCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
195 | targetSuccessRateTextBox.Enabled = useSuccessRuleCheckBox.Checked;
|
---|
196 | }
|
---|
197 | #endregion
|
---|
198 | }
|
---|
199 | }
|
---|