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