Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3262 for trunk


Ignore:
Timestamp:
04/04/10 05:22:47 (15 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

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  
    5555      // createUserDefinedAlgorithmButton
    5656      //
    57       this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(90, 552);
     57      this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(150, 552);
    5858      this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm");
    5959      //
     
    105105      //
    106106      this.startButton.Location = new System.Drawing.Point(0, 552);
     107      this.toolTip.SetToolTip(this.startButton, "Start/Resume Algorithm");
    107108      //
    108       // stopButton
     109      // pauseButton
    109110      //
    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");
    111113      //
    112114      // resetButton
    113115      //
    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");
    115118      //
    116119      // executionTimeLabel
     
    129132      //
    130133      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");
    131139      //
    132140      // nameTextBox
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r3199 r3262  
    179179    }
    180180
    181     protected override void OnPrepared() {
    182       base.OnPrepared();
     181    public override void Prepare() {
     182      base.Prepare();
    183183      if (Engine != null) {
    184184        if (Problem == null) Engine.Prepare(null);
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r3201 r3262  
    154154    }
    155155
    156     protected override void OnPrepared() {
    157       base.OnPrepared();
     156    public override void Prepare() {
     157      base.Prepare();
    158158      if (Engine != null) {
    159159        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3201 r3262  
    182182    }
    183183
    184     protected override void OnPrepared() {
    185       base.OnPrepared();
     184    public override void Prepare() {
     185      base.Prepare();
    186186      if (Engine != null) {
    187187        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3232 r3262  
    176176    }
    177177
    178     protected override void OnPrepared() {
    179       base.OnPrepared();
     178    public override void Prepare() {
     179      base.Prepare();
    180180      if (Engine != null) {
    181181        if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs

    r3261 r3262  
    3232  [Content(typeof(IEngine), false)]
    3333  public partial class EngineView : ItemView {
    34     private int executionTimeCounter;
    35 
    3634    /// <summary>
    3735    /// Gets or sets the current engine.
     
    5957    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    6058    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);
    6360      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    6461      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     
    7269    protected override void RegisterContentEvents() {
    7370      base.RegisterContentEvents();
    74       Content.Prepared += new EventHandler(Content_Prepared);
    75       Content.RunningChanged += new EventHandler(Content_RunningChanged);
     71      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
    7672      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    7773      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     
    8783      if (Content == null) {
    8884        logTextBox.Enabled = false;
     85        executionTimeTextBox.Text = "-";
    8986        executionTimeTextBox.Enabled = false;
    9087      } else {
    9188        logTextBox.Enabled = true;
    92         UpdateExecutionTimeTextBox();
     89        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    9390        executionTimeTextBox.Enabled = true;
    9491      }
     
    9693
    9794    #region Content Events
    98     protected virtual void Content_Prepared(object sender, EventArgs e) {
     95    protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {
    9996      if (InvokeRequired)
    100         Invoke(new EventHandler(Content_Prepared), sender, e);
     97        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    10198      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");
    115103      }
    116104    }
    117105    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();
    123110    }
    124111    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     
    131118
    132119    #region Helpers
    133     protected virtual void UpdateExecutionTimeTextBox() {
    134       if (InvokeRequired)
    135         Invoke(new Action(UpdateExecutionTimeTextBox));
    136       else
    137         executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    138     }
    139120    protected virtual void Log(string message) {
    140121      if (InvokeRequired)
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r3261 r3262  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Threading;
    26 using HeuristicLab.Common;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
    2927namespace HeuristicLab.Core {
    30   /// <summary>
    31   /// Base class to represent an engine, which is an interpreter, holding the code, the data and
    32   /// the actual state, which is the runtime stack and a pointer onto the next operation. It represents
    33   /// one execution and can handle parallel executions.
    34   /// </summary>
    3528  [Item("Engine", "A base class for engines.")]
    3629  [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 {
    5931    [Storable]
    6032    private Stack<IOperation> executionStack;
    61     /// <summary>
    62     /// Gets the current execution stack.
    63     /// </summary>
    6433    protected Stack<IOperation> ExecutionStack {
    6534      get { return executionStack; }
    6635    }
    6736
    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);
    8348    }
    8449
    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 class
    119     /// <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>
    12250    public override IDeepCloneable Clone(Cloner cloner) {
    12351      Engine clone = (Engine)base.Clone(cloner);
    124       clone.executionTime = executionTime;
    12552      IOperation[] contexts = executionStack.ToArray();
    12653      for (int i = contexts.Length - 1; i >= 0; i--)
    12754        clone.executionStack.Push((IOperation)cloner.Clone(contexts[i]));
    128       clone.running = running;
    129       clone.canceled = canceled;
     55      clone.pausePending = pausePending;
     56      clone.stopPending = stopPending;
    13057      return clone;
    13158    }
    13259
     60    public sealed override void Prepare() {
     61      base.Prepare();
     62      executionStack.Clear();
     63      OnPrepared();
     64    }
    13365    public void Prepare(IOperation initialOperation) {
    134       ExecutionTime = new TimeSpan();
     66      base.Prepare();
    13567      executionStack.Clear();
    13668      if (initialOperation != null)
     
    13870      OnPrepared();
    13971    }
    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();
    14474      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
    14575    }
    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;
    15179    }
    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();
    15684    }
    15785
    15886    private void Run(object state) {
    15987      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)) {
    16593        ProcessNextOperator();
    166         end = DateTime.Now;
    167         ExecutionTime += end - start;
    168         start = end;
    16994      }
    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();
    186100    }
    187101
    188     /// <summary>
    189     /// Performs the next operation.
    190     /// </summary>
    191102    protected abstract void ProcessNextOperator();
    192103
    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();
    203107    }
    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;
    260113    }
    261114  }
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2932 r3262  
    103103    <Compile Include="Attributes\CreatableAttribute.cs" />
    104104    <None Include="HeuristicLabCorePlugin.cs.frame" />
     105    <Compile Include="Executable.cs" />
     106    <Compile Include="ExecutionState.cs" />
     107    <Compile Include="Interfaces\IExecutable.cs" />
    105108    <Compile Include="Interfaces\IParameterizedNamedItem.cs" />
    106109    <Compile Include="Interfaces\IParameterizedItem.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs

    r3226 r3262  
    2424
    2525namespace 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 {
    4927    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;
    8728  }
    8829}
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.Designer.cs

    r3226 r3262  
    5757      this.resultsView = new HeuristicLab.Optimization.Views.ResultCollectionView();
    5858      this.startButton = new System.Windows.Forms.Button();
    59       this.stopButton = new System.Windows.Forms.Button();
     59      this.pauseButton = new System.Windows.Forms.Button();
    6060      this.resetButton = new System.Windows.Forms.Button();
    6161      this.executionTimeLabel = new System.Windows.Forms.Label();
     
    6363      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    6464      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
     65      this.stopButton = new System.Windows.Forms.Button();
    6566      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6667      this.tabControl.SuspendLayout();
     
    211212      this.startButton.Click += new System.EventHandler(this.startButton_Click);
    212213      //
    213       // stopButton
    214       //
    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);
    224225      //
    225226      // resetButton
     
    227228      this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    228229      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);
    230231      this.resetButton.Name = "resetButton";
    231232      this.resetButton.Size = new System.Drawing.Size(24, 24);
    232       this.resetButton.TabIndex = 7;
     233      this.resetButton.TabIndex = 8;
    233234      this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm");
    234235      this.resetButton.UseVisualStyleBackColor = true;
     
    242243      this.executionTimeLabel.Name = "executionTimeLabel";
    243244      this.executionTimeLabel.Size = new System.Drawing.Size(83, 13);
    244       this.executionTimeLabel.TabIndex = 8;
     245      this.executionTimeLabel.TabIndex = 9;
    245246      this.executionTimeLabel.Text = "&Execution Time:";
    246247      //
     
    252253      this.executionTimeTextBox.ReadOnly = true;
    253254      this.executionTimeTextBox.Size = new System.Drawing.Size(137, 20);
    254       this.executionTimeTextBox.TabIndex = 9;
     255      this.executionTimeTextBox.TabIndex = 10;
    255256      //
    256257      // openFileDialog
     
    269270      this.saveFileDialog.Title = "Save Problem";
    270271      //
     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      //
    271284      // AlgorithmView
    272285      //
     
    275288      this.Controls.Add(this.tabControl);
    276289      this.Controls.Add(this.startButton);
    277       this.Controls.Add(this.stopButton);
     290      this.Controls.Add(this.pauseButton);
    278291      this.Controls.Add(this.executionTimeTextBox);
    279292      this.Controls.Add(this.executionTimeLabel);
     293      this.Controls.Add(this.stopButton);
    280294      this.Controls.Add(this.resetButton);
    281295      this.Name = "AlgorithmView";
    282296      this.Size = new System.Drawing.Size(679, 482);
    283297      this.Controls.SetChildIndex(this.resetButton, 0);
     298      this.Controls.SetChildIndex(this.stopButton, 0);
    284299      this.Controls.SetChildIndex(this.executionTimeLabel, 0);
    285300      this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    286       this.Controls.SetChildIndex(this.stopButton, 0);
     301      this.Controls.SetChildIndex(this.pauseButton, 0);
    287302      this.Controls.SetChildIndex(this.startButton, 0);
    288303      this.Controls.SetChildIndex(this.tabControl, 0);
     
    312327    protected System.Windows.Forms.Button openProblemButton;
    313328    protected System.Windows.Forms.Button startButton;
    314     protected System.Windows.Forms.Button stopButton;
     329    protected System.Windows.Forms.Button pauseButton;
    315330    protected System.Windows.Forms.Button resetButton;
    316331    protected System.Windows.Forms.Label executionTimeLabel;
     
    320335    protected System.Windows.Forms.TabPage resultsTabPage;
    321336    protected HeuristicLab.Optimization.Views.ResultCollectionView resultsView;
     337    protected System.Windows.Forms.Button stopButton;
    322338
    323339  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3261 r3262  
    2424using System.Windows.Forms;
    2525using HeuristicLab.Common;
     26using HeuristicLab.Core;
    2627using HeuristicLab.Core.Views;
    2728using HeuristicLab.MainForm;
     
    3738  public partial class AlgorithmView : NamedItemView {
    3839    private TypeSelectorDialog problemTypeSelectorDialog;
    39     private int executionTimeCounter;
    4040
    4141    public new IAlgorithm Content {
     
    7575    protected override void DeregisterContentEvents() {
    7676      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     77      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
    7778      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    7879      Content.Prepared -= new EventHandler(Content_Prepared);
    7980      Content.ProblemChanged -= new EventHandler(Content_ProblemChanged);
    80       Content.RunningChanged -= new EventHandler(Content_RunningChanged);
    8181      base.DeregisterContentEvents();
    8282    }
     
    8484      base.RegisterContentEvents();
    8585      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     86      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
    8687      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    8788      Content.Prepared += new EventHandler(Content_Prepared);
    8889      Content.ProblemChanged += new EventHandler(Content_ProblemChanged);
    89       Content.RunningChanged += new EventHandler(Content_RunningChanged);
    9090    }
    9191
    9292    protected override void OnContentChanged() {
    9393      base.OnContentChanged();
    94       stopButton.Enabled = false;
    9594      if (Content == null) {
    9695        parameterCollectionView.Content = null;
     
    9897        resultsView.Content = null;
    9998        tabControl.Enabled = false;
    100         startButton.Enabled = resetButton.Enabled = false;
     99        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    101100        executionTimeTextBox.Text = "-";
    102101        executionTimeTextBox.Enabled = false;
     
    108107        resultsView.Content = Content.Results.AsReadOnly();
    109108        tabControl.Enabled = true;
    110         startButton.Enabled = !Content.Finished;
    111         resetButton.Enabled = true;
    112         UpdateExecutionTimeTextBox();
     109        EnableDisableButtons();
     110        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    113111        executionTimeTextBox.Enabled = true;
    114112      }
     
    116114
    117115    protected override void OnClosed(FormClosedEventArgs e) {
    118       if (Content != null) Content.Stop();
     116      if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
    119117      base.OnClosed(e);
    120118    }
    121119
    122120    #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     }
    133121    protected virtual void Content_ProblemChanged(object sender, EventArgs e) {
    134122      if (InvokeRequired)
     
    140128      }
    141129    }
    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);
    145139      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();
    155146      }
    156147    }
    157148    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();
    163153    }
    164154    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     
    238228      Content.Start();
    239229    }
     230    protected virtual void pauseButton_Click(object sender, EventArgs e) {
     231      Content.Pause();
     232    }
    240233    protected virtual void stopButton_Click(object sender, EventArgs e) {
    241234      Content.Stop();
     
    247240
    248241    #region Helpers
    249     protected virtual void UpdateExecutionTimeTextBox() {
    250       if (InvokeRequired)
    251         Invoke(new Action(UpdateExecutionTimeTextBox));
    252       else
    253         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;
    254247    }
    255248    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.Designer.cs

    r3225 r3262  
    9898      //
    9999      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);
    100129      //
    101130      // stopButton
    102131      //
    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");
    126134      //
    127135      // nameTextBox
     
    147155      //
    148156      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);
    150158      this.createUserDefinedAlgorithmButton.Name = "createUserDefinedAlgorithmButton";
    151159      this.createUserDefinedAlgorithmButton.Size = new System.Drawing.Size(254, 24);
    152       this.createUserDefinedAlgorithmButton.TabIndex = 8;
     160      this.createUserDefinedAlgorithmButton.TabIndex = 9;
    153161      this.createUserDefinedAlgorithmButton.Text = "&Create User Defined Algorithm";
    154162      this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm");
     
    164172      this.engineComboBox.Location = new System.Drawing.Point(55, 6);
    165173      this.engineComboBox.Name = "engineComboBox";
    166       this.engineComboBox.Size = new System.Drawing.Size(644, 21);
     174      this.engineComboBox.Size = new System.Drawing.Size(610, 21);
    167175      this.engineComboBox.TabIndex = 1;
    168176      this.engineComboBox.SelectedIndexChanged += new System.EventHandler(this.engineComboBox_SelectedIndexChanged);
     
    189197      this.engineViewHost.Location = new System.Drawing.Point(6, 33);
    190198      this.engineViewHost.Name = "engineViewHost";
    191       this.engineViewHost.Size = new System.Drawing.Size(693, 402);
     199      this.engineViewHost.Size = new System.Drawing.Size(659, 335);
    192200      this.engineViewHost.TabIndex = 2;
    193201      this.engineViewHost.ViewType = null;
     
    200208      this.Name = "EngineAlgorithmView";
    201209      this.Size = new System.Drawing.Size(713, 549);
     210      this.Controls.SetChildIndex(this.stopButton, 0);
    202211      this.Controls.SetChildIndex(this.createUserDefinedAlgorithmButton, 0);
    203212      this.Controls.SetChildIndex(this.resetButton, 0);
     213      this.Controls.SetChildIndex(this.pauseButton, 0);
    204214      this.Controls.SetChildIndex(this.executionTimeLabel, 0);
    205215      this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    206       this.Controls.SetChildIndex(this.stopButton, 0);
    207216      this.Controls.SetChildIndex(this.startButton, 0);
    208217      this.Controls.SetChildIndex(this.tabControl, 0);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.cs

    r3261 r3262  
    9898    }
    9999
    100     protected override void Content_RunningChanged(object sender, EventArgs e) {
     100    protected override void Content_ExecutionStateChanged(object sender, EventArgs e) {
    101101      if (InvokeRequired)
    102         Invoke(new EventHandler(Content_RunningChanged), sender, e);
     102        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    103103      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);
    108108      }
    109109    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r3260 r3262  
    9292      <DependentUpon>AlgorithmView.cs</DependentUpon>
    9393    </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>
    10094    <Compile Include="RunCollectionView.cs">
    10195      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.Designer.cs

    r3225 r3262  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserDefinedAlgorithmView));
    4847      this.operatorGraphTabPage = new System.Windows.Forms.TabPage();
    4948      this.saveOperatorGraphButton = new System.Windows.Forms.Button();
     
    6665      //
    6766      this.createUserDefinedAlgorithmButton.Enabled = false;
     67      this.createUserDefinedAlgorithmButton.Location = new System.Drawing.Point(150, 525);
     68      this.createUserDefinedAlgorithmButton.TabIndex = 9;
    6869      this.toolTip.SetToolTip(this.createUserDefinedAlgorithmButton, "Create User Defined Algorithm from this Algorithm");
    6970      this.createUserDefinedAlgorithmButton.Visible = false;
     
    9192      //
    9293      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");
    93120      //
    94121      // nameTextBox
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs

    r3261 r3262  
    7575    }
    7676
    77     protected override void Content_RunningChanged(object sender, EventArgs e) {
     77    protected override void Content_ExecutionStateChanged(object sender, EventArgs e) {
    7878      if (InvokeRequired)
    79         Invoke(new EventHandler(Content_RunningChanged), sender, e);
     79        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    8080      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);
    8585      }
    8686    }
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r3261 r3262  
    3636    public override Image ItemImage {
    3737      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      }
    3860    }
    3961
     
    6890    public abstract ResultCollection Results { get; }
    6991
    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    }
    101117
    102118    public override IDeepCloneable Clone(Cloner cloner) {
    103119      Algorithm clone = (Algorithm)base.Clone(cloner);
     120      clone.executionState = executionState;
     121      clone.executionTime = executionTime;
    104122      clone.Problem = (IProblem)cloner.Clone(problem);
    105       clone.running = running;
    106       clone.canceled = canceled;
    107123      return clone;
    108124    }
    109125
    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));
    120142    }
    121143
     
    130152
    131153    #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    }
    132164    public event EventHandler ProblemChanged;
    133165    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);
    146168    }
    147169    public event EventHandler Prepared;
    148170    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);
    151174    }
    152175    public event EventHandler Started;
    153176    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);
    156186    }
    157187    public event EventHandler Stopped;
    158188    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    }
    165193    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    166194    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));
    169197    }
    170198
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3261 r3262  
    9494    }
    9595
    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 
    11096    protected EngineAlgorithm()
    11197      : base() {
     
    172158    }
    173159
    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();
    179162      globalScope.Clear();
    180163      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     
    195178        engine.Prepare(context);
    196179      }
    197       base.OnPrepared();
    198     }
    199     protected override void OnStarted() {
     180    }
     181    public override void Start() {
     182      base.Start();
    200183      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
    206195    public event EventHandler EngineChanged;
    207196    protected virtual void OnEngineChanged() {
     
    209198        EngineChanged(this, EventArgs.Empty);
    210199    }
    211 
    212     private void OperatorGraph_InitialOperatorChanged(object sender, EventArgs e) {
    213       Prepare();
    214     }
     200    protected virtual void OnOperatorGraphChanged() { }
     201
    215202    private void RegisterEngineEvents() {
    216203      Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    217204      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);
    218208      Engine.Stopped += new EventHandler(Engine_Stopped);
    219209    }
    220 
    221210    private void DeregisterEngineEvents() {
    222211      Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    223212      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);
    224216      Engine.Stopped -= new EventHandler(Engine_Stopped);
    225217    }
    226 
    227218    private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    228219      OnExceptionOccurred(e.Value);
    229220    }
    230221    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();
    232232    }
    233233    private void Engine_Stopped(object sender, EventArgs e) {
    234234      OnStopped();
    235235    }
     236
     237    private void OperatorGraph_InitialOperatorChanged(object sender, EventArgs e) {
     238      Prepare();
     239    }
     240    #endregion
    236241  }
    237242}
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3260 r3262  
    8686    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    8787    <Compile Include="Algorithm.cs" />
    88     <Compile Include="BatchRun.cs" />
    8988    <Compile Include="RunCollection.cs" />
    9089    <Compile Include="Run.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IAlgorithm.cs

    r3260 r3262  
    2929  /// Interface to represent an algorithm.
    3030  /// </summary>
    31   public interface IAlgorithm : IParameterizedNamedItem {
     31  public interface IAlgorithm : IParameterizedNamedItem, IExecutable {
    3232    Type ProblemType { get; }
    3333    IProblem Problem { get; set; }
    3434    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();
    4235
    4336    void CollectResultValues(IDictionary<string, IItem> values);
    4437
    4538    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;
    5239  }
    5340}
  • trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs

    r3017 r3262  
    5555    public event EventHandler OperatorGraphChanged;
    5656    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);
    5959    }
    6060  }
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r3226 r3262  
    5656          currentOperator = operation.Operator;
    5757          ExecutionStack.Push(operation.Operator.Execute((IExecutionContext)operation));
    58           currentOperator = null;
    5958        }
    6059        catch (Exception ex) {
    6160          ExecutionStack.Push(operation);
    6261          OnExceptionOccurred(ex);
    63           Stop();
     62          Pause();
    6463        }
    6564        if (operation.Operator.Breakpoint)
    66           Stop();
     65          Pause();
    6766      }
    6867    }
    6968
    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();
    7376    }
    7477  }
Note: See TracChangeset for help on using the changeset viewer.