[1156] | 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 |
|
---|
[1287] | 31 | public OffspringSelectionGP OffspringSelectionGP {
|
---|
| 32 | get { return (OffspringSelectionGP)Item; }
|
---|
[1156] | 33 | set { base.Item = value; }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public OffspringSelectionGpEditor() {
|
---|
| 37 | InitializeComponent();
|
---|
| 38 | }
|
---|
[1287] | 39 | public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
|
---|
[1156] | 40 | : this() {
|
---|
[1287] | 41 | OffspringSelectionGP = osgp;
|
---|
[1156] | 42 | }
|
---|
| 43 |
|
---|
| 44 | protected override void RemoveItemEvents() {
|
---|
[1287] | 45 | OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
|
---|
| 46 | OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
|
---|
[1156] | 47 | scopeView.Scope = null;
|
---|
| 48 | base.RemoveItemEvents();
|
---|
| 49 | }
|
---|
[1287] | 50 |
|
---|
[1156] | 51 | protected override void AddItemEvents() {
|
---|
| 52 | base.AddItemEvents();
|
---|
[1287] | 53 | OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
|
---|
| 54 | OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
|
---|
[1156] | 55 | SetDataBinding();
|
---|
[1287] | 56 | scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
|
---|
[1156] | 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void UpdateControls() {
|
---|
| 60 | base.UpdateControls();
|
---|
[1287] | 61 | if (OffspringSelectionGP == null) {
|
---|
[1156] | 62 | tabControl.Enabled = false;
|
---|
| 63 | } else {
|
---|
| 64 | tabControl.Enabled = true;
|
---|
[1287] | 65 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
|
---|
[1156] | 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[1287] | 69 | protected virtual void SetDataBinding() {
|
---|
| 70 | setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
|
---|
[1873] | 71 | randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
|
---|
[1287] | 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");
|
---|
[1156] | 77 | }
|
---|
| 78 |
|
---|
| 79 | #region Button Events
|
---|
| 80 | private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 81 | IView view = OffspringSelectionGP.ProblemInjector.CreateView();
|
---|
[1156] | 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) {
|
---|
[1287] | 89 | OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
|
---|
| 90 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
|
---|
[1156] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | private void executeButton_Click(object sender, EventArgs e) {
|
---|
| 94 | executeButton.Enabled = false;
|
---|
| 95 | abortButton.Enabled = true;
|
---|
[1287] | 96 | resetButton.Enabled = false;
|
---|
| 97 | OffspringSelectionGP.Engine.Execute();
|
---|
[1156] | 98 | }
|
---|
| 99 | private void abortButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 100 | OffspringSelectionGP.Engine.Abort();
|
---|
[1156] | 101 | }
|
---|
| 102 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 103 | OffspringSelectionGP.Engine.Reset();
|
---|
[1156] | 104 | }
|
---|
| 105 | private void cloneEngineButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 106 | IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
|
---|
[1156] | 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;
|
---|
[1287] | 127 | resetButton.Enabled = true;
|
---|
[1156] | 128 | }
|
---|
| 129 | }
|
---|
| 130 | #endregion
|
---|
| 131 |
|
---|
[1287] | 132 | private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 133 | randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 134 | randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 135 | }
|
---|
[1156] | 136 | }
|
---|
| 137 | }
|
---|