Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffSpringSelectionGpEditor.cs @ 2036

Last change on this file since 2036 was 1873, checked in by gkronber, 16 years ago

Worked on different dispatching of deterministic and non-deterministic modeling algorithms. #635

File size: 5.7 KB
RevLine 
[1156]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.GP.StructureIdentification {
33  public partial class OffspringSelectionGpEditor : EditorBase {
34    private ChooseOperatorDialog chooseOperatorDialog;
35
[1287]36    public OffspringSelectionGP OffspringSelectionGP {
37      get { return (OffspringSelectionGP)Item; }
[1156]38      set { base.Item = value; }
39    }
40
41    public OffspringSelectionGpEditor() {
42      InitializeComponent();
43    }
[1287]44    public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
[1156]45      : this() {
[1287]46      OffspringSelectionGP = osgp;
[1156]47    }
48
49    protected override void RemoveItemEvents() {
[1287]50      OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
51      OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
[1156]52      scopeView.Scope = null;
53      base.RemoveItemEvents();
54    }
[1287]55
[1156]56    protected override void AddItemEvents() {
57      base.AddItemEvents();
[1287]58      OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
59      OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
[1156]60      SetDataBinding();
[1287]61      scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
[1156]62    }
63
64    protected override void UpdateControls() {
65      base.UpdateControls();
[1287]66      if (OffspringSelectionGP == null) {
[1156]67        tabControl.Enabled = false;
68      } else {
69        tabControl.Enabled = true;
[1287]70        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
[1156]71      }
72    }
73
[1287]74    protected virtual void SetDataBinding() {
75      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
[1873]76      randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
[1287]77      populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGP, "PopulationSize");
78      maximumEvaluatedSolutionsTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MaxEvaluatedSolutions");
79      selectionPressureTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SelectionPressureLimit");
80      mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MutationRate");
81      elitesTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Elites");
[1156]82    }
83
84    #region Button Events
85    private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
[1287]86      IView view = OffspringSelectionGP.ProblemInjector.CreateView();
[1156]87      if(view != null)
88        PluginManager.ControlManager.ShowControl(view);
89    }
90
91    private void setProblemInitializationButton_Click(object sender, EventArgs e) {
92      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
93      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
[1287]94        OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
95        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
[1156]96      }
97    }
98    private void executeButton_Click(object sender, EventArgs e) {
99      executeButton.Enabled = false;
100      abortButton.Enabled = true;
[1287]101      resetButton.Enabled = false;
102      OffspringSelectionGP.Engine.Execute();
[1156]103    }
104    private void abortButton_Click(object sender, EventArgs e) {
[1287]105      OffspringSelectionGP.Engine.Abort();
[1156]106    }
107    private void resetButton_Click(object sender, EventArgs e) {
[1287]108      OffspringSelectionGP.Engine.Reset();
[1156]109    }
110    private void cloneEngineButton_Click(object sender, EventArgs e) {
[1287]111      IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
[1156]112      IEditor editor = ((IEditable)clone).CreateEditor();
113      PluginManager.ControlManager.ShowControl(editor);
114    }
115    #endregion
116
117    #region Engine Events
118    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
119    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
120      if (InvokeRequired)
121        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
122      else
123        Auxiliary.ShowErrorMessageBox(e.Exception);
124    }
125    private void Engine_Finished(object sender, EventArgs e) {
126      if(InvokeRequired)
127        Invoke((EventHandler)Engine_Finished, sender, e);
128      else {
129        scopeView.Refresh();
130        executeButton.Enabled = true;
131        abortButton.Enabled = false;
[1287]132        resetButton.Enabled = true;
[1156]133      }
134    }
135    #endregion
136
[1287]137    private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
138      randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
139      randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
140    }
[1156]141  }
142}
Note: See TracBrowser for help on using the repository browser.