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