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