[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.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;
|
---|
[2474] | 31 | using HeuristicLab.Common;
|
---|
[1156] | 32 |
|
---|
| 33 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
| 34 | public partial class OffspringSelectionGpEditor : EditorBase {
|
---|
| 35 | private ChooseOperatorDialog chooseOperatorDialog;
|
---|
| 36 |
|
---|
[1287] | 37 | public OffspringSelectionGP OffspringSelectionGP {
|
---|
| 38 | get { return (OffspringSelectionGP)Item; }
|
---|
[1156] | 39 | set { base.Item = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public OffspringSelectionGpEditor() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
[1287] | 45 | public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
|
---|
[1156] | 46 | : this() {
|
---|
[1287] | 47 | OffspringSelectionGP = osgp;
|
---|
[1156] | 48 | }
|
---|
| 49 |
|
---|
| 50 | protected override void RemoveItemEvents() {
|
---|
[2474] | 51 | OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1287] | 52 | OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
|
---|
[1156] | 53 | scopeView.Scope = null;
|
---|
| 54 | base.RemoveItemEvents();
|
---|
| 55 | }
|
---|
[1287] | 56 |
|
---|
[1156] | 57 | protected override void AddItemEvents() {
|
---|
| 58 | base.AddItemEvents();
|
---|
[2474] | 59 | OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1287] | 60 | OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
|
---|
[1156] | 61 | SetDataBinding();
|
---|
[1287] | 62 | scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
|
---|
[1156] | 63 | }
|
---|
| 64 |
|
---|
| 65 | protected override void UpdateControls() {
|
---|
| 66 | base.UpdateControls();
|
---|
[1287] | 67 | if (OffspringSelectionGP == null) {
|
---|
[1156] | 68 | tabControl.Enabled = false;
|
---|
| 69 | } else {
|
---|
| 70 | tabControl.Enabled = true;
|
---|
[1287] | 71 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
|
---|
[1156] | 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[1287] | 75 | protected virtual void SetDataBinding() {
|
---|
| 76 | setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
|
---|
[1873] | 77 | randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
|
---|
[1287] | 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");
|
---|
[1156] | 83 | }
|
---|
| 84 |
|
---|
| 85 | #region Button Events
|
---|
| 86 | private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 87 | IView view = OffspringSelectionGP.ProblemInjector.CreateView();
|
---|
[1156] | 88 | if(view != null)
|
---|
[2744] | 89 | ControlManager.Manager.ShowControl(view);
|
---|
[1156] | 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) {
|
---|
[1287] | 95 | OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
|
---|
| 96 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
|
---|
[1156] | 97 | }
|
---|
| 98 | }
|
---|
| 99 | private void executeButton_Click(object sender, EventArgs e) {
|
---|
| 100 | executeButton.Enabled = false;
|
---|
| 101 | abortButton.Enabled = true;
|
---|
[1287] | 102 | resetButton.Enabled = false;
|
---|
| 103 | OffspringSelectionGP.Engine.Execute();
|
---|
[1156] | 104 | }
|
---|
| 105 | private void abortButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 106 | OffspringSelectionGP.Engine.Abort();
|
---|
[1156] | 107 | }
|
---|
| 108 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 109 | OffspringSelectionGP.Engine.Reset();
|
---|
[1156] | 110 | }
|
---|
| 111 | private void cloneEngineButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 112 | IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
|
---|
[1156] | 113 | IEditor editor = ((IEditable)clone).CreateEditor();
|
---|
[2744] | 114 | ControlManager.Manager.ShowControl(editor);
|
---|
[1156] | 115 | }
|
---|
| 116 | #endregion
|
---|
| 117 |
|
---|
| 118 | #region Engine Events
|
---|
[2474] | 119 | private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);
|
---|
| 120 | private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
[1156] | 121 | if (InvokeRequired)
|
---|
| 122 | Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
|
---|
| 123 | else
|
---|
[2474] | 124 | Auxiliary.ShowErrorMessageBox(e.Value);
|
---|
[1156] | 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;
|
---|
[1287] | 133 | resetButton.Enabled = true;
|
---|
[1156] | 134 | }
|
---|
| 135 | }
|
---|
| 136 | #endregion
|
---|
| 137 |
|
---|
[1287] | 138 | private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 139 | randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 140 | randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 141 | }
|
---|
[1156] | 142 | }
|
---|
| 143 | }
|
---|