[1289] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2009 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;
|
---|
[2474] | 30 | using HeuristicLab.Common;
|
---|
[1289] | 31 | using HeuristicLab.Core;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.SA {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// Visual representation of the <see cref="SA"/> class.
|
---|
| 36 | /// </summary>
|
---|
| 37 | public partial class SAEditor : EditorBase {
|
---|
| 38 | private ChooseOperatorDialog chooseOperatorDialog;
|
---|
| 39 |
|
---|
| 40 | /// <summary>
|
---|
| 41 | /// Gets or sets the <see cref="SA"/> item to represent visually.
|
---|
| 42 | /// </summary>
|
---|
| 43 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.
|
---|
| 44 | /// No own data storage present!</remarks>
|
---|
| 45 | public SA SA {
|
---|
| 46 | get { return (SA)Item; }
|
---|
| 47 | set { base.Item = value; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// Initializes a new instance of <see cref="SAEditor"/>.
|
---|
| 52 | /// </summary>
|
---|
| 53 | public SAEditor() {
|
---|
| 54 | InitializeComponent();
|
---|
| 55 | }
|
---|
| 56 | /// <summary>
|
---|
| 57 | /// Initializes a new instance of <see cref="SAEditor"/> with the given <paramref name="sga"/>.
|
---|
| 58 | /// </summary>
|
---|
| 59 | /// <param name="sa">The simulated annealing algorithm to represent visually.</param>
|
---|
| 60 | public SAEditor(SA sa)
|
---|
| 61 | : this() {
|
---|
| 62 | SA = sa;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /// <summary>
|
---|
| 66 | /// Removes the eventhandlers from the underlying <see cref="IEngine"/> of the <see cref="SA"/>.
|
---|
| 67 | /// </summary>
|
---|
| 68 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 69 | protected override void RemoveItemEvents() {
|
---|
[2474] | 70 | SA.Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1289] | 71 | SA.Engine.Finished -= new EventHandler(Engine_Finished);
|
---|
| 72 | scopeView.Scope = null;
|
---|
| 73 | base.RemoveItemEvents();
|
---|
| 74 | }
|
---|
| 75 | /// <summary>
|
---|
| 76 | /// Adds eventhandlers to the underlying <see cref="IEngine"/> of the <see cref="SA"/>.
|
---|
| 77 | /// </summary>
|
---|
| 78 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 79 | protected override void AddItemEvents() {
|
---|
| 80 | base.AddItemEvents();
|
---|
[2474] | 81 | SA.Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
|
---|
[1289] | 82 | SA.Engine.Finished += new EventHandler(Engine_Finished);
|
---|
| 83 | SetDataBinding();
|
---|
| 84 | scopeView.Scope = SA.Engine.GlobalScope;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | /// <summary>
|
---|
| 88 | /// Updates all controls with the latest data of the model.
|
---|
| 89 | /// </summary>
|
---|
| 90 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 91 | protected override void UpdateControls() {
|
---|
| 92 | base.UpdateControls();
|
---|
| 93 | if (SA == null) {
|
---|
| 94 | tabControl.Enabled = false;
|
---|
| 95 | } else {
|
---|
| 96 | tabControl.Enabled = true;
|
---|
| 97 | problemInitializationTextBox.Text = SA.ProblemInjector.GetType().Name;
|
---|
| 98 | solutionGenerationTextBox.Text = SA.SolutionGenerator.GetType().Name;
|
---|
| 99 | annealingSchemaTextBox.Text = SA.AnnealingScheme.GetType().Name;
|
---|
| 100 | mutationTextBox.Text = SA.Mutator.GetType().Name;
|
---|
| 101 | evaluationTextBox.Text = SA.Evaluator.GetType().Name;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | private void SetDataBinding() {
|
---|
| 106 | setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", SA, "SetSeedRandomly");
|
---|
| 107 | randomSeedTextBox.DataBindings.Add("Text", SA, "Seed");
|
---|
| 108 | maximumIterationsTextBox.DataBindings.Add("Text", SA, "MaximumIterations");
|
---|
| 109 | maximumIterationEffortTextBox.DataBindings.Add("Text", SA, "MaximumIterationEffort");
|
---|
| 110 | temperatureTextBox.DataBindings.Add("Text", SA, "Temperature");
|
---|
[1353] | 111 | minimumTemperatureTextBox.DataBindings.Add("Text", SA, "MinimumTemperature");
|
---|
[1289] | 112 | annealingParameterTextBox.DataBindings.Add("Text", SA, "AnnealingParameter");
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | #region Button Events
|
---|
| 116 | private void viewProblemInitializationButton_Click(object sender, EventArgs e) {
|
---|
| 117 | IView view = SA.ProblemInjector.CreateView();
|
---|
| 118 | if (view != null)
|
---|
[2591] | 119 | ControlManager.Manager.ShowControl(view);
|
---|
[1289] | 120 | }
|
---|
| 121 | private void viewSolutionGenerationButton_Click(object sender, EventArgs e) {
|
---|
| 122 | IView view = SA.SolutionGenerator.CreateView();
|
---|
| 123 | if (view != null)
|
---|
[2591] | 124 | ControlManager.Manager.ShowControl(view);
|
---|
[1289] | 125 | }
|
---|
| 126 | private void viewAnnealingSchemeButton_Click(object sender, EventArgs e) {
|
---|
| 127 | IView view = SA.AnnealingScheme.CreateView();
|
---|
| 128 | if (view != null)
|
---|
[2591] | 129 | ControlManager.Manager.ShowControl(view);
|
---|
[1289] | 130 | }
|
---|
| 131 | private void viewMutationButton_Click(object sender, EventArgs e) {
|
---|
| 132 | IView view = SA.Mutator.CreateView();
|
---|
| 133 | if (view != null)
|
---|
[2591] | 134 | ControlManager.Manager.ShowControl(view);
|
---|
[1289] | 135 | }
|
---|
| 136 | private void viewEvaluationButton_Click(object sender, EventArgs e) {
|
---|
| 137 | IView view = SA.Evaluator.CreateView();
|
---|
| 138 | if (view != null)
|
---|
[2591] | 139 | ControlManager.Manager.ShowControl(view);
|
---|
[1289] | 140 | }
|
---|
| 141 | private void setProblemInitializationButton_Click(object sender, EventArgs e) {
|
---|
| 142 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 143 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 144 | SA.ProblemInjector = chooseOperatorDialog.Operator;
|
---|
| 145 | problemInitializationTextBox.Text = SA.ProblemInjector.GetType().Name;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 | private void setSolutionGenerationButton_Click(object sender, EventArgs e) {
|
---|
| 149 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 150 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 151 | SA.SolutionGenerator= chooseOperatorDialog.Operator;
|
---|
| 152 | solutionGenerationTextBox.Text = SA.SolutionGenerator.GetType().Name;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | private void setAnnealingSchemeButton_Click(object sender, EventArgs e) {
|
---|
| 156 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 157 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 158 | SA.AnnealingScheme = chooseOperatorDialog.Operator;
|
---|
| 159 | annealingSchemaTextBox.Text = SA.AnnealingScheme.GetType().Name;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | private void setMutationButton_Click(object sender, EventArgs e) {
|
---|
| 163 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 164 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 165 | SA.Mutator = chooseOperatorDialog.Operator;
|
---|
| 166 | mutationTextBox.Text = SA.Mutator.GetType().Name;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | private void setEvaluationButton_Click(object sender, EventArgs e) {
|
---|
| 170 | if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
|
---|
| 171 | if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 172 | SA.Evaluator = chooseOperatorDialog.Operator;
|
---|
| 173 | evaluationTextBox.Text = SA.Evaluator.GetType().Name;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | private void executeButton_Click(object sender, EventArgs e) {
|
---|
| 177 | executeButton.Enabled = false;
|
---|
| 178 | abortButton.Enabled = true;
|
---|
| 179 | SA.Engine.Execute();
|
---|
| 180 | }
|
---|
| 181 | private void abortButton_Click(object sender, EventArgs e) {
|
---|
| 182 | SA.Engine.Abort();
|
---|
| 183 | }
|
---|
| 184 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
| 185 | SA.Engine.Reset();
|
---|
| 186 | }
|
---|
| 187 | private void cloneEngineButton_Click(object sender, EventArgs e) {
|
---|
| 188 | IEngine clone = (IEngine)SA.Engine.Clone();
|
---|
| 189 | IEditor editor = ((IEditable)clone).CreateEditor();
|
---|
[2591] | 190 | ControlManager.Manager.ShowControl(editor);
|
---|
[1289] | 191 | }
|
---|
| 192 | #endregion
|
---|
| 193 |
|
---|
| 194 | #region Engine Events
|
---|
[2474] | 195 | private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);
|
---|
| 196 | private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
[1289] | 197 | if (InvokeRequired)
|
---|
| 198 | Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
|
---|
| 199 | else
|
---|
[2474] | 200 | Auxiliary.ShowErrorMessageBox(e.Value);
|
---|
[1289] | 201 | }
|
---|
| 202 | private void Engine_Finished(object sender, EventArgs e) {
|
---|
| 203 | scopeView.Refresh();
|
---|
| 204 | executeButton.Enabled = true;
|
---|
| 205 | abortButton.Enabled = false;
|
---|
| 206 | }
|
---|
| 207 | #endregion
|
---|
| 208 | }
|
---|
| 209 | }
|
---|