Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 71 was 71, checked in by abeham, 15 years ago

Added SGA-like ES interface (ref ticket #18)

File size: 6.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      scopeView.Scope = null;
53      base.RemoveItemEvents();
54    }
55    protected override void AddItemEvents() {
56      base.AddItemEvents();
57      ES.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
58      ES.Engine.Finished += new EventHandler(Engine_Finished);
59      SetDataBinding();
60      scopeView.Scope = ES.Engine.GlobalScope;
61    }
62
63    protected override void UpdateControls() {
64      base.UpdateControls();
65      if (ES == null) {
66        tabControl.Enabled = false;
67      } else {
68        tabControl.Enabled = true;
69        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
70        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
71        mutationTextBox.Text = ES.Mutator.GetType().Name;
72        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
73      }
74    }
75
76    private void SetDataBinding() {
77      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", ES, "SetSeedRandomly");
78      randomSeedTextBox.DataBindings.Add("Text", ES, "Seed");
79      muTextBox.DataBindings.Add("Text", ES, "Mu");
80      lambdaTextBox.DataBindings.Add("Text", ES, "Lambda");
81      maximumGenerationsTextBox.DataBindings.Add("Text", ES, "MaximumGenerations");
82      initialMutationStrengthTextBox.DataBindings.Add("Text", ES, "ShakingFactor");
83      targetSuccessRateTextBox.DataBindings.Add("Text", ES, "SuccessProbability");
84    }
85
86    #region Button Events
87    private void plusNotationButton_Click(object sender, EventArgs e) {
88      if (plusNotationButton.Text.Equals("Plus")) {
89        plusNotationButton.Text = "Point";
90      } else {
91        plusNotationButton.Text = "Plus";
92      }
93      ES.PlusNotation = !ES.PlusNotation;
94    }
95    private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
96      IView view = ES.ProblemInjector.CreateView();
97      if (view != null)
98        PluginManager.ControlManager.ShowControl(view);
99    }
100    private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
101      IView view = ES.SolutionGenerator.CreateView();
102      if (view != null)
103        PluginManager.ControlManager.ShowControl(view);
104    }
105    private void viewMutationButton_Click(object sender, EventArgs e) {
106      IView view = ES.Mutator.CreateView();
107      if (view != null)
108        PluginManager.ControlManager.ShowControl(view);
109    }
110    private void viewEvaluationButton_Click(object sender, EventArgs e) {
111      IView view = ES.Evaluator.CreateView();
112      if (view != null)
113        PluginManager.ControlManager.ShowControl(view);
114    }
115    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
116      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
117      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
118        ES.ProblemInjector = chooseOperatorDialog.Operator;
119        problemInitializationTextBox.Text = ES.ProblemInjector.GetType().Name;
120      }
121    }
122    private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
123      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
124      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
125        ES.SolutionGenerator= chooseOperatorDialog.Operator;
126        solutionGenerationTextBox.Text = ES.SolutionGenerator.GetType().Name;
127      }
128    }
129    private void setMutationButton_Click(object sender, EventArgs e) {
130      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
131      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
132        ES.Mutator = chooseOperatorDialog.Operator;
133        mutationTextBox.Text = ES.Mutator.GetType().Name;
134      }
135    }
136    private void setEvaluationButton_Click(object sender, EventArgs e) {
137      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
138      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
139        ES.Evaluator = chooseOperatorDialog.Operator;
140        evaluationTextBox.Text = ES.Evaluator.GetType().Name;
141      }
142    }
143    private void executeButton_Click(object sender, EventArgs e) {
144      executeButton.Enabled = false;
145      abortButton.Enabled = true;
146      ES.Engine.Execute();
147    }
148    private void abortButton_Click(object sender, EventArgs e) {
149      ES.Engine.Abort();
150    }
151    private void resetButton_Click(object sender, EventArgs e) {
152      ES.Engine.Reset();
153    }
154    private void cloneEngineButton_Click(object sender, EventArgs e) {
155      IEngine clone = (IEngine)ES.Engine.Clone();
156      IEditor editor = ((IEditable)clone).CreateEditor();
157      PluginManager.ControlManager.ShowControl(editor);
158    }
159    #endregion
160
161    #region Engine Events
162    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
163    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
164      if (InvokeRequired)
165        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
166      else
167        Auxiliary.ShowErrorMessageBox(e.Exception);
168    }
169    private void Engine_Finished(object sender, EventArgs e) {
170      scopeView.Refresh();
171      executeButton.Enabled = true;
172      abortButton.Enabled = false;
173    }
174    #endregion
175  }
176}
Note: See TracBrowser for help on using the repository browser.