[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;
|
---|
[2474] | 25 | using HeuristicLab.Common;
|
---|
[1156] | 26 | using HeuristicLab.Core;
|
---|
| 27 |
|
---|
[2331] | 28 | namespace HeuristicLab.GP.Algorithms {
|
---|
[1156] | 29 | public partial class OffspringSelectionGpEditor : EditorBase {
|
---|
| 30 | private ChooseOperatorDialog chooseOperatorDialog;
|
---|
| 31 |
|
---|
[1287] | 32 | public OffspringSelectionGP OffspringSelectionGP {
|
---|
| 33 | get { return (OffspringSelectionGP)Item; }
|
---|
[1156] | 34 | set { base.Item = value; }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public OffspringSelectionGpEditor() {
|
---|
| 38 | InitializeComponent();
|
---|
| 39 | }
|
---|
[1287] | 40 | public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
|
---|
[1156] | 41 | : this() {
|
---|
[1287] | 42 | OffspringSelectionGP = osgp;
|
---|
[1156] | 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override void RemoveItemEvents() {
|
---|
[2474] | 46 | OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1287] | 47 | OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
|
---|
[1156] | 48 | scopeView.Scope = null;
|
---|
| 49 | base.RemoveItemEvents();
|
---|
| 50 | }
|
---|
[1287] | 51 |
|
---|
[1156] | 52 | protected override void AddItemEvents() {
|
---|
| 53 | base.AddItemEvents();
|
---|
[2474] | 54 | OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1287] | 55 | OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
|
---|
[1156] | 56 | SetDataBinding();
|
---|
[1287] | 57 | scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
|
---|
[1156] | 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void UpdateControls() {
|
---|
| 61 | base.UpdateControls();
|
---|
[1287] | 62 | if (OffspringSelectionGP == null) {
|
---|
[1156] | 63 | tabControl.Enabled = false;
|
---|
| 64 | } else {
|
---|
| 65 | tabControl.Enabled = true;
|
---|
[2728] | 66 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.Name;
|
---|
| 67 | functionLibraryInjectorTextBox.Text = OffspringSelectionGP.FunctionLibraryInjector.Name;
|
---|
[1156] | 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[1287] | 71 | protected virtual void SetDataBinding() {
|
---|
| 72 | setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
|
---|
[1873] | 73 | randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "RandomSeed");
|
---|
[1287] | 74 | populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGP, "PopulationSize");
|
---|
| 75 | maximumEvaluatedSolutionsTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MaxEvaluatedSolutions");
|
---|
| 76 | selectionPressureTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SelectionPressureLimit");
|
---|
| 77 | mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MutationRate");
|
---|
| 78 | elitesTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Elites");
|
---|
[2728] | 79 | comparisonFactorTextBox.DataBindings.Add("Text", OffspringSelectionGP, "ComparisonFactor");
|
---|
| 80 | successRatioLimitTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SuccessRatioLimit");
|
---|
[1156] | 81 | }
|
---|
| 82 |
|
---|
| 83 | #region Button Events
|
---|
| 84 | private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 85 | IView view = OffspringSelectionGP.ProblemInjector.CreateView();
|
---|
[2728] | 86 | if (view != null)
|
---|
[2591] | 87 | ControlManager.Manager.ShowControl(view);
|
---|
[1156] | 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) {
|
---|
[1287] | 93 | OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
|
---|
[2728] | 94 | problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.Name;
|
---|
[1156] | 95 | }
|
---|
| 96 | }
|
---|
[2728] | 97 |
|
---|
| 98 | private void functionLibraryInjectorViewButton_Click(object sender, EventArgs e) {
|
---|
| 99 | IView view = OffspringSelectionGP.FunctionLibraryInjector.CreateView();
|
---|
| 100 | if (view != null)
|
---|
| 101 | ControlManager.Manager.ShowControl(view);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void functionLibraryInjectorSetButton_Click(object sender, EventArgs e) {
|
---|
| 105 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 106 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 107 | OffspringSelectionGP.FunctionLibraryInjector = chooseOperatorDialog.Operator;
|
---|
| 108 | functionLibraryInjectorTextBox.Text = OffspringSelectionGP.FunctionLibraryInjector.Name;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[1156] | 112 | private void executeButton_Click(object sender, EventArgs e) {
|
---|
| 113 | executeButton.Enabled = false;
|
---|
| 114 | abortButton.Enabled = true;
|
---|
[1287] | 115 | resetButton.Enabled = false;
|
---|
| 116 | OffspringSelectionGP.Engine.Execute();
|
---|
[1156] | 117 | }
|
---|
| 118 | private void abortButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 119 | OffspringSelectionGP.Engine.Abort();
|
---|
[1156] | 120 | }
|
---|
| 121 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 122 | OffspringSelectionGP.Engine.Reset();
|
---|
[1156] | 123 | }
|
---|
| 124 | private void cloneEngineButton_Click(object sender, EventArgs e) {
|
---|
[1287] | 125 | IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
|
---|
[1156] | 126 | IEditor editor = ((IEditable)clone).CreateEditor();
|
---|
[2591] | 127 | ControlManager.Manager.ShowControl(editor);
|
---|
[1156] | 128 | }
|
---|
| 129 | #endregion
|
---|
| 130 |
|
---|
| 131 | #region Engine Events
|
---|
[2474] | 132 | private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);
|
---|
| 133 | private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
[1156] | 134 | if (InvokeRequired)
|
---|
| 135 | Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
|
---|
| 136 | else
|
---|
[2474] | 137 | Auxiliary.ShowErrorMessageBox(e.Value);
|
---|
[1156] | 138 | }
|
---|
| 139 | private void Engine_Finished(object sender, EventArgs e) {
|
---|
[2728] | 140 | if (InvokeRequired)
|
---|
[1156] | 141 | Invoke((EventHandler)Engine_Finished, sender, e);
|
---|
| 142 | else {
|
---|
| 143 | scopeView.Refresh();
|
---|
| 144 | executeButton.Enabled = true;
|
---|
| 145 | abortButton.Enabled = false;
|
---|
[1287] | 146 | resetButton.Enabled = true;
|
---|
[1156] | 147 | }
|
---|
| 148 | }
|
---|
| 149 | #endregion
|
---|
| 150 |
|
---|
[1287] | 151 | private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 152 | randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 153 | randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
|
---|
| 154 | }
|
---|
[2728] | 155 |
|
---|
| 156 | private void randomSeedTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 157 | int randomSeed;
|
---|
| 158 | if (int.TryParse(randomSeedTextBox.Text, out randomSeed)) {
|
---|
| 159 | //OffspringSelectionGP.RandomSeed = randomSeed;
|
---|
| 160 | errorProvider.SetError(randomSeedTextBox, string.Empty);
|
---|
| 161 | } else {
|
---|
| 162 | errorProvider.SetError(randomSeedTextBox, "Invalid value.");
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | private void populationSizeTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 167 | int popSize;
|
---|
| 168 | if (int.TryParse(populationSizeTextBox.Text, out popSize) && popSize > 1) {
|
---|
| 169 | //OffspringSelectionGP.PopulationSize = popSize;
|
---|
| 170 | errorProvider.SetError(populationSizeTextBox, string.Empty);
|
---|
| 171 | } else {
|
---|
| 172 | errorProvider.SetError(populationSizeTextBox, "Population size must be a positive integer > 0.");
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | private void elitesTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 177 | int elites;
|
---|
| 178 | if (int.TryParse(elitesTextBox.Text, out elites) && elites >= 0 && elites < OffspringSelectionGP.PopulationSize) {
|
---|
| 179 | //OffspringSelectionGP.Elites = elites;
|
---|
| 180 | errorProvider.SetError(elitesTextBox, string.Empty);
|
---|
| 181 | } else {
|
---|
| 182 | errorProvider.SetError(elitesTextBox, "Invalid value for number of elites. Allowed range [0.." + OffspringSelectionGP.PopulationSize + "[.");
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | private void mutationRateTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 187 | double mutationRate;
|
---|
| 188 | if (double.TryParse(mutationRateTextBox.Text, out mutationRate) && mutationRate >= 0.0 && mutationRate <= 1.0) {
|
---|
| 189 | //OffspringSelectionGP.MutationRate = mutationRate;
|
---|
| 190 | errorProvider.SetError(mutationRateTextBox, string.Empty);
|
---|
| 191 | } else {
|
---|
| 192 | errorProvider.SetError(mutationRateTextBox, "Invalid value for mutation rate. Allowed range = [0..1].");
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | private void comparisonFactorTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 197 | double comparisonFactor;
|
---|
| 198 | if (double.TryParse(comparisonFactorTextBox.Text, out comparisonFactor) && comparisonFactor >= 0.0 && comparisonFactor <= 1.0) {
|
---|
| 199 | //OffspringSelectionGP.ComparisonFactor = comparisonFactor;
|
---|
| 200 | errorProvider.SetError(comparisonFactorTextBox, string.Empty);
|
---|
| 201 | } else {
|
---|
| 202 | errorProvider.SetError(comparisonFactorTextBox, "Invalid value for comparison factor. Allowed range = [0..1].");
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | private void successRatioLimitTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 207 | double successRatioLimit;
|
---|
| 208 | if (double.TryParse(successRatioLimitTextBox.Text, out successRatioLimit) && successRatioLimit >= 0.0 && successRatioLimit <= 1.0) {
|
---|
| 209 | //OffspringSelectionGP.SuccessRatioLimit = successRatioLimit;
|
---|
| 210 | errorProvider.SetError(successRatioLimitTextBox, string.Empty);
|
---|
| 211 | } else {
|
---|
| 212 | errorProvider.SetError(successRatioLimitTextBox, "Invalid value for success ratio limit. Allowed range = [0..1].");
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | private void maximumEvaluatedSolutionsTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 217 | int maxEvaluatedSolutions;
|
---|
| 218 | if (int.TryParse(maximumEvaluatedSolutionsTextBox.Text, out maxEvaluatedSolutions) && maxEvaluatedSolutions > 0) {
|
---|
| 219 | //OffspringSelectionGP.MaxEvaluatedSolutions = maxEvaluatedSolutions;
|
---|
| 220 | errorProvider.SetError(maximumEvaluatedSolutionsTextBox, string.Empty);
|
---|
| 221 | } else {
|
---|
| 222 | errorProvider.SetError(maximumEvaluatedSolutionsTextBox, "Max. evaluated solutions must be a positive integer > 0.");
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | private void selectionPressureTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 227 | double maxSelPres;
|
---|
| 228 | if (double.TryParse(selectionPressureTextBox.Text, out maxSelPres) && maxSelPres > 1.0) {
|
---|
| 229 | //OffspringSelectionGP.SelectionPressureLimit = maxSelPres;
|
---|
| 230 | errorProvider.SetError(selectionPressureTextBox, string.Empty);
|
---|
| 231 | } else {
|
---|
| 232 | errorProvider.SetError(selectionPressureTextBox, "Selection pressure limit must be > 1.0.");
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
[1156] | 235 | }
|
---|
| 236 | }
|
---|