Changeset 3262
- Timestamp:
- 04/04/10 05:22:47 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm.Views/3.3/GeneticAlgorithmView.Designer.cs
r3225 r3262 55 55 // createUserDefinedAlgorithmButton 56 56 // 57 this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point( 90, 552);57 this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(150, 552); 58 58 this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm"); 59 59 // … … 105 105 // 106 106 this.startButton.Location = new System.Drawing.Point(0, 552); 107 this.toolTip.SetToolTip(this.startButton, "Start/Resume Algorithm"); 107 108 // 108 // stopButton109 // pauseButton 109 110 // 110 this.stopButton.Location = new System.Drawing.Point(30, 552); 111 this.pauseButton.Location = new System.Drawing.Point(30, 552); 112 this.toolTip.SetToolTip(this.pauseButton, "Pause Algorithm"); 111 113 // 112 114 // resetButton 113 115 // 114 this.resetButton.Location = new System.Drawing.Point(60, 552); 116 this.resetButton.Location = new System.Drawing.Point(90, 552); 117 this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm"); 115 118 // 116 119 // executionTimeLabel … … 129 132 // 130 133 this.resultsView.Size = new System.Drawing.Size(724, 456); 134 // 135 // stopButton 136 // 137 this.stopButton.Location = new System.Drawing.Point(60, 552); 138 this.toolTip.SetToolTip(this.stopButton, "Stop Algorithm"); 131 139 // 132 140 // nameTextBox -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r3199 r3262 179 179 } 180 180 181 p rotected override void OnPrepared() {182 base. OnPrepared();181 public override void Prepare() { 182 base.Prepare(); 183 183 if (Engine != null) { 184 184 if (Problem == null) Engine.Prepare(null); -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r3201 r3262 154 154 } 155 155 156 p rotected override void OnPrepared() {157 base. OnPrepared();156 public override void Prepare() { 157 base.Prepare(); 158 158 if (Engine != null) { 159 159 if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null) -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3201 r3262 182 182 } 183 183 184 p rotected override void OnPrepared() {185 base. OnPrepared();184 public override void Prepare() { 185 base.Prepare(); 186 186 if (Engine != null) { 187 187 if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null) -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r3232 r3262 176 176 } 177 177 178 p rotected override void OnPrepared() {179 base. OnPrepared();178 public override void Prepare() { 179 base.Prepare(); 180 180 if (Engine != null) { 181 181 if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null -
trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs
r3261 r3262 32 32 [Content(typeof(IEngine), false)] 33 33 public partial class EngineView : ItemView { 34 private int executionTimeCounter;35 36 34 /// <summary> 37 35 /// Gets or sets the current engine. … … 59 57 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks> 60 58 protected override void DeregisterContentEvents() { 61 Content.Prepared -= new EventHandler(Content_Prepared); 62 Content.RunningChanged -= new EventHandler(Content_RunningChanged); 59 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); 63 60 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 64 61 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); … … 72 69 protected override void RegisterContentEvents() { 73 70 base.RegisterContentEvents(); 74 Content.Prepared += new EventHandler(Content_Prepared); 75 Content.RunningChanged += new EventHandler(Content_RunningChanged); 71 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); 76 72 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 77 73 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); … … 87 83 if (Content == null) { 88 84 logTextBox.Enabled = false; 85 executionTimeTextBox.Text = "-"; 89 86 executionTimeTextBox.Enabled = false; 90 87 } else { 91 88 logTextBox.Enabled = true; 92 UpdateExecutionTimeTextBox();89 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 93 90 executionTimeTextBox.Enabled = true; 94 91 } … … 96 93 97 94 #region Content Events 98 protected virtual void Content_ Prepared(object sender, EventArgs e) {95 protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) { 99 96 if (InvokeRequired) 100 Invoke(new EventHandler(Content_ Prepared), sender, e);97 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); 101 98 else { 102 executionTimeCounter = 0; 103 UpdateExecutionTimeTextBox(); 104 Log("Engine prepared"); 105 } 106 } 107 protected virtual void Content_RunningChanged(object sender, EventArgs e) { 108 if (InvokeRequired) 109 Invoke(new EventHandler(Content_RunningChanged), sender, e); 110 else { 111 UpdateExecutionTimeTextBox(); 112 if (Content.Running) Log("Engine started"); 113 else if (Content.Finished) Log("Engine finished"); 114 else Log("Engine stopped"); 99 if (Content.ExecutionState == ExecutionState.Prepared) Log("Engine prepared"); 100 else if (Content.ExecutionState == ExecutionState.Started) Log("Engine started"); 101 else if (Content.ExecutionState == ExecutionState.Paused) Log("Engine paused"); 102 else if (Content.ExecutionState == ExecutionState.Stopped) Log("Engine stopped"); 115 103 } 116 104 } 117 105 protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) { 118 executionTimeCounter++; 119 if ((executionTimeCounter >= 100) || !Content.Running) { 120 executionTimeCounter = 0; 121 UpdateExecutionTimeTextBox(); 122 } 106 if (InvokeRequired) 107 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e); 108 else 109 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 123 110 } 124 111 protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 131 118 132 119 #region Helpers 133 protected virtual void UpdateExecutionTimeTextBox() {134 if (InvokeRequired)135 Invoke(new Action(UpdateExecutionTimeTextBox));136 else137 executionTimeTextBox.Text = Content.ExecutionTime.ToString();138 }139 120 protected virtual void Log(string message) { 140 121 if (InvokeRequired) -
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r3261 r3262 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing;25 24 using System.Threading; 26 using HeuristicLab.Common;27 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 26 29 27 namespace HeuristicLab.Core { 30 /// <summary>31 /// Base class to represent an engine, which is an interpreter, holding the code, the data and32 /// the actual state, which is the runtime stack and a pointer onto the next operation. It represents33 /// one execution and can handle parallel executions.34 /// </summary>35 28 [Item("Engine", "A base class for engines.")] 36 29 [StorableClass] 37 public abstract class Engine : Item, IEngine { 38 public override Image ItemImage { 39 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event; } 40 } 41 42 [Storable] 43 private TimeSpan executionTime; 44 /// <summary> 45 /// Gets or sets the execution time. 46 /// </summary> 47 /// <remarks>Calls <see cref="OnExecutionTimeChanged"/> in the setter.</remarks> 48 public TimeSpan ExecutionTime { 49 get { return executionTime; } 50 protected set { 51 executionTime = value; 52 OnExecutionTimeChanged(); 53 } 54 } 55 56 /// <summary> 57 /// Field of the current instance that represent the execution stack. 58 /// </summary> 30 public abstract class Engine : Executable, IEngine { 59 31 [Storable] 60 32 private Stack<IOperation> executionStack; 61 /// <summary>62 /// Gets the current execution stack.63 /// </summary>64 33 protected Stack<IOperation> ExecutionStack { 65 34 get { return executionStack; } 66 35 } 67 36 68 /// <summary> 69 /// Flag of the current instance whether it is currently running. 70 /// </summary> 71 private bool running; 72 /// <summary> 73 /// Gets information whether the instance is currently running. 74 /// </summary> 75 public bool Running { 76 get { return running; } 77 private set { 78 if (running != value) { 79 running = value; 80 OnRunningChanged(); 81 } 82 } 37 private bool pausePending, stopPending; 38 private DateTime lastUpdateTime; 39 private System.Timers.Timer timer; 40 41 protected Engine() 42 : base() { 43 executionStack = new Stack<IOperation>(); 44 pausePending = stopPending = false; 45 timer = new System.Timers.Timer(100); 46 timer.AutoReset = true; 47 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 83 48 } 84 49 85 /// <summary>86 /// Flag of the current instance whether it is canceled.87 /// </summary>88 private bool canceled;89 /// <summary>90 /// Gets information whether the instance is currently canceled.91 /// </summary>92 protected bool Canceled {93 get { return canceled; }94 private set {95 if (canceled != value) {96 canceled = value;97 OnCanceledChanged();98 }99 }100 }101 /// <summary>102 /// Gets information whether the instance has already terminated.103 /// </summary>104 public bool Finished {105 get { return executionStack.Count == 0; }106 }107 108 /// <summary>109 /// Initializes a new instance of <see cref="EngineBase"/> with a new global scope.110 /// </summary>111 protected Engine() {112 executionStack = new Stack<IOperation>();113 }114 115 /// <summary>116 /// Clones the current instance (deep clone).117 /// </summary>118 /// <remarks>Deep clone through <see cref="cloner.Clone"/> method of helper class119 /// <see cref="Auxiliary"/>.</remarks>120 /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>121 /// <returns>The cloned object as <see cref="EngineBase"/>.</returns>122 50 public override IDeepCloneable Clone(Cloner cloner) { 123 51 Engine clone = (Engine)base.Clone(cloner); 124 clone.executionTime = executionTime;125 52 IOperation[] contexts = executionStack.ToArray(); 126 53 for (int i = contexts.Length - 1; i >= 0; i--) 127 54 clone.executionStack.Push((IOperation)cloner.Clone(contexts[i])); 128 clone. running = running;129 clone. canceled = canceled;55 clone.pausePending = pausePending; 56 clone.stopPending = stopPending; 130 57 return clone; 131 58 } 132 59 60 public sealed override void Prepare() { 61 base.Prepare(); 62 executionStack.Clear(); 63 OnPrepared(); 64 } 133 65 public void Prepare(IOperation initialOperation) { 134 ExecutionTime = new TimeSpan();66 base.Prepare(); 135 67 executionStack.Clear(); 136 68 if (initialOperation != null) … … 138 70 OnPrepared(); 139 71 } 140 /// <inheritdoc/> 141 /// <remarks>Calls <see cref="ThreadPool.QueueUserWorkItem(System.Threading.WaitCallback, object)"/> 142 /// of class <see cref="ThreadPool"/>.</remarks> 143 public void Start() { 72 public override void Start() { 73 base.Start(); 144 74 ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null); 145 75 } 146 /// <inheritdoc/> 147 /// <remarks>Calls <see cref="ThreadPool.QueueUserWorkItem(System.Threading.WaitCallback, object)"/> 148 /// of class <see cref="ThreadPool"/>.</remarks> 149 public void Step() { 150 ThreadPool.QueueUserWorkItem(new WaitCallback(RunStep), null); 76 public override void Pause() { 77 base.Pause(); 78 pausePending = true; 151 79 } 152 /// <inheritdoc/>153 /// <remarks>Sets the protected flag <c>myCanceled</c> to <c>true</c>.</remarks>154 public void Stop() {155 Canceled = true;80 public override void Stop() { 81 base.Stop(); 82 stopPending = true; 83 if (ExecutionState == ExecutionState.Paused) OnStopped(); 156 84 } 157 85 158 86 private void Run(object state) { 159 87 OnStarted(); 160 Running = true;161 Canceled = false; 162 DateTime start= DateTime.Now;163 DateTime end;164 while ( (!Canceled) && (!Finished)) {88 pausePending = stopPending = false; 89 90 lastUpdateTime = DateTime.Now; 91 timer.Start(); 92 while (!pausePending && !stopPending && (executionStack.Count > 0)) { 165 93 ProcessNextOperator(); 166 end = DateTime.Now;167 ExecutionTime += end - start;168 start = end;169 94 } 170 ExecutionTime += DateTime.Now - start; 171 Canceled = false; 172 Running = false; 173 OnStopped(); 174 } 175 private void RunStep(object state) { 176 OnStarted(); 177 Running = true; 178 Canceled = false; 179 DateTime start = DateTime.Now; 180 if ((!Canceled) && (!Finished)) 181 ProcessNextOperator(); 182 ExecutionTime += DateTime.Now - start; 183 Canceled = false; 184 Running = false; 185 OnStopped(); 95 timer.Stop(); 96 ExecutionTime += DateTime.Now - lastUpdateTime; 97 98 if (pausePending) OnPaused(); 99 else OnStopped(); 186 100 } 187 101 188 /// <summary>189 /// Performs the next operation.190 /// </summary>191 102 protected abstract void ProcessNextOperator(); 192 103 193 /// <summary> 194 /// Occurs when the execution time changed. 195 /// </summary> 196 public event EventHandler ExecutionTimeChanged; 197 /// <summary> 198 /// Fires a new <c>ExecutionTimeChanged</c> event. 199 /// </summary> 200 protected virtual void OnExecutionTimeChanged() { 201 if (ExecutionTimeChanged != null) 202 ExecutionTimeChanged(this, EventArgs.Empty); 104 protected override void OnPrepared() { 105 if (executionStack.Count > 0) base.OnPrepared(); 106 else base.OnStopped(); 203 107 } 204 /// <summary> 205 /// Occurs when the running flag changed. 206 /// </summary> 207 public event EventHandler RunningChanged; 208 /// <summary> 209 /// Fires a new <c>RunningChanged</c> event. 210 /// </summary> 211 protected virtual void OnRunningChanged() { 212 if (RunningChanged != null) 213 RunningChanged(this, EventArgs.Empty); 214 } 215 /// <summary> 216 /// Occurs when the execution is prepared for a new run. 217 /// </summary> 218 public event EventHandler Prepared; 219 /// <summary> 220 /// Fires a new <c>Prepared</c> event. 221 /// </summary> 222 protected virtual void OnPrepared() { 223 if (Prepared != null) 224 Prepared(this, EventArgs.Empty); 225 } 226 /// <summary> 227 /// Occurs when the execution is executed. 228 /// </summary> 229 public event EventHandler Started; 230 /// <summary> 231 /// Fires a new <c>Started</c> event. 232 /// </summary> 233 protected virtual void OnStarted() { 234 if (Started != null) 235 Started(this, EventArgs.Empty); 236 } 237 /// <summary> 238 /// Occurs when the execution is finished. 239 /// </summary> 240 public event EventHandler Stopped; 241 /// <summary> 242 /// Fires a new <c>Stopped</c> event. 243 /// </summary> 244 protected virtual void OnStopped() { 245 if (Stopped != null) 246 Stopped(this, EventArgs.Empty); 247 } 248 protected virtual void OnCanceledChanged() { } 249 /// <summary> 250 /// Occurs when an exception occured during the execution. 251 /// </summary> 252 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 253 /// <summary> 254 /// Aborts the execution and fires a new <c>ExceptionOccurred</c> event. 255 /// </summary> 256 /// <param name="exception">The exception that was thrown.</param> 257 protected virtual void OnExceptionOccurred(Exception exception) { 258 if (ExceptionOccurred != null) 259 ExceptionOccurred(this, new EventArgs<Exception>(exception)); 108 109 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 110 DateTime now = DateTime.Now; 111 ExecutionTime += now - lastUpdateTime; 112 lastUpdateTime = now; 260 113 } 261 114 } -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r2932 r3262 103 103 <Compile Include="Attributes\CreatableAttribute.cs" /> 104 104 <None Include="HeuristicLabCorePlugin.cs.frame" /> 105 <Compile Include="Executable.cs" /> 106 <Compile Include="ExecutionState.cs" /> 107 <Compile Include="Interfaces\IExecutable.cs" /> 105 108 <Compile Include="Interfaces\IParameterizedNamedItem.cs" /> 106 109 <Compile Include="Interfaces\IParameterizedItem.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs
r3226 r3262 24 24 25 25 namespace HeuristicLab.Core { 26 /// <summary> 27 /// Interface to represent one run. (An engine is an interpreter, holding the code, 28 /// the data and the actual state, which is the runtime stack and a pointer onto the next operation.). 29 /// It is responsible for operator execution and able to deal with parallelism. 30 /// </summary> 31 public interface IEngine : IItem { 32 /// <summary> 33 /// Gets the execution time of the current instance. 34 /// </summary> 35 TimeSpan ExecutionTime { get; } 36 37 /// <summary> 38 /// Gets information whether the engine is currently running. 39 /// </summary> 40 bool Running { get; } 41 /// <summary> 42 /// Gets information whether the engine has already terminated. 43 /// </summary> 44 bool Finished { get; } 45 46 /// <summary> 47 /// Prepares the engine with a given initial operation. 48 /// </summary> 26 public interface IEngine : IExecutable { 49 27 void Prepare(IOperation initialOperation); 50 /// <summary>51 /// Executes the whole run.52 /// </summary>53 void Start();54 /// <summary>55 /// Executes one step (one operation).56 /// </summary>57 void Step();58 /// <summary>59 /// Aborts the engine run.60 /// </summary>61 void Stop();62 63 /// <summary>64 /// Occurs when the execution time was changed.65 /// </summary>66 event EventHandler ExecutionTimeChanged;67 /// <summary>68 /// Occurs when the running flag was changed.69 /// </summary>70 event EventHandler RunningChanged;71 /// <summary>72 /// Occurs when the engine is prepared for a new run.73 /// </summary>74 event EventHandler Prepared;75 /// <summary>76 /// Occurs when the engine is executed.77 /// </summary>78 event EventHandler Started;79 /// <summary>80 /// Occurs when the engine is finished.81 /// </summary>82 event EventHandler Stopped;83 /// <summary>84 /// Occurs when an exception was thrown.85 /// </summary>86 event EventHandler<EventArgs<Exception>> ExceptionOccurred;87 28 } 88 29 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.Designer.cs
r3226 r3262 57 57 this.resultsView = new HeuristicLab.Optimization.Views.ResultCollectionView(); 58 58 this.startButton = new System.Windows.Forms.Button(); 59 this. stopButton = new System.Windows.Forms.Button();59 this.pauseButton = new System.Windows.Forms.Button(); 60 60 this.resetButton = new System.Windows.Forms.Button(); 61 61 this.executionTimeLabel = new System.Windows.Forms.Label(); … … 63 63 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 64 64 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 65 this.stopButton = new System.Windows.Forms.Button(); 65 66 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 66 67 this.tabControl.SuspendLayout(); … … 211 212 this.startButton.Click += new System.EventHandler(this.startButton_Click); 212 213 // 213 // stopButton214 // 215 this. stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));216 this. stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;217 this. stopButton.Location = new System.Drawing.Point(30, 458);218 this. stopButton.Name = "stopButton";219 this. stopButton.Size = new System.Drawing.Size(24, 24);220 this. stopButton.TabIndex = 6;221 this.toolTip.SetToolTip(this. stopButton, "Pause Algorithm");222 this. stopButton.UseVisualStyleBackColor = true;223 this. stopButton.Click += new System.EventHandler(this.stopButton_Click);214 // pauseButton 215 // 216 this.pauseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 217 this.pauseButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause; 218 this.pauseButton.Location = new System.Drawing.Point(30, 458); 219 this.pauseButton.Name = "pauseButton"; 220 this.pauseButton.Size = new System.Drawing.Size(24, 24); 221 this.pauseButton.TabIndex = 6; 222 this.toolTip.SetToolTip(this.pauseButton, "Pause Algorithm"); 223 this.pauseButton.UseVisualStyleBackColor = true; 224 this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click); 224 225 // 225 226 // resetButton … … 227 228 this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 228 229 this.resetButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Restart; 229 this.resetButton.Location = new System.Drawing.Point( 60, 458);230 this.resetButton.Location = new System.Drawing.Point(90, 458); 230 231 this.resetButton.Name = "resetButton"; 231 232 this.resetButton.Size = new System.Drawing.Size(24, 24); 232 this.resetButton.TabIndex = 7;233 this.resetButton.TabIndex = 8; 233 234 this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm"); 234 235 this.resetButton.UseVisualStyleBackColor = true; … … 242 243 this.executionTimeLabel.Name = "executionTimeLabel"; 243 244 this.executionTimeLabel.Size = new System.Drawing.Size(83, 13); 244 this.executionTimeLabel.TabIndex = 8;245 this.executionTimeLabel.TabIndex = 9; 245 246 this.executionTimeLabel.Text = "&Execution Time:"; 246 247 // … … 252 253 this.executionTimeTextBox.ReadOnly = true; 253 254 this.executionTimeTextBox.Size = new System.Drawing.Size(137, 20); 254 this.executionTimeTextBox.TabIndex = 9;255 this.executionTimeTextBox.TabIndex = 10; 255 256 // 256 257 // openFileDialog … … 269 270 this.saveFileDialog.Title = "Save Problem"; 270 271 // 272 // stopButton 273 // 274 this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 275 this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Stop; 276 this.stopButton.Location = new System.Drawing.Point(60, 458); 277 this.stopButton.Name = "stopButton"; 278 this.stopButton.Size = new System.Drawing.Size(24, 24); 279 this.stopButton.TabIndex = 7; 280 this.toolTip.SetToolTip(this.stopButton, "Stop Algorithm"); 281 this.stopButton.UseVisualStyleBackColor = true; 282 this.stopButton.Click += new System.EventHandler(this.stopButton_Click); 283 // 271 284 // AlgorithmView 272 285 // … … 275 288 this.Controls.Add(this.tabControl); 276 289 this.Controls.Add(this.startButton); 277 this.Controls.Add(this. stopButton);290 this.Controls.Add(this.pauseButton); 278 291 this.Controls.Add(this.executionTimeTextBox); 279 292 this.Controls.Add(this.executionTimeLabel); 293 this.Controls.Add(this.stopButton); 280 294 this.Controls.Add(this.resetButton); 281 295 this.Name = "AlgorithmView"; 282 296 this.Size = new System.Drawing.Size(679, 482); 283 297 this.Controls.SetChildIndex(this.resetButton, 0); 298 this.Controls.SetChildIndex(this.stopButton, 0); 284 299 this.Controls.SetChildIndex(this.executionTimeLabel, 0); 285 300 this.Controls.SetChildIndex(this.executionTimeTextBox, 0); 286 this.Controls.SetChildIndex(this. stopButton, 0);301 this.Controls.SetChildIndex(this.pauseButton, 0); 287 302 this.Controls.SetChildIndex(this.startButton, 0); 288 303 this.Controls.SetChildIndex(this.tabControl, 0); … … 312 327 protected System.Windows.Forms.Button openProblemButton; 313 328 protected System.Windows.Forms.Button startButton; 314 protected System.Windows.Forms.Button stopButton;329 protected System.Windows.Forms.Button pauseButton; 315 330 protected System.Windows.Forms.Button resetButton; 316 331 protected System.Windows.Forms.Label executionTimeLabel; … … 320 335 protected System.Windows.Forms.TabPage resultsTabPage; 321 336 protected HeuristicLab.Optimization.Views.ResultCollectionView resultsView; 337 protected System.Windows.Forms.Button stopButton; 322 338 323 339 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs
r3261 r3262 24 24 using System.Windows.Forms; 25 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Core.Views; 27 28 using HeuristicLab.MainForm; … … 37 38 public partial class AlgorithmView : NamedItemView { 38 39 private TypeSelectorDialog problemTypeSelectorDialog; 39 private int executionTimeCounter;40 40 41 41 public new IAlgorithm Content { … … 75 75 protected override void DeregisterContentEvents() { 76 76 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 77 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); 77 78 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 78 79 Content.Prepared -= new EventHandler(Content_Prepared); 79 80 Content.ProblemChanged -= new EventHandler(Content_ProblemChanged); 80 Content.RunningChanged -= new EventHandler(Content_RunningChanged);81 81 base.DeregisterContentEvents(); 82 82 } … … 84 84 base.RegisterContentEvents(); 85 85 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 86 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); 86 87 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 87 88 Content.Prepared += new EventHandler(Content_Prepared); 88 89 Content.ProblemChanged += new EventHandler(Content_ProblemChanged); 89 Content.RunningChanged += new EventHandler(Content_RunningChanged);90 90 } 91 91 92 92 protected override void OnContentChanged() { 93 93 base.OnContentChanged(); 94 stopButton.Enabled = false;95 94 if (Content == null) { 96 95 parameterCollectionView.Content = null; … … 98 97 resultsView.Content = null; 99 98 tabControl.Enabled = false; 100 startButton.Enabled = resetButton.Enabled = false;99 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false; 101 100 executionTimeTextBox.Text = "-"; 102 101 executionTimeTextBox.Enabled = false; … … 108 107 resultsView.Content = Content.Results.AsReadOnly(); 109 108 tabControl.Enabled = true; 110 startButton.Enabled = !Content.Finished; 111 resetButton.Enabled = true; 112 UpdateExecutionTimeTextBox(); 109 EnableDisableButtons(); 110 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 113 111 executionTimeTextBox.Enabled = true; 114 112 } … … 116 114 117 115 protected override void OnClosed(FormClosedEventArgs e) { 118 if ( Content != null) Content.Stop();116 if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop(); 119 117 base.OnClosed(e); 120 118 } 121 119 122 120 #region Content Events 123 protected virtual void Content_Prepared(object sender, EventArgs e) {124 if (InvokeRequired)125 Invoke(new EventHandler(Content_Prepared), sender, e);126 else {127 executionTimeCounter = 0;128 resultsView.Content = Content.Results.AsReadOnly();129 startButton.Enabled = !Content.Finished;130 UpdateExecutionTimeTextBox();131 }132 }133 121 protected virtual void Content_ProblemChanged(object sender, EventArgs e) { 134 122 if (InvokeRequired) … … 140 128 } 141 129 } 142 protected virtual void Content_RunningChanged(object sender, EventArgs e) { 143 if (InvokeRequired) 144 Invoke(new EventHandler(Content_RunningChanged), sender, e); 130 protected virtual void Content_Prepared(object sender, EventArgs e) { 131 if (InvokeRequired) 132 Invoke(new EventHandler(Content_Prepared), sender, e); 133 else 134 resultsView.Content = Content.Results.AsReadOnly(); 135 } 136 protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) { 137 if (InvokeRequired) 138 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); 145 139 else { 146 SaveEnabled = !Content.Running; 147 parameterCollectionView.Enabled = !Content.Running; 148 newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = !Content.Running; 149 problemViewHost.Enabled = !Content.Running; 150 resultsView.Enabled = !Content.Running; 151 startButton.Enabled = !Content.Running && !Content.Finished; 152 stopButton.Enabled = Content.Running; 153 resetButton.Enabled = !Content.Running; 154 UpdateExecutionTimeTextBox(); 140 SaveEnabled = Content.ExecutionState != ExecutionState.Started; 141 parameterCollectionView.Enabled = Content.ExecutionState != ExecutionState.Started; 142 newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = Content.ExecutionState != ExecutionState.Started; 143 problemViewHost.Enabled = Content.ExecutionState != ExecutionState.Started; 144 resultsView.Enabled = Content.ExecutionState != ExecutionState.Started; 145 EnableDisableButtons(); 155 146 } 156 147 } 157 148 protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) { 158 executionTimeCounter++; 159 if ((executionTimeCounter >= 100) || !Content.Running) { 160 executionTimeCounter = 0; 161 UpdateExecutionTimeTextBox(); 162 } 149 if (InvokeRequired) 150 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e); 151 else 152 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 163 153 } 164 154 protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 238 228 Content.Start(); 239 229 } 230 protected virtual void pauseButton_Click(object sender, EventArgs e) { 231 Content.Pause(); 232 } 240 233 protected virtual void stopButton_Click(object sender, EventArgs e) { 241 234 Content.Stop(); … … 247 240 248 241 #region Helpers 249 pr otected virtual void UpdateExecutionTimeTextBox() {250 if (InvokeRequired)251 Invoke(new Action(UpdateExecutionTimeTextBox));252 else253 executionTimeTextBox.Text = Content.ExecutionTime.ToString();242 private void EnableDisableButtons() { 243 startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused); 244 pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started; 245 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused); 246 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started; 254 247 } 255 248 #endregion -
trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.Designer.cs
r3225 r3262 98 98 // 99 99 this.startButton.Location = new System.Drawing.Point(0, 525); 100 this.toolTip.SetToolTip(this.startButton, "Start/Resume Algorithm"); 101 // 102 // pauseButton 103 // 104 this.pauseButton.Location = new System.Drawing.Point(30, 525); 105 this.toolTip.SetToolTip(this.pauseButton, "Pause Algorithm"); 106 // 107 // resetButton 108 // 109 this.resetButton.Location = new System.Drawing.Point(90, 525); 110 this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm"); 111 // 112 // executionTimeLabel 113 // 114 this.executionTimeLabel.Location = new System.Drawing.Point(487, 532); 115 this.executionTimeLabel.TabIndex = 10; 116 // 117 // executionTimeTextBox 118 // 119 this.executionTimeTextBox.Location = new System.Drawing.Point(576, 529); 120 this.executionTimeTextBox.TabIndex = 11; 121 // 122 // resultsTabPage 123 // 124 this.resultsTabPage.Size = new System.Drawing.Size(705, 441); 125 // 126 // resultsView 127 // 128 this.resultsView.Size = new System.Drawing.Size(693, 429); 100 129 // 101 130 // stopButton 102 131 // 103 this.stopButton.Location = new System.Drawing.Point(30, 525); 104 // 105 // resetButton 106 // 107 this.resetButton.Location = new System.Drawing.Point(60, 525); 108 // 109 // executionTimeLabel 110 // 111 this.executionTimeLabel.Location = new System.Drawing.Point(487, 532); 112 this.executionTimeLabel.TabIndex = 9; 113 // 114 // executionTimeTextBox 115 // 116 this.executionTimeTextBox.Location = new System.Drawing.Point(576, 529); 117 this.executionTimeTextBox.TabIndex = 10; 118 // 119 // resultsTabPage 120 // 121 this.resultsTabPage.Size = new System.Drawing.Size(705, 441); 122 // 123 // resultsView 124 // 125 this.resultsView.Size = new System.Drawing.Size(693, 429); 132 this.stopButton.Location = new System.Drawing.Point(60, 525); 133 this.toolTip.SetToolTip(this.stopButton, "Stop Algorithm"); 126 134 // 127 135 // nameTextBox … … 147 155 // 148 156 this.createUserDefinedAlgorithmButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 149 this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point( 90, 525);157 this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(150, 525); 150 158 this.createUserDefinedAlgorithmButton.Name = "createUserDefinedAlgorithmButton"; 151 159 this.createUserDefinedAlgorithmButton.Size = new System.Drawing.Size(254, 24); 152 this.createUserDefinedAlgorithmButton.TabIndex = 8;160 this.createUserDefinedAlgorithmButton.TabIndex = 9; 153 161 this.createUserDefinedAlgorithmButton.Text = "&Create User Defined Algorithm"; 154 162 this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm"); … … 164 172 this.engineComboBox.Location = new System.Drawing.Point(55, 6); 165 173 this.engineComboBox.Name = "engineComboBox"; 166 this.engineComboBox.Size = new System.Drawing.Size(6 44, 21);174 this.engineComboBox.Size = new System.Drawing.Size(610, 21); 167 175 this.engineComboBox.TabIndex = 1; 168 176 this.engineComboBox.SelectedIndexChanged += new System.EventHandler(this.engineComboBox_SelectedIndexChanged); … … 189 197 this.engineViewHost.Location = new System.Drawing.Point(6, 33); 190 198 this.engineViewHost.Name = "engineViewHost"; 191 this.engineViewHost.Size = new System.Drawing.Size(6 93, 402);199 this.engineViewHost.Size = new System.Drawing.Size(659, 335); 192 200 this.engineViewHost.TabIndex = 2; 193 201 this.engineViewHost.ViewType = null; … … 200 208 this.Name = "EngineAlgorithmView"; 201 209 this.Size = new System.Drawing.Size(713, 549); 210 this.Controls.SetChildIndex(this.stopButton, 0); 202 211 this.Controls.SetChildIndex(this.createUserDefinedAlgorithmButton, 0); 203 212 this.Controls.SetChildIndex(this.resetButton, 0); 213 this.Controls.SetChildIndex(this.pauseButton, 0); 204 214 this.Controls.SetChildIndex(this.executionTimeLabel, 0); 205 215 this.Controls.SetChildIndex(this.executionTimeTextBox, 0); 206 this.Controls.SetChildIndex(this.stopButton, 0);207 216 this.Controls.SetChildIndex(this.startButton, 0); 208 217 this.Controls.SetChildIndex(this.tabControl, 0); -
trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.cs
r3261 r3262 98 98 } 99 99 100 protected override void Content_ RunningChanged(object sender, EventArgs e) {100 protected override void Content_ExecutionStateChanged(object sender, EventArgs e) { 101 101 if (InvokeRequired) 102 Invoke(new EventHandler(Content_ RunningChanged), sender, e);102 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); 103 103 else { 104 createUserDefinedAlgorithmButton.Enabled = !Content.Running;105 engineComboBox.Enabled = !Content.Running;106 engineViewHost.Enabled = !Content.Running;107 base.Content_ RunningChanged(sender, e);104 createUserDefinedAlgorithmButton.Enabled = Content.ExecutionState != ExecutionState.Started; 105 engineComboBox.Enabled = Content.ExecutionState != ExecutionState.Started; 106 engineViewHost.Enabled = Content.ExecutionState != ExecutionState.Started; 107 base.Content_ExecutionStateChanged(sender, e); 108 108 } 109 109 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj
r3260 r3262 92 92 <DependentUpon>AlgorithmView.cs</DependentUpon> 93 93 </Compile> 94 <Compile Include="BatchRunView.cs">95 <SubType>UserControl</SubType>96 </Compile>97 <Compile Include="BatchRunView.Designer.cs">98 <DependentUpon>BatchRunView.cs</DependentUpon>99 </Compile>100 94 <Compile Include="RunCollectionView.cs"> 101 95 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.Designer.cs
r3225 r3262 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserDefinedAlgorithmView));48 47 this.operatorGraphTabPage = new System.Windows.Forms.TabPage(); 49 48 this.saveOperatorGraphButton = new System.Windows.Forms.Button(); … … 66 65 // 67 66 this.createUserDefinedAlgorithmButton.Enabled = false; 67 this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(150, 525); 68 this.createUserDefinedAlgorithmButton.TabIndex = 9; 68 69 this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm"); 69 70 this.createUserDefinedAlgorithmButton.Visible = false; … … 91 92 // 92 93 this.toolTip.SetToolTip(this.openProblemButton, "Open Problem"); 94 // 95 // startButton 96 // 97 this.toolTip.SetToolTip(this.startButton, "Start/Resume Algorithm"); 98 // 99 // pauseButton 100 // 101 this.toolTip.SetToolTip(this.pauseButton, "Pause Algorithm"); 102 // 103 // resetButton 104 // 105 this.resetButton.Location = new System.Drawing.Point(90, 525); 106 this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm"); 107 // 108 // executionTimeLabel 109 // 110 this.executionTimeLabel.TabIndex = 10; 111 // 112 // executionTimeTextBox 113 // 114 this.executionTimeTextBox.TabIndex = 11; 115 // 116 // stopButton 117 // 118 this.stopButton.Location = new System.Drawing.Point(60, 525); 119 this.toolTip.SetToolTip(this.stopButton, "Stop Algorithm"); 93 120 // 94 121 // nameTextBox -
trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs
r3261 r3262 75 75 } 76 76 77 protected override void Content_ RunningChanged(object sender, EventArgs e) {77 protected override void Content_ExecutionStateChanged(object sender, EventArgs e) { 78 78 if (InvokeRequired) 79 Invoke(new EventHandler(Content_ RunningChanged), sender, e);79 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); 80 80 else { 81 newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = !Content.Running;82 operatorGraphViewHost.Enabled = !Content.Running;83 globalScopeView.Enabled = !Content.Running;84 base.Content_ RunningChanged(sender, e);81 newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = Content.ExecutionState != ExecutionState.Started; 82 operatorGraphViewHost.Enabled = Content.ExecutionState != ExecutionState.Started; 83 globalScopeView.Enabled = Content.ExecutionState != ExecutionState.Started; 84 base.Content_ExecutionStateChanged(sender, e); 85 85 } 86 86 } -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3261 r3262 36 36 public override Image ItemImage { 37 37 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event; } 38 } 39 40 [Storable] 41 private ExecutionState executionState; 42 public ExecutionState ExecutionState { 43 get { return executionState; } 44 private set { 45 if (executionState != value) { 46 executionState = value; 47 OnExecutionStateChanged(); 48 } 49 } 50 } 51 52 [Storable] 53 private TimeSpan executionTime; 54 public TimeSpan ExecutionTime { 55 get { return executionTime; } 56 protected set { 57 executionTime = value; 58 OnExecutionTimeChanged(); 59 } 38 60 } 39 61 … … 68 90 public abstract ResultCollection Results { get; } 69 91 70 public abstract TimeSpan ExecutionTime { get; } 71 72 private bool running; 73 public bool Running { 74 get { return running; } 75 protected set { 76 if (running != value) { 77 running = value; 78 OnRunningChanged(); 79 } 80 } 81 } 82 83 public abstract bool Finished { get; } 84 85 private bool canceled; 86 protected bool Canceled { 87 get { return canceled; } 88 private set { 89 if (canceled != value) { 90 canceled = value; 91 OnCanceledChanged(); 92 } 93 } 94 } 95 96 protected Algorithm() : base() { } 97 protected Algorithm(string name) : base(name) { } 98 protected Algorithm(string name, ParameterCollection parameters) : base(name, parameters) { } 99 protected Algorithm(string name, string description) : base(name, description) { } 100 protected Algorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { } 92 protected Algorithm() 93 : base() { 94 executionState = ExecutionState.Stopped; 95 executionTime = TimeSpan.Zero; 96 } 97 protected Algorithm(string name) 98 : base(name) { 99 executionState = ExecutionState.Stopped; 100 executionTime = TimeSpan.Zero; 101 } 102 protected Algorithm(string name, ParameterCollection parameters) 103 : base(name, parameters) { 104 executionState = ExecutionState.Stopped; 105 executionTime = TimeSpan.Zero; 106 } 107 protected Algorithm(string name, string description) 108 : base(name, description) { 109 executionState = ExecutionState.Stopped; 110 executionTime = TimeSpan.Zero; 111 } 112 protected Algorithm(string name, string description, ParameterCollection parameters) 113 : base(name, description, parameters) { 114 executionState = ExecutionState.Stopped; 115 executionTime = TimeSpan.Zero; 116 } 101 117 102 118 public override IDeepCloneable Clone(Cloner cloner) { 103 119 Algorithm clone = (Algorithm)base.Clone(cloner); 120 clone.executionState = executionState; 121 clone.executionTime = executionTime; 104 122 clone.Problem = (IProblem)cloner.Clone(problem); 105 clone.running = running;106 clone.canceled = canceled;107 123 return clone; 108 124 } 109 125 110 public void Prepare() { 111 OnPrepared(); 112 } 113 public void Start() { 114 OnStarted(); 115 Running = true; 116 Canceled = false; 117 } 118 public void Stop() { 119 Canceled = true; 126 public virtual void Prepare() { 127 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 128 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 129 ExecutionTime = TimeSpan.Zero; 130 } 131 public virtual void Start() { 132 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 133 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 134 } 135 public virtual void Pause() { 136 if (ExecutionState != ExecutionState.Started) 137 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 138 } 139 public virtual void Stop() { 140 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 141 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 120 142 } 121 143 … … 130 152 131 153 #region Events 154 public event EventHandler ExecutionStateChanged; 155 protected virtual void OnExecutionStateChanged() { 156 EventHandler handler = ExecutionStateChanged; 157 if (handler != null) handler(this, EventArgs.Empty); 158 } 159 public event EventHandler ExecutionTimeChanged; 160 protected virtual void OnExecutionTimeChanged() { 161 EventHandler handler = ExecutionTimeChanged; 162 if (handler != null) handler(this, EventArgs.Empty); 163 } 132 164 public event EventHandler ProblemChanged; 133 165 protected virtual void OnProblemChanged() { 134 if (ProblemChanged != null) 135 ProblemChanged(this, EventArgs.Empty); 136 } 137 public event EventHandler ExecutionTimeChanged; 138 protected virtual void OnExecutionTimeChanged() { 139 if (ExecutionTimeChanged != null) 140 ExecutionTimeChanged(this, EventArgs.Empty); 141 } 142 public event EventHandler RunningChanged; 143 protected virtual void OnRunningChanged() { 144 if (RunningChanged != null) 145 RunningChanged(this, EventArgs.Empty); 166 EventHandler handler = ProblemChanged; 167 if (handler != null) handler(this, EventArgs.Empty); 146 168 } 147 169 public event EventHandler Prepared; 148 170 protected virtual void OnPrepared() { 149 if (Prepared != null) 150 Prepared(this, EventArgs.Empty); 171 ExecutionState = ExecutionState.Prepared; 172 EventHandler handler = Prepared; 173 if (handler != null) handler(this, EventArgs.Empty); 151 174 } 152 175 public event EventHandler Started; 153 176 protected virtual void OnStarted() { 154 if (Started != null) 155 Started(this, EventArgs.Empty); 177 ExecutionState = ExecutionState.Started; 178 EventHandler handler = Started; 179 if (handler != null) handler(this, EventArgs.Empty); 180 } 181 public event EventHandler Paused; 182 protected virtual void OnPaused() { 183 ExecutionState = ExecutionState.Paused; 184 EventHandler handler = Paused; 185 if (handler != null) handler(this, EventArgs.Empty); 156 186 } 157 187 public event EventHandler Stopped; 158 188 protected virtual void OnStopped() { 159 Canceled = false; 160 Running = false; 161 if (Stopped != null) 162 Stopped(this, EventArgs.Empty); 163 } 164 protected virtual void OnCanceledChanged() { } 189 ExecutionState = ExecutionState.Stopped; 190 EventHandler handler = Stopped; 191 if (handler != null) handler(this, EventArgs.Empty); 192 } 165 193 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 166 194 protected virtual void OnExceptionOccurred(Exception exception) { 167 if (ExceptionOccurred != null)168 ExceptionOccurred(this, new EventArgs<Exception>(exception));195 EventHandler<EventArgs<Exception>> handler = ExceptionOccurred; 196 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 169 197 } 170 198 -
trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs
r3261 r3262 94 94 } 95 95 96 public override TimeSpan ExecutionTime {97 get {98 if (engine == null) return TimeSpan.Zero;99 else return engine.ExecutionTime;100 }101 }102 103 public override bool Finished {104 get {105 if (engine == null) return true;106 else return engine.Finished;107 }108 }109 110 96 protected EngineAlgorithm() 111 97 : base() { … … 172 158 } 173 159 174 protected override void OnCanceledChanged() { 175 if (Canceled && (engine != null)) 176 engine.Stop(); 177 } 178 protected override void OnPrepared() { 160 public override void Prepare() { 161 base.Prepare(); 179 162 globalScope.Clear(); 180 163 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); … … 195 178 engine.Prepare(context); 196 179 } 197 base.OnPrepared();198 }199 protected override void OnStarted() {180 } 181 public override void Start() { 182 base.Start(); 200 183 if (engine != null) engine.Start(); 201 base.OnStarted(); 202 } 203 204 protected virtual void OnOperatorGraphChanged() { } 205 184 } 185 public override void Pause() { 186 base.Pause(); 187 if (engine != null) engine.Pause(); 188 } 189 public override void Stop() { 190 base.Stop(); 191 if (engine != null) engine.Stop(); 192 } 193 194 #region Events 206 195 public event EventHandler EngineChanged; 207 196 protected virtual void OnEngineChanged() { … … 209 198 EngineChanged(this, EventArgs.Empty); 210 199 } 211 212 private void OperatorGraph_InitialOperatorChanged(object sender, EventArgs e) { 213 Prepare(); 214 } 200 protected virtual void OnOperatorGraphChanged() { } 201 215 202 private void RegisterEngineEvents() { 216 203 Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 217 204 Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged); 205 Engine.Paused += new EventHandler(Engine_Paused); 206 Engine.Prepared += new EventHandler(Engine_Prepared); 207 Engine.Started += new EventHandler(Engine_Started); 218 208 Engine.Stopped += new EventHandler(Engine_Stopped); 219 209 } 220 221 210 private void DeregisterEngineEvents() { 222 211 Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 223 212 Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged); 213 Engine.Paused -= new EventHandler(Engine_Paused); 214 Engine.Prepared -= new EventHandler(Engine_Prepared); 215 Engine.Started -= new EventHandler(Engine_Started); 224 216 Engine.Stopped -= new EventHandler(Engine_Stopped); 225 217 } 226 227 218 private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) { 228 219 OnExceptionOccurred(e.Value); 229 220 } 230 221 private void Engine_ExecutionTimeChanged(object sender, EventArgs e) { 231 OnExecutionTimeChanged(); 222 ExecutionTime = Engine.ExecutionTime; 223 } 224 private void Engine_Paused(object sender, EventArgs e) { 225 OnPaused(); 226 } 227 private void Engine_Prepared(object sender, EventArgs e) { 228 OnPrepared(); 229 } 230 private void Engine_Started(object sender, EventArgs e) { 231 OnStarted(); 232 232 } 233 233 private void Engine_Stopped(object sender, EventArgs e) { 234 234 OnStopped(); 235 235 } 236 237 private void OperatorGraph_InitialOperatorChanged(object sender, EventArgs e) { 238 Prepare(); 239 } 240 #endregion 236 241 } 237 242 } -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3260 r3262 86 86 <None Include="HeuristicLabOptimizationPlugin.cs.frame" /> 87 87 <Compile Include="Algorithm.cs" /> 88 <Compile Include="BatchRun.cs" />89 88 <Compile Include="RunCollection.cs" /> 90 89 <Compile Include="Run.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IAlgorithm.cs
r3260 r3262 29 29 /// Interface to represent an algorithm. 30 30 /// </summary> 31 public interface IAlgorithm : IParameterizedNamedItem {31 public interface IAlgorithm : IParameterizedNamedItem, IExecutable { 32 32 Type ProblemType { get; } 33 33 IProblem Problem { get; set; } 34 34 ResultCollection Results { get; } 35 TimeSpan ExecutionTime { get; }36 bool Running { get; }37 bool Finished { get; }38 39 void Prepare();40 void Start();41 void Stop();42 35 43 36 void CollectResultValues(IDictionary<string, IItem> values); 44 37 45 38 event EventHandler ProblemChanged; 46 event EventHandler ExecutionTimeChanged;47 event EventHandler RunningChanged;48 event EventHandler Prepared;49 event EventHandler Started;50 event EventHandler Stopped;51 event EventHandler<EventArgs<Exception>> ExceptionOccurred;52 39 } 53 40 } -
trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs
r3017 r3262 55 55 public event EventHandler OperatorGraphChanged; 56 56 protected override void OnOperatorGraphChanged() { 57 if (OperatorGraphChanged != null)58 OperatorGraphChanged(this, EventArgs.Empty);57 EventHandler handler = OperatorGraphChanged; 58 if (handler != null) handler(this, EventArgs.Empty); 59 59 } 60 60 } -
trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs
r3226 r3262 56 56 currentOperator = operation.Operator; 57 57 ExecutionStack.Push(operation.Operator.Execute((IExecutionContext)operation)); 58 currentOperator = null;59 58 } 60 59 catch (Exception ex) { 61 60 ExecutionStack.Push(operation); 62 61 OnExceptionOccurred(ex); 63 Stop();62 Pause(); 64 63 } 65 64 if (operation.Operator.Breakpoint) 66 Stop();65 Pause(); 67 66 } 68 67 } 69 68 70 protected override void OnCanceledChanged() { 71 if (Canceled && (currentOperator != null)) 72 currentOperator.Abort(); 69 public override void Pause() { 70 base.Pause(); 71 if (currentOperator != null) currentOperator.Abort(); 72 } 73 public override void Stop() { 74 base.Stop(); 75 if (currentOperator != null) currentOperator.Abort(); 73 76 } 74 77 }
Note: See TracChangeset
for help on using the changeset viewer.