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