Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.SA/3.2/SAEditor.cs @ 3005

Last change on this file since 3005 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

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