Index: /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs	(revision 3265)
@@ -180,8 +180,5 @@
 
     public override void Prepare() {
-      base.Prepare();
-      if (Engine != null) {
-        if (Problem == null) Engine.Prepare(null);
-      }
+      if (Problem != null) base.Prepare();
     }
 
Index: /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.Tests.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.Tests.csproj	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.Tests.csproj	(revision 3265)
@@ -156,5 +156,5 @@
   </ItemGroup>
   <ItemGroup>
-    <None Include="GeneticAlgorithm.hl">
+    <None Include="GA_TSP.hl">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
Index: /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs	(revision 3265)
@@ -80,8 +80,8 @@
 
     [TestMethod]
-    [DeploymentItem(@"GeneticAlgorithm.hl")]
+    [DeploymentItem(@"GA_TSP.hl")]
     public void GeneticAlgorithmPerformanceTest() {
       ex = null;
-      IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GeneticAlgorithm.hl");
+      IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GA_TSP.hl");
       ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
       ga.Stopped += new EventHandler(ga_Stopped);
Index: /trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs	(revision 3265)
@@ -155,9 +155,6 @@
 
     public override void Prepare() {
-      base.Prepare();
-      if (Engine != null) {
-        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
-          Engine.Prepare(null);
-      }
+      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
+        base.Prepare();
     }
 
Index: /trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs	(revision 3265)
@@ -183,9 +183,6 @@
 
     public override void Prepare() {
-      base.Prepare();
-      if (Engine != null) {
-        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
-          Engine.Prepare(null);
-      }
+      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
+        base.Prepare();
     }
 
Index: /trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs	(revision 3265)
@@ -177,10 +177,7 @@
 
     public override void Prepare() {
-      base.Prepare();
-      if (Engine != null) {
-        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null
-          || TabuMoveEvaluator == null || TabuMoveMaker == null)
-          Engine.Prepare(null);
-      }
+      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
+          TabuMoveEvaluator != null && TabuMoveMaker != null)
+        base.Prepare();
     }
 
Index: /trunk/sources/HeuristicLab.Core/3.3/Engine.cs
===================================================================
--- /trunk/sources/HeuristicLab.Core/3.3/Engine.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Core/3.3/Engine.cs	(revision 3265)
@@ -102,9 +102,4 @@
     protected abstract void ProcessNextOperator();
 
-    protected override void OnPrepared() {
-      if (executionStack.Count > 0) base.OnPrepared();
-      else base.OnStopped();
-    }
-
     private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
       DateTime now = DateTime.Now;
Index: /trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs	(revision 3265)
@@ -138,4 +138,6 @@
         Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
       else {
+        nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
+        descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
         SaveEnabled = Content.ExecutionState != ExecutionState.Started;
         parameterCollectionView.Enabled = Content.ExecutionState != ExecutionState.Started;
Index: /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs	(revision 3265)
@@ -53,4 +53,5 @@
       this.algorithmViewHost = new HeuristicLab.Core.Views.ViewHost();
       this.runsTabPage = new System.Windows.Forms.TabPage();
+      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
       this.startButton = new System.Windows.Forms.Button();
       this.stopButton = new System.Windows.Forms.Button();
@@ -62,5 +63,5 @@
       this.repetitionsLabel = new System.Windows.Forms.Label();
       this.repetitionsNumericUpDown = new System.Windows.Forms.NumericUpDown();
-      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
+      this.pauseButton = new System.Windows.Forms.Button();
       ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
       this.tabControl.SuspendLayout();
@@ -163,4 +164,16 @@
       this.runsTabPage.UseVisualStyleBackColor = true;
       // 
+      // runsView
+      // 
+      this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+                  | System.Windows.Forms.AnchorStyles.Left)
+                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.runsView.Caption = "RunCollection";
+      this.runsView.Content = null;
+      this.runsView.Location = new System.Drawing.Point(6, 6);
+      this.runsView.Name = "runsView";
+      this.runsView.Size = new System.Drawing.Size(659, 336);
+      this.runsView.TabIndex = 0;
+      // 
       // startButton
       // 
@@ -178,10 +191,10 @@
       // 
       this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-      this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;
-      this.stopButton.Location = new System.Drawing.Point(30, 458);
+      this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Stop;
+      this.stopButton.Location = new System.Drawing.Point(60, 458);
       this.stopButton.Name = "stopButton";
       this.stopButton.Size = new System.Drawing.Size(24, 24);
-      this.stopButton.TabIndex = 8;
-      this.toolTip.SetToolTip(this.stopButton, "Pause Batch Run");
+      this.stopButton.TabIndex = 9;
+      this.toolTip.SetToolTip(this.stopButton, "Stop Batch Run");
       this.stopButton.UseVisualStyleBackColor = true;
       this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
@@ -191,8 +204,8 @@
       this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
       this.resetButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Restart;
-      this.resetButton.Location = new System.Drawing.Point(60, 458);
+      this.resetButton.Location = new System.Drawing.Point(90, 458);
       this.resetButton.Name = "resetButton";
       this.resetButton.Size = new System.Drawing.Size(24, 24);
-      this.resetButton.TabIndex = 9;
+      this.resetButton.TabIndex = 10;
       this.toolTip.SetToolTip(this.resetButton, "Reset Batch Run");
       this.resetButton.UseVisualStyleBackColor = true;
@@ -206,5 +219,5 @@
       this.executionTimeLabel.Name = "executionTimeLabel";
       this.executionTimeLabel.Size = new System.Drawing.Size(83, 13);
-      this.executionTimeLabel.TabIndex = 10;
+      this.executionTimeLabel.TabIndex = 11;
       this.executionTimeLabel.Text = "&Execution Time:";
       // 
@@ -216,5 +229,5 @@
       this.executionTimeTextBox.ReadOnly = true;
       this.executionTimeTextBox.Size = new System.Drawing.Size(137, 20);
-      this.executionTimeTextBox.TabIndex = 11;
+      this.executionTimeTextBox.TabIndex = 12;
       // 
       // openFileDialog
@@ -266,17 +279,18 @@
             0,
             0});
+      this.repetitionsNumericUpDown.Validated += new System.EventHandler(repetitionsNumericUpDown_Validated);
       this.repetitionsNumericUpDown.ValueChanged += new System.EventHandler(this.repetitionsNumericUpDown_ValueChanged);
       // 
-      // runsView
-      // 
-      this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
-      this.runsView.Caption = "RunCollection";
-      this.runsView.Content = null;
-      this.runsView.Location = new System.Drawing.Point(6, 6);
-      this.runsView.Name = "runsView";
-      this.runsView.Size = new System.Drawing.Size(659, 336);
-      this.runsView.TabIndex = 0;
+      // pauseButton
+      // 
+      this.pauseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+      this.pauseButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;
+      this.pauseButton.Location = new System.Drawing.Point(30, 458);
+      this.pauseButton.Name = "pauseButton";
+      this.pauseButton.Size = new System.Drawing.Size(24, 24);
+      this.pauseButton.TabIndex = 8;
+      this.toolTip.SetToolTip(this.pauseButton, "Pause Batch Run");
+      this.pauseButton.UseVisualStyleBackColor = true;
+      this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click);
       // 
       // BatchRunView
@@ -286,18 +300,20 @@
       this.Controls.Add(this.tabControl);
       this.Controls.Add(this.startButton);
-      this.Controls.Add(this.stopButton);
       this.Controls.Add(this.executionTimeTextBox);
       this.Controls.Add(this.executionTimeLabel);
-      this.Controls.Add(this.resetButton);
       this.Controls.Add(this.repetitionsNumericUpDown);
       this.Controls.Add(this.repetitionsLabel);
+      this.Controls.Add(this.pauseButton);
+      this.Controls.Add(this.stopButton);
+      this.Controls.Add(this.resetButton);
       this.Name = "BatchRunView";
       this.Size = new System.Drawing.Size(679, 482);
+      this.Controls.SetChildIndex(this.resetButton, 0);
+      this.Controls.SetChildIndex(this.stopButton, 0);
+      this.Controls.SetChildIndex(this.pauseButton, 0);
       this.Controls.SetChildIndex(this.repetitionsLabel, 0);
       this.Controls.SetChildIndex(this.repetitionsNumericUpDown, 0);
-      this.Controls.SetChildIndex(this.resetButton, 0);
       this.Controls.SetChildIndex(this.executionTimeLabel, 0);
       this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
-      this.Controls.SetChildIndex(this.stopButton, 0);
       this.Controls.SetChildIndex(this.startButton, 0);
       this.Controls.SetChildIndex(this.tabControl, 0);
@@ -315,5 +331,4 @@
 
     }
-
     #endregion
 
@@ -335,4 +350,5 @@
     private System.Windows.Forms.NumericUpDown repetitionsNumericUpDown;
     private RunCollectionView runsView;
+    private System.Windows.Forms.Button pauseButton;
 
   }
Index: /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs	(revision 3265)
@@ -21,7 +21,7 @@
 
 using System;
-using System.Collections.Generic;
 using System.Windows.Forms;
 using HeuristicLab.Common;
+using HeuristicLab.Core;
 using HeuristicLab.Core.Views;
 using HeuristicLab.MainForm;
@@ -58,25 +58,22 @@
 
     protected override void DeregisterContentEvents() {
+      Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
       Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
+      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
       Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
-      Content.Prepared -= new EventHandler(Content_Prepared);
-      Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
       Content.RepetitionsChanged -= new EventHandler(Content_RepetitionsChanged);
-      Content.RunningChanged -= new EventHandler(Content_RunningChanged);
       base.DeregisterContentEvents();
     }
     protected override void RegisterContentEvents() {
       base.RegisterContentEvents();
+      Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
       Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
+      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
       Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
-      Content.Prepared += new EventHandler(Content_Prepared);
-      Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
       Content.RepetitionsChanged += new EventHandler(Content_RepetitionsChanged);
-      Content.RunningChanged += new EventHandler(Content_RunningChanged);
     }
 
     protected override void OnContentChanged() {
       base.OnContentChanged();
-      stopButton.Enabled = false;
       if (Content == null) {
         repetitionsNumericUpDown.Value = 1;
@@ -85,5 +82,5 @@
         runsView.Content = null;
         tabControl.Enabled = false;
-        startButton.Enabled = resetButton.Enabled = false;
+        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
         executionTimeTextBox.Text = "-";
         executionTimeTextBox.Enabled = false;
@@ -96,7 +93,6 @@
         runsView.Content = Content.Runs;
         tabControl.Enabled = true;
-        startButton.Enabled = !Content.Finished;
-        resetButton.Enabled = true;
-        UpdateExecutionTimeTextBox();
+        EnableDisableButtons();
+        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
         executionTimeTextBox.Enabled = true;
       }
@@ -104,9 +100,33 @@
 
     protected override void OnClosed(FormClosedEventArgs e) {
-      if (Content != null) Content.Stop();
+      if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
       base.OnClosed(e);
     }
 
     #region Content Events
+    private void Content_ExecutionStateChanged(object sender, EventArgs e) {
+      if (InvokeRequired)
+        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
+      else {
+        nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
+        descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
+        SaveEnabled = Content.ExecutionState != ExecutionState.Started;
+        repetitionsNumericUpDown.Enabled = Content.ExecutionState != ExecutionState.Started;
+        newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = Content.ExecutionState != ExecutionState.Started;
+        EnableDisableButtons();
+      }
+    }
+    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
+      if (InvokeRequired)
+        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
+      else
+        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
+    }
+    private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
+      if (InvokeRequired)
+        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
+      else
+        Auxiliary.ShowErrorMessageBox(e.Value);
+    }
     private void Content_AlgorithmChanged(object sender, EventArgs e) {
       if (InvokeRequired)
@@ -118,45 +138,17 @@
       }
     }
-    private void Content_Prepared(object sender, EventArgs e) {
-      if (InvokeRequired)
-        Invoke(new EventHandler(Content_Prepared), sender, e);
-      else {
-        startButton.Enabled = !Content.Finished;
-        UpdateExecutionTimeTextBox();
-      }
-    }
-    private void Content_RunningChanged(object sender, EventArgs e) {
-      if (InvokeRequired)
-        Invoke(new EventHandler(Content_RunningChanged), sender, e);
-      else {
-        SaveEnabled = !Content.Running;
-        repetitionsNumericUpDown.Enabled = !Content.Running;
-        newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = !Content.Running;
-        startButton.Enabled = !Content.Running && !Content.Finished;
-        stopButton.Enabled = Content.Running;
-        resetButton.Enabled = !Content.Running;
-        UpdateExecutionTimeTextBox();
-      }
-    }
-    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
-      UpdateExecutionTimeTextBox();
-    }
-    private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
-      if (InvokeRequired)
-        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
+    private void Content_RepetitionsChanged(object sender, EventArgs e) {
+      if (InvokeRequired)
+        Invoke(new EventHandler(Content_RepetitionsChanged), sender, e);
       else
-        Auxiliary.ShowErrorMessageBox(e.Value);
-    }
-    private void Content_RepetitionsChanged(object sender, EventArgs e) {
-      if (InvokeRequired)
-        Invoke(new EventHandler(Content_RepetitionsChanged), sender, e);
-      else {
         repetitionsNumericUpDown.Value = Content.Repetitions;
-        startButton.Enabled = !Content.Finished;
-      }
     }
     #endregion
 
     #region Control events
+    private void repetitionsNumericUpDown_Validated(object sender, System.EventArgs e) {
+      if (repetitionsNumericUpDown.Text == string.Empty)
+        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
+    }
     private void repetitionsNumericUpDown_ValueChanged(object sender, EventArgs e) {
       Content.Repetitions = (int)repetitionsNumericUpDown.Value;
@@ -227,18 +219,28 @@
       Content.Start();
     }
+    private void pauseButton_Click(object sender, EventArgs e) {
+      Content.Pause();
+    }
     private void stopButton_Click(object sender, EventArgs e) {
       Content.Stop();
     }
     private void resetButton_Click(object sender, EventArgs e) {
-      Content.Prepare();
+      if (Content.Runs.Count > 0) {
+        if (MessageBox.Show(this, "Clear all runs executed so far?", "Clear All Runs?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
+          Content.Prepare(true);
+        else
+          Content.Prepare(false);
+      } else {
+        Content.Prepare();
+      }
     }
     #endregion
 
     #region Helpers
-    private void UpdateExecutionTimeTextBox() {
-      if (InvokeRequired)
-        Invoke(new Action(UpdateExecutionTimeTextBox));
-      else
-        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
+    private void EnableDisableButtons() {
+      startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
+      pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
+      stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
+      resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
     }
     #endregion
Index: /trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj	(revision 3265)
@@ -92,4 +92,10 @@
       <DependentUpon>AlgorithmView.cs</DependentUpon>
     </Compile>
+    <Compile Include="BatchRunView.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="BatchRunView.Designer.cs">
+      <DependentUpon>BatchRunView.cs</DependentUpon>
+    </Compile>
     <Compile Include="RunCollectionView.cs">
       <SubType>UserControl</SubType>
Index: /trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs	(revision 3265)
@@ -22,4 +22,5 @@
 using System;
 using System.Drawing;
+using HeuristicLab.Common;
 using HeuristicLab.Core;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
@@ -32,7 +33,34 @@
   [Creatable("Testing & Analysis")]
   [StorableClass]
-  public sealed class BatchRun : NamedItem {
+  public sealed class BatchRun : NamedItem, IExecutable {
     public override Image ItemImage {
       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event; }
+    }
+
+    [Storable]
+    private ExecutionState executionState;
+    public ExecutionState ExecutionState {
+      get { return executionState; }
+      private set {
+        if (executionState != value) {
+          executionState = value;
+          OnExecutionStateChanged();
+        }
+      }
+    }
+
+    [Storable]
+    private TimeSpan executionTime;
+    public TimeSpan ExecutionTime {
+      get {
+        if ((Algorithm != null) && (Algorithm.ExecutionState != ExecutionState.Stopped))
+          return executionTime + Algorithm.ExecutionTime;
+        else
+          return executionTime;
+      }
+      private set {
+        executionTime = value;
+        OnExecutionTimeChanged();
+      }
     }
 
@@ -68,4 +96,6 @@
           repetitions = value;
           OnRepetitionsChanged();
+          if ((runs.Count < repetitions) && (Algorithm != null) && (Algorithm.ExecutionState == ExecutionState.Stopped))
+            Prepare(false);
         }
       }
@@ -78,161 +108,163 @@
     }
 
-    [Storable]
-    private TimeSpan executionTime;
-    public TimeSpan ExecutionTime {
-      get { return executionTime; }
-      private set {
-        if (executionTime != value) {
-          executionTime = value;
-          OnExecutionTimeChanged();
-        }
-      }
-    }
-
-    private bool running;
-    public bool Running {
-      get { return running; }
-      private set {
-        if (running != value) {
-          running = value;
-          OnRunningChanged();
-        }
-      }
-    }
-
-    public bool Finished {
-      get { return ((Algorithm == null) || (Algorithm.Finished && (runs.Count >= repetitions))); }
-    }
-
-    private bool canceled;
+    private bool stopPending;
 
     public BatchRun()
       : base() {
+      executionState = ExecutionState.Stopped;
+      executionTime = TimeSpan.Zero;
       repetitions = 10;
       runs = new RunCollection();
+      stopPending = false;
+    }
+    public BatchRun(string name) : base(name) {
+      executionState = ExecutionState.Stopped;
       executionTime = TimeSpan.Zero;
-    }
-    public BatchRun(string name) : base(name) {
       repetitions = 10;
       runs = new RunCollection();
+      stopPending = false;
+    }
+    public BatchRun(string name, string description) : base(name, description) {
+      executionState = ExecutionState.Stopped;
       executionTime = TimeSpan.Zero;
-    }
-    public BatchRun(string name, string description) : base(name, description) {
       repetitions = 10;
       runs = new RunCollection();
-      executionTime = TimeSpan.Zero;
+      stopPending = false;
     }
 
     public override IDeepCloneable Clone(Cloner cloner) {
       BatchRun clone = (BatchRun)base.Clone(cloner);
+      clone.executionState = executionState;
+      clone.executionTime = executionTime;
       clone.Algorithm = (IAlgorithm)cloner.Clone(algorithm);
       clone.repetitions = repetitions;
       clone.runs = (RunCollection)cloner.Clone(runs);
-      clone.executionTime = executionTime;
-      clone.running = running;
-      clone.canceled = canceled;
+      clone.stopPending = stopPending;
       return clone;
     }
 
     public void Prepare() {
-      executionTime = TimeSpan.Zero;
-      runs.Clear();
-      if (Algorithm != null) Algorithm.Prepare();
-      OnPrepared();
+      Prepare(true);
+    }
+    public void Prepare(bool clearRuns) {
+      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
+        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
+      if (Algorithm != null) {
+        if (clearRuns) {
+          ExecutionTime = TimeSpan.Zero;
+          runs.Clear();
+        }
+        Algorithm.Prepare();
+      }
     }
     public void Start() {
-      if (Algorithm != null) {
-        OnStarted();
-        Running = true;
-        canceled = false;
-        Algorithm.Start();
-      }
+      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
+        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
+      if (Algorithm != null) Algorithm.Start();
+    }
+    public void Pause() {
+      if (ExecutionState != ExecutionState.Started)
+        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
+      if (Algorithm != null) Algorithm.Pause();
     }
     public void Stop() {
-      if (Algorithm != null) {
-        canceled = true;
-        Algorithm.Stop();
-      }
+      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
+        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
+      stopPending = true;
+      if (Algorithm != null) Algorithm.Stop();
     }
 
     #region Events
+    public event EventHandler ExecutionStateChanged;
+    private void OnExecutionStateChanged() {
+      EventHandler handler = ExecutionStateChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler ExecutionTimeChanged;
+    private void OnExecutionTimeChanged() {
+      EventHandler handler = ExecutionTimeChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
     public event EventHandler AlgorithmChanged;
     private void OnAlgorithmChanged() {
-      if (AlgorithmChanged != null)
-        AlgorithmChanged(this, EventArgs.Empty);
+      EventHandler handler = AlgorithmChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
     }
     public event EventHandler RepetitionsChanged;
     private void OnRepetitionsChanged() {
-      if (RepetitionsChanged != null)
-        RepetitionsChanged(this, EventArgs.Empty);
-    }
-    public event EventHandler ExecutionTimeChanged;
-    private void OnExecutionTimeChanged() {
-      if (ExecutionTimeChanged != null)
-        ExecutionTimeChanged(this, EventArgs.Empty);
-    }
-    public event EventHandler RunningChanged;
-    private void OnRunningChanged() {
-      if (RunningChanged != null)
-        RunningChanged(this, EventArgs.Empty);
+      EventHandler handler = RepetitionsChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
     }
     public event EventHandler Prepared;
     private void OnPrepared() {
-      if (Prepared != null)
-        Prepared(this, EventArgs.Empty);
+      ExecutionState = ExecutionState.Prepared;
+      EventHandler handler = Prepared;
+      if (handler != null) handler(this, EventArgs.Empty);
     }
     public event EventHandler Started;
     private void OnStarted() {
-      if (Started != null)
-        Started(this, EventArgs.Empty);
+      ExecutionState = ExecutionState.Started;
+      EventHandler handler = Started;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler Paused;
+    private void OnPaused() {
+      ExecutionState = ExecutionState.Paused;
+      EventHandler handler = Paused;
+      if (handler != null) handler(this, EventArgs.Empty);
     }
     public event EventHandler Stopped;
     private void OnStopped() {
-      if (Stopped != null)
-        Stopped(this, EventArgs.Empty);
-    }
-    public event EventHandler<HeuristicLab.Common.EventArgs<Exception>> ExceptionOccurred;
+      ExecutionState = ExecutionState.Stopped;
+      EventHandler handler = Stopped;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
     private void OnExceptionOccurred(Exception exception) {
-      if (ExceptionOccurred != null)
-        ExceptionOccurred(this, new HeuristicLab.Common.EventArgs<Exception>(exception));
+      EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
+      if (handler != null) handler(this, new EventArgs<Exception>(exception));
     }
 
     private void RegisterAlgorithmEvents() {
-      algorithm.ExceptionOccurred += new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
+      algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
+      algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
+      algorithm.Paused += new EventHandler(Algorithm_Paused);
+      algorithm.Prepared += new EventHandler(Algorithm_Prepared);
       algorithm.Started += new EventHandler(Algorithm_Started);
       algorithm.Stopped += new EventHandler(Algorithm_Stopped);
     }
     private void DeregisterAlgorithmEvents() {
-      algorithm.ExceptionOccurred -= new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
+      algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
+      algorithm.ExecutionTimeChanged -= new EventHandler(Algorithm_ExecutionTimeChanged);
+      algorithm.Paused -= new EventHandler(Algorithm_Paused);
+      algorithm.Prepared -= new EventHandler(Algorithm_Prepared);
       algorithm.Started -= new EventHandler(Algorithm_Started);
       algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
     }
 
-    private void Algorithm_ExceptionOccurred(object sender, HeuristicLab.Common.EventArgs<Exception> e) {
+    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
       OnExceptionOccurred(e.Value);
     }
+    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
+      OnExecutionTimeChanged();
+    }
+    private void Algorithm_Paused(object sender, EventArgs e) {
+      OnPaused();
+    }
+    private void Algorithm_Prepared(object sender, EventArgs e) {
+      OnPrepared();
+    }
     private void Algorithm_Started(object sender, EventArgs e) {
-      if (!Running) {
-        OnStarted();
-        Running = true;
-        canceled = false;
-      }
+      stopPending = false;
+      OnStarted();
     }
     private void Algorithm_Stopped(object sender, EventArgs e) {
-      if (!canceled) {
-        ExecutionTime += Algorithm.ExecutionTime;
-        runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
+      ExecutionTime += Algorithm.ExecutionTime;
+      runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
+      OnStopped();
+
+      if (!stopPending && (runs.Count < repetitions)) {
         Algorithm.Prepare();
-
-        if (runs.Count < repetitions)
-          Algorithm.Start();
-        else {
-          Running = false;
-          OnStopped();
-        }
-      } else {
-        canceled = false;
-        Running = false;
-        OnStopped();
+        Algorithm.Start();
       }
     }
Index: /trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj	(revision 3264)
+++ /trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj	(revision 3265)
@@ -86,4 +86,5 @@
     <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
     <Compile Include="Algorithm.cs" />
+    <Compile Include="BatchRun.cs" />
     <Compile Include="RunCollection.cs" />
     <Compile Include="Run.cs" />
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj	(revision 3264)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj	(revision 3265)
@@ -97,4 +97,5 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Symbolic\SymbolicRegressionProblemView.cs">
+      <SubType>UserControl</SubType>
     </Compile>
     <Compile Include="Symbolic\SymbolicRegressionProblemView.Designer.cs">
