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