Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.SGA/SGAEditor.cs @ 3747

Last change on this file since 3747 was 65, checked in by swagner, 17 years ago

Fixed ticket #52

  • adapted plugin HeuristicLab.SGA according to changes in CombinedOperator, OperatorExtractor and ItemList
File size: 7.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.SGA {
33  public partial class SGAEditor : EditorBase {
34    private ChooseOperatorDialog chooseOperatorDialog;
35
36    public SGA SGA {
37      get { return (SGA)Item; }
38      set { base.Item = value; }
39    }
40
41    public SGAEditor() {
42      InitializeComponent();
43    }
44    public SGAEditor(SGA sga)
45      : this() {
46      SGA = sga;
47    }
48
49    protected override void RemoveItemEvents() {
50      SGA.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
51      SGA.Engine.Finished -= new EventHandler(Engine_Finished);
52      scopeView.Scope = null;
53      base.RemoveItemEvents();
54    }
55    protected override void AddItemEvents() {
56      base.AddItemEvents();
57      SGA.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
58      SGA.Engine.Finished += new EventHandler(Engine_Finished);
59      SetDataBinding();
60      scopeView.Scope = SGA.Engine.GlobalScope;
61    }
62
63    protected override void UpdateControls() {
64      base.UpdateControls();
65      if (SGA == null) {
66        tabControl.Enabled = false;
67      } else {
68        tabControl.Enabled = true;
69        problemInitializationTextBox.Text = SGA.ProblemInjector.GetType().Name;
70        solutionGenerationTextBox.Text = SGA.SolutionGenerator.GetType().Name;
71        selectionTextBox.Text = SGA.Selector.GetType().Name;
72        crossoverTextBox.Text = SGA.Crossover.GetType().Name;
73        mutationTextBox.Text = SGA.Mutator.GetType().Name;
74        evaluationTextBox.Text = SGA.Evaluator.GetType().Name;
75      }
76    }
77
78    private void SetDataBinding() {
79      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", SGA, "SetSeedRandomly");
80      randomSeedTextBox.DataBindings.Add("Text", SGA, "Seed");
81      populationSizeTextBox.DataBindings.Add("Text", SGA, "PopulationSize");
82      maximumGenerationsTextBox.DataBindings.Add("Text", SGA, "MaximumGenerations");
83      mutationRateTextBox.DataBindings.Add("Text", SGA, "MutationRate");
84      elitesTextBox.DataBindings.Add("Text", SGA, "Elites");
85    }
86
87    #region Button Events
88    private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
89      IView view = SGA.ProblemInjector.CreateView();
90      if (view != null)
91        PluginManager.ControlManager.ShowControl(view);
92    }
93    private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
94      IView view = SGA.SolutionGenerator.CreateView();
95      if (view != null)
96        PluginManager.ControlManager.ShowControl(view);
97    }
98    private void viewSelectionButton_Click(object sender, EventArgs e) {
99      IView view = SGA.Selector.CreateView();
100      if (view != null)
101        PluginManager.ControlManager.ShowControl(view);
102    }
103    private void viewCrossoverButton_Click(object sender, EventArgs e) {
104      IView view = SGA.Crossover.CreateView();
105      if (view != null)
106        PluginManager.ControlManager.ShowControl(view);
107    }
108    private void viewMutationButton_Click(object sender, EventArgs e) {
109      IView view = SGA.Mutator.CreateView();
110      if (view != null)
111        PluginManager.ControlManager.ShowControl(view);
112    }
113    private void viewEvaluationButton_Click(object sender, EventArgs e) {
114      IView view = SGA.Evaluator.CreateView();
115      if (view != null)
116        PluginManager.ControlManager.ShowControl(view);
117    }
118    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
119      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
120      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
121        SGA.ProblemInjector = chooseOperatorDialog.Operator;
122        problemInitializationTextBox.Text = SGA.ProblemInjector.GetType().Name;
123      }
124    }
125    private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
126      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
127      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
128        SGA.SolutionGenerator= chooseOperatorDialog.Operator;
129        solutionGenerationTextBox.Text = SGA.SolutionGenerator.GetType().Name;
130      }
131    }
132    private void setSelectionButton_Click(object sender, EventArgs e) {
133      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
134      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
135        SGA.Selector = chooseOperatorDialog.Operator;
136        selectionTextBox.Text = SGA.Selector.GetType().Name;
137      }
138    }
139    private void setCrossoverButton_Click(object sender, EventArgs e) {
140      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
141      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
142        SGA.Crossover = chooseOperatorDialog.Operator;
143        crossoverTextBox.Text = SGA.Crossover.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        SGA.Mutator = chooseOperatorDialog.Operator;
150        mutationTextBox.Text = SGA.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        SGA.Evaluator = chooseOperatorDialog.Operator;
157        evaluationTextBox.Text = SGA.Evaluator.GetType().Name;
158      }
159    }
160    private void executeButton_Click(object sender, EventArgs e) {
161      executeButton.Enabled = false;
162      abortButton.Enabled = true;
163      SGA.Engine.Execute();
164    }
165    private void abortButton_Click(object sender, EventArgs e) {
166      SGA.Engine.Abort();
167    }
168    private void resetButton_Click(object sender, EventArgs e) {
169      SGA.Engine.Reset();
170    }
171    private void cloneEngineButton_Click(object sender, EventArgs e) {
172      IEngine clone = (IEngine)SGA.Engine.Clone();
173      IEditor editor = ((IEditable)clone).CreateEditor();
174      PluginManager.ControlManager.ShowControl(editor);
175    }
176    #endregion
177
178    #region Engine Events
179    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
180    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
181      if (InvokeRequired)
182        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
183      else
184        Auxiliary.ShowErrorMessageBox(e.Exception);
185    }
186    private void Engine_Finished(object sender, EventArgs e) {
187      scopeView.Refresh();
188      executeButton.Enabled = true;
189      abortButton.Enabled = false;
190    }
191    #endregion
192  }
193}
Note: See TracBrowser for help on using the repository browser.