Changeset 3265


Ignore:
Timestamp:
04/05/10 03:17:25 (11 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

Location:
trunk/sources
Files:
1 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r3262 r3265  
    180180
    181181    public override void Prepare() {
    182       base.Prepare();
    183       if (Engine != null) {
    184         if (Problem == null) Engine.Prepare(null);
    185       }
     182      if (Problem != null) base.Prepare();
    186183    }
    187184
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/HeuristicLab.Algorithms.GeneticAlgorithm-3.3.Tests.csproj

    r3199 r3265  
    156156  </ItemGroup>
    157157  <ItemGroup>
    158     <None Include="GeneticAlgorithm.hl">
     158    <None Include="GA_TSP.hl">
    159159      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    160160    </None>
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs

    r3198 r3265  
    8080
    8181    [TestMethod]
    82     [DeploymentItem(@"GeneticAlgorithm.hl")]
     82    [DeploymentItem(@"GA_TSP.hl")]
    8383    public void GeneticAlgorithmPerformanceTest() {
    8484      ex = null;
    85       IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GeneticAlgorithm.hl");
     85      IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GA_TSP.hl");
    8686      ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
    8787      ga.Stopped += new EventHandler(ga_Stopped);
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r3262 r3265  
    155155
    156156    public override void Prepare() {
    157       base.Prepare();
    158       if (Engine != null) {
    159         if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
    160           Engine.Prepare(null);
    161       }
     157      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
     158        base.Prepare();
    162159    }
    163160
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3262 r3265  
    183183
    184184    public override void Prepare() {
    185       base.Prepare();
    186       if (Engine != null) {
    187         if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null)
    188           Engine.Prepare(null);
    189       }
     185      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
     186        base.Prepare();
    190187    }
    191188
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3262 r3265  
    177177
    178178    public override void Prepare() {
    179       base.Prepare();
    180       if (Engine != null) {
    181         if (Problem == null || MoveGenerator == null || MoveMaker == null || MoveEvaluator == null
    182           || TabuMoveEvaluator == null || TabuMoveMaker == null)
    183           Engine.Prepare(null);
    184       }
     179      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
     180          TabuMoveEvaluator != null && TabuMoveMaker != null)
     181        base.Prepare();
    185182    }
    186183
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r3262 r3265  
    102102    protected abstract void ProcessNextOperator();
    103103
    104     protected override void OnPrepared() {
    105       if (executionStack.Count > 0) base.OnPrepared();
    106       else base.OnStopped();
    107     }
    108 
    109104    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
    110105      DateTime now = DateTime.Now;
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3262 r3265  
    138138        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    139139      else {
     140        nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
     141        descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
    140142        SaveEnabled = Content.ExecutionState != ExecutionState.Started;
    141143        parameterCollectionView.Enabled = Content.ExecutionState != ExecutionState.Started;
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs

    r3261 r3265  
    5353      this.algorithmViewHost = new HeuristicLab.Core.Views.ViewHost();
    5454      this.runsTabPage = new System.Windows.Forms.TabPage();
     55      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    5556      this.startButton = new System.Windows.Forms.Button();
    5657      this.stopButton = new System.Windows.Forms.Button();
     
    6263      this.repetitionsLabel = new System.Windows.Forms.Label();
    6364      this.repetitionsNumericUpDown = new System.Windows.Forms.NumericUpDown();
    64       this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     65      this.pauseButton = new System.Windows.Forms.Button();
    6566      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6667      this.tabControl.SuspendLayout();
     
    163164      this.runsTabPage.UseVisualStyleBackColor = true;
    164165      //
     166      // runsView
     167      //
     168      this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     169                  | System.Windows.Forms.AnchorStyles.Left)
     170                  | System.Windows.Forms.AnchorStyles.Right)));
     171      this.runsView.Caption = "RunCollection";
     172      this.runsView.Content = null;
     173      this.runsView.Location = new System.Drawing.Point(6, 6);
     174      this.runsView.Name = "runsView";
     175      this.runsView.Size = new System.Drawing.Size(659, 336);
     176      this.runsView.TabIndex = 0;
     177      //
    165178      // startButton
    166179      //
     
    178191      //
    179192      this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    180       this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;
    181       this.stopButton.Location = new System.Drawing.Point(30, 458);
     193      this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Stop;
     194      this.stopButton.Location = new System.Drawing.Point(60, 458);
    182195      this.stopButton.Name = "stopButton";
    183196      this.stopButton.Size = new System.Drawing.Size(24, 24);
    184       this.stopButton.TabIndex = 8;
    185       this.toolTip.SetToolTip(this.stopButton, "Pause Batch Run");
     197      this.stopButton.TabIndex = 9;
     198      this.toolTip.SetToolTip(this.stopButton, "Stop Batch Run");
    186199      this.stopButton.UseVisualStyleBackColor = true;
    187200      this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
     
    191204      this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    192205      this.resetButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Restart;
    193       this.resetButton.Location = new System.Drawing.Point(60, 458);
     206      this.resetButton.Location = new System.Drawing.Point(90, 458);
    194207      this.resetButton.Name = "resetButton";
    195208      this.resetButton.Size = new System.Drawing.Size(24, 24);
    196       this.resetButton.TabIndex = 9;
     209      this.resetButton.TabIndex = 10;
    197210      this.toolTip.SetToolTip(this.resetButton, "Reset Batch Run");
    198211      this.resetButton.UseVisualStyleBackColor = true;
     
    206219      this.executionTimeLabel.Name = "executionTimeLabel";
    207220      this.executionTimeLabel.Size = new System.Drawing.Size(83, 13);
    208       this.executionTimeLabel.TabIndex = 10;
     221      this.executionTimeLabel.TabIndex = 11;
    209222      this.executionTimeLabel.Text = "&Execution Time:";
    210223      //
     
    216229      this.executionTimeTextBox.ReadOnly = true;
    217230      this.executionTimeTextBox.Size = new System.Drawing.Size(137, 20);
    218       this.executionTimeTextBox.TabIndex = 11;
     231      this.executionTimeTextBox.TabIndex = 12;
    219232      //
    220233      // openFileDialog
     
    266279            0,
    267280            0});
     281      this.repetitionsNumericUpDown.Validated += new System.EventHandler(repetitionsNumericUpDown_Validated);
    268282      this.repetitionsNumericUpDown.ValueChanged += new System.EventHandler(this.repetitionsNumericUpDown_ValueChanged);
    269283      //
    270       // runsView
    271       //
    272       this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    273                   | System.Windows.Forms.AnchorStyles.Left)
    274                   | System.Windows.Forms.AnchorStyles.Right)));
    275       this.runsView.Caption = "RunCollection";
    276       this.runsView.Content = null;
    277       this.runsView.Location = new System.Drawing.Point(6, 6);
    278       this.runsView.Name = "runsView";
    279       this.runsView.Size = new System.Drawing.Size(659, 336);
    280       this.runsView.TabIndex = 0;
     284      // pauseButton
     285      //
     286      this.pauseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     287      this.pauseButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;
     288      this.pauseButton.Location = new System.Drawing.Point(30, 458);
     289      this.pauseButton.Name = "pauseButton";
     290      this.pauseButton.Size = new System.Drawing.Size(24, 24);
     291      this.pauseButton.TabIndex = 8;
     292      this.toolTip.SetToolTip(this.pauseButton, "Pause Batch Run");
     293      this.pauseButton.UseVisualStyleBackColor = true;
     294      this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click);
    281295      //
    282296      // BatchRunView
     
    286300      this.Controls.Add(this.tabControl);
    287301      this.Controls.Add(this.startButton);
    288       this.Controls.Add(this.stopButton);
    289302      this.Controls.Add(this.executionTimeTextBox);
    290303      this.Controls.Add(this.executionTimeLabel);
    291       this.Controls.Add(this.resetButton);
    292304      this.Controls.Add(this.repetitionsNumericUpDown);
    293305      this.Controls.Add(this.repetitionsLabel);
     306      this.Controls.Add(this.pauseButton);
     307      this.Controls.Add(this.stopButton);
     308      this.Controls.Add(this.resetButton);
    294309      this.Name = "BatchRunView";
    295310      this.Size = new System.Drawing.Size(679, 482);
     311      this.Controls.SetChildIndex(this.resetButton, 0);
     312      this.Controls.SetChildIndex(this.stopButton, 0);
     313      this.Controls.SetChildIndex(this.pauseButton, 0);
    296314      this.Controls.SetChildIndex(this.repetitionsLabel, 0);
    297315      this.Controls.SetChildIndex(this.repetitionsNumericUpDown, 0);
    298       this.Controls.SetChildIndex(this.resetButton, 0);
    299316      this.Controls.SetChildIndex(this.executionTimeLabel, 0);
    300317      this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    301       this.Controls.SetChildIndex(this.stopButton, 0);
    302318      this.Controls.SetChildIndex(this.startButton, 0);
    303319      this.Controls.SetChildIndex(this.tabControl, 0);
     
    315331
    316332    }
    317 
    318333    #endregion
    319334
     
    335350    private System.Windows.Forms.NumericUpDown repetitionsNumericUpDown;
    336351    private RunCollectionView runsView;
     352    private System.Windows.Forms.Button pauseButton;
    337353
    338354  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r3261 r3265  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Windows.Forms;
    2524using HeuristicLab.Common;
     25using HeuristicLab.Core;
    2626using HeuristicLab.Core.Views;
    2727using HeuristicLab.MainForm;
     
    5858
    5959    protected override void DeregisterContentEvents() {
     60      Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
    6061      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     62      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
    6163      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    62       Content.Prepared -= new EventHandler(Content_Prepared);
    63       Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
    6464      Content.RepetitionsChanged -= new EventHandler(Content_RepetitionsChanged);
    65       Content.RunningChanged -= new EventHandler(Content_RunningChanged);
    6665      base.DeregisterContentEvents();
    6766    }
    6867    protected override void RegisterContentEvents() {
    6968      base.RegisterContentEvents();
     69      Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
    7070      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     71      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
    7172      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    72       Content.Prepared += new EventHandler(Content_Prepared);
    73       Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
    7473      Content.RepetitionsChanged += new EventHandler(Content_RepetitionsChanged);
    75       Content.RunningChanged += new EventHandler(Content_RunningChanged);
    7674    }
    7775
    7876    protected override void OnContentChanged() {
    7977      base.OnContentChanged();
    80       stopButton.Enabled = false;
    8178      if (Content == null) {
    8279        repetitionsNumericUpDown.Value = 1;
     
    8582        runsView.Content = null;
    8683        tabControl.Enabled = false;
    87         startButton.Enabled = resetButton.Enabled = false;
     84        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    8885        executionTimeTextBox.Text = "-";
    8986        executionTimeTextBox.Enabled = false;
     
    9693        runsView.Content = Content.Runs;
    9794        tabControl.Enabled = true;
    98         startButton.Enabled = !Content.Finished;
    99         resetButton.Enabled = true;
    100         UpdateExecutionTimeTextBox();
     95        EnableDisableButtons();
     96        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    10197        executionTimeTextBox.Enabled = true;
    10298      }
     
    104100
    105101    protected override void OnClosed(FormClosedEventArgs e) {
    106       if (Content != null) Content.Stop();
     102      if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
    107103      base.OnClosed(e);
    108104    }
    109105
    110106    #region Content Events
     107    private void Content_ExecutionStateChanged(object sender, EventArgs e) {
     108      if (InvokeRequired)
     109        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
     110      else {
     111        nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
     112        descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
     113        SaveEnabled = Content.ExecutionState != ExecutionState.Started;
     114        repetitionsNumericUpDown.Enabled = Content.ExecutionState != ExecutionState.Started;
     115        newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = Content.ExecutionState != ExecutionState.Started;
     116        EnableDisableButtons();
     117      }
     118    }
     119    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
     120      if (InvokeRequired)
     121        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
     122      else
     123        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
     124    }
     125    private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     126      if (InvokeRequired)
     127        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
     128      else
     129        Auxiliary.ShowErrorMessageBox(e.Value);
     130    }
    111131    private void Content_AlgorithmChanged(object sender, EventArgs e) {
    112132      if (InvokeRequired)
     
    118138      }
    119139    }
    120     private void Content_Prepared(object sender, EventArgs e) {
    121       if (InvokeRequired)
    122         Invoke(new EventHandler(Content_Prepared), sender, e);
    123       else {
    124         startButton.Enabled = !Content.Finished;
    125         UpdateExecutionTimeTextBox();
    126       }
    127     }
    128     private void Content_RunningChanged(object sender, EventArgs e) {
    129       if (InvokeRequired)
    130         Invoke(new EventHandler(Content_RunningChanged), sender, e);
    131       else {
    132         SaveEnabled = !Content.Running;
    133         repetitionsNumericUpDown.Enabled = !Content.Running;
    134         newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = !Content.Running;
    135         startButton.Enabled = !Content.Running && !Content.Finished;
    136         stopButton.Enabled = Content.Running;
    137         resetButton.Enabled = !Content.Running;
    138         UpdateExecutionTimeTextBox();
    139       }
    140     }
    141     private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    142       UpdateExecutionTimeTextBox();
    143     }
    144     private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    145       if (InvokeRequired)
    146         Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
     140    private void Content_RepetitionsChanged(object sender, EventArgs e) {
     141      if (InvokeRequired)
     142        Invoke(new EventHandler(Content_RepetitionsChanged), sender, e);
    147143      else
    148         Auxiliary.ShowErrorMessageBox(e.Value);
    149     }
    150     private void Content_RepetitionsChanged(object sender, EventArgs e) {
    151       if (InvokeRequired)
    152         Invoke(new EventHandler(Content_RepetitionsChanged), sender, e);
    153       else {
    154144        repetitionsNumericUpDown.Value = Content.Repetitions;
    155         startButton.Enabled = !Content.Finished;
    156       }
    157145    }
    158146    #endregion
    159147
    160148    #region Control events
     149    private void repetitionsNumericUpDown_Validated(object sender, System.EventArgs e) {
     150      if (repetitionsNumericUpDown.Text == string.Empty)
     151        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
     152    }
    161153    private void repetitionsNumericUpDown_ValueChanged(object sender, EventArgs e) {
    162154      Content.Repetitions = (int)repetitionsNumericUpDown.Value;
     
    227219      Content.Start();
    228220    }
     221    private void pauseButton_Click(object sender, EventArgs e) {
     222      Content.Pause();
     223    }
    229224    private void stopButton_Click(object sender, EventArgs e) {
    230225      Content.Stop();
    231226    }
    232227    private void resetButton_Click(object sender, EventArgs e) {
    233       Content.Prepare();
     228      if (Content.Runs.Count > 0) {
     229        if (MessageBox.Show(this, "Clear all runs executed so far?", "Clear All Runs?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
     230          Content.Prepare(true);
     231        else
     232          Content.Prepare(false);
     233      } else {
     234        Content.Prepare();
     235      }
    234236    }
    235237    #endregion
    236238
    237239    #region Helpers
    238     private void UpdateExecutionTimeTextBox() {
    239       if (InvokeRequired)
    240         Invoke(new Action(UpdateExecutionTimeTextBox));
    241       else
    242         executionTimeTextBox.Text = Content.ExecutionTime.ToString();
     240    private void EnableDisableButtons() {
     241      startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
     242      pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
     243      stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
     244      resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
    243245    }
    244246    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r3262 r3265  
    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>
    94100    <Compile Include="RunCollectionView.cs">
    95101      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3261 r3265  
    2222using System;
    2323using System.Drawing;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [Creatable("Testing & Analysis")]
    3334  [StorableClass]
    34   public sealed class BatchRun : NamedItem {
     35  public sealed class BatchRun : NamedItem, IExecutable {
    3536    public override Image ItemImage {
    3637      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 {
     56        if ((Algorithm != null) && (Algorithm.ExecutionState != ExecutionState.Stopped))
     57          return executionTime + Algorithm.ExecutionTime;
     58        else
     59          return executionTime;
     60      }
     61      private set {
     62        executionTime = value;
     63        OnExecutionTimeChanged();
     64      }
    3765    }
    3866
     
    6896          repetitions = value;
    6997          OnRepetitionsChanged();
     98          if ((runs.Count < repetitions) && (Algorithm != null) && (Algorithm.ExecutionState == ExecutionState.Stopped))
     99            Prepare(false);
    70100        }
    71101      }
     
    78108    }
    79109
    80     [Storable]
    81     private TimeSpan executionTime;
    82     public TimeSpan ExecutionTime {
    83       get { return executionTime; }
    84       private set {
    85         if (executionTime != value) {
    86           executionTime = value;
    87           OnExecutionTimeChanged();
    88         }
    89       }
    90     }
    91 
    92     private bool running;
    93     public bool Running {
    94       get { return running; }
    95       private set {
    96         if (running != value) {
    97           running = value;
    98           OnRunningChanged();
    99         }
    100       }
    101     }
    102 
    103     public bool Finished {
    104       get { return ((Algorithm == null) || (Algorithm.Finished && (runs.Count >= repetitions))); }
    105     }
    106 
    107     private bool canceled;
     110    private bool stopPending;
    108111
    109112    public BatchRun()
    110113      : base() {
     114      executionState = ExecutionState.Stopped;
     115      executionTime = TimeSpan.Zero;
    111116      repetitions = 10;
    112117      runs = new RunCollection();
     118      stopPending = false;
     119    }
     120    public BatchRun(string name) : base(name) {
     121      executionState = ExecutionState.Stopped;
    113122      executionTime = TimeSpan.Zero;
    114     }
    115     public BatchRun(string name) : base(name) {
    116123      repetitions = 10;
    117124      runs = new RunCollection();
     125      stopPending = false;
     126    }
     127    public BatchRun(string name, string description) : base(name, description) {
     128      executionState = ExecutionState.Stopped;
    118129      executionTime = TimeSpan.Zero;
    119     }
    120     public BatchRun(string name, string description) : base(name, description) {
    121130      repetitions = 10;
    122131      runs = new RunCollection();
    123       executionTime = TimeSpan.Zero;
     132      stopPending = false;
    124133    }
    125134
    126135    public override IDeepCloneable Clone(Cloner cloner) {
    127136      BatchRun clone = (BatchRun)base.Clone(cloner);
     137      clone.executionState = executionState;
     138      clone.executionTime = executionTime;
    128139      clone.Algorithm = (IAlgorithm)cloner.Clone(algorithm);
    129140      clone.repetitions = repetitions;
    130141      clone.runs = (RunCollection)cloner.Clone(runs);
    131       clone.executionTime = executionTime;
    132       clone.running = running;
    133       clone.canceled = canceled;
     142      clone.stopPending = stopPending;
    134143      return clone;
    135144    }
    136145
    137146    public void Prepare() {
    138       executionTime = TimeSpan.Zero;
    139       runs.Clear();
    140       if (Algorithm != null) Algorithm.Prepare();
    141       OnPrepared();
     147      Prepare(true);
     148    }
     149    public void Prepare(bool clearRuns) {
     150      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
     151        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
     152      if (Algorithm != null) {
     153        if (clearRuns) {
     154          ExecutionTime = TimeSpan.Zero;
     155          runs.Clear();
     156        }
     157        Algorithm.Prepare();
     158      }
    142159    }
    143160    public void Start() {
    144       if (Algorithm != null) {
    145         OnStarted();
    146         Running = true;
    147         canceled = false;
    148         Algorithm.Start();
    149       }
     161      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
     162        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     163      if (Algorithm != null) Algorithm.Start();
     164    }
     165    public void Pause() {
     166      if (ExecutionState != ExecutionState.Started)
     167        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
     168      if (Algorithm != null) Algorithm.Pause();
    150169    }
    151170    public void Stop() {
    152       if (Algorithm != null) {
    153         canceled = true;
    154         Algorithm.Stop();
    155       }
     171      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
     172        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
     173      stopPending = true;
     174      if (Algorithm != null) Algorithm.Stop();
    156175    }
    157176
    158177    #region Events
     178    public event EventHandler ExecutionStateChanged;
     179    private void OnExecutionStateChanged() {
     180      EventHandler handler = ExecutionStateChanged;
     181      if (handler != null) handler(this, EventArgs.Empty);
     182    }
     183    public event EventHandler ExecutionTimeChanged;
     184    private void OnExecutionTimeChanged() {
     185      EventHandler handler = ExecutionTimeChanged;
     186      if (handler != null) handler(this, EventArgs.Empty);
     187    }
    159188    public event EventHandler AlgorithmChanged;
    160189    private void OnAlgorithmChanged() {
    161       if (AlgorithmChanged != null)
    162         AlgorithmChanged(this, EventArgs.Empty);
     190      EventHandler handler = AlgorithmChanged;
     191      if (handler != null) handler(this, EventArgs.Empty);
    163192    }
    164193    public event EventHandler RepetitionsChanged;
    165194    private void OnRepetitionsChanged() {
    166       if (RepetitionsChanged != null)
    167         RepetitionsChanged(this, EventArgs.Empty);
    168     }
    169     public event EventHandler ExecutionTimeChanged;
    170     private void OnExecutionTimeChanged() {
    171       if (ExecutionTimeChanged != null)
    172         ExecutionTimeChanged(this, EventArgs.Empty);
    173     }
    174     public event EventHandler RunningChanged;
    175     private void OnRunningChanged() {
    176       if (RunningChanged != null)
    177         RunningChanged(this, EventArgs.Empty);
     195      EventHandler handler = RepetitionsChanged;
     196      if (handler != null) handler(this, EventArgs.Empty);
    178197    }
    179198    public event EventHandler Prepared;
    180199    private void OnPrepared() {
    181       if (Prepared != null)
    182         Prepared(this, EventArgs.Empty);
     200      ExecutionState = ExecutionState.Prepared;
     201      EventHandler handler = Prepared;
     202      if (handler != null) handler(this, EventArgs.Empty);
    183203    }
    184204    public event EventHandler Started;
    185205    private void OnStarted() {
    186       if (Started != null)
    187         Started(this, EventArgs.Empty);
     206      ExecutionState = ExecutionState.Started;
     207      EventHandler handler = Started;
     208      if (handler != null) handler(this, EventArgs.Empty);
     209    }
     210    public event EventHandler Paused;
     211    private void OnPaused() {
     212      ExecutionState = ExecutionState.Paused;
     213      EventHandler handler = Paused;
     214      if (handler != null) handler(this, EventArgs.Empty);
    188215    }
    189216    public event EventHandler Stopped;
    190217    private void OnStopped() {
    191       if (Stopped != null)
    192         Stopped(this, EventArgs.Empty);
    193     }
    194     public event EventHandler<HeuristicLab.Common.EventArgs<Exception>> ExceptionOccurred;
     218      ExecutionState = ExecutionState.Stopped;
     219      EventHandler handler = Stopped;
     220      if (handler != null) handler(this, EventArgs.Empty);
     221    }
     222    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    195223    private void OnExceptionOccurred(Exception exception) {
    196       if (ExceptionOccurred != null)
    197         ExceptionOccurred(this, new HeuristicLab.Common.EventArgs<Exception>(exception));
     224      EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
     225      if (handler != null) handler(this, new EventArgs<Exception>(exception));
    198226    }
    199227
    200228    private void RegisterAlgorithmEvents() {
    201       algorithm.ExceptionOccurred += new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     229      algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     230      algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
     231      algorithm.Paused += new EventHandler(Algorithm_Paused);
     232      algorithm.Prepared += new EventHandler(Algorithm_Prepared);
    202233      algorithm.Started += new EventHandler(Algorithm_Started);
    203234      algorithm.Stopped += new EventHandler(Algorithm_Stopped);
    204235    }
    205236    private void DeregisterAlgorithmEvents() {
    206       algorithm.ExceptionOccurred -= new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     237      algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     238      algorithm.ExecutionTimeChanged -= new EventHandler(Algorithm_ExecutionTimeChanged);
     239      algorithm.Paused -= new EventHandler(Algorithm_Paused);
     240      algorithm.Prepared -= new EventHandler(Algorithm_Prepared);
    207241      algorithm.Started -= new EventHandler(Algorithm_Started);
    208242      algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
    209243    }
    210244
    211     private void Algorithm_ExceptionOccurred(object sender, HeuristicLab.Common.EventArgs<Exception> e) {
     245    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    212246      OnExceptionOccurred(e.Value);
    213247    }
     248    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
     249      OnExecutionTimeChanged();
     250    }
     251    private void Algorithm_Paused(object sender, EventArgs e) {
     252      OnPaused();
     253    }
     254    private void Algorithm_Prepared(object sender, EventArgs e) {
     255      OnPrepared();
     256    }
    214257    private void Algorithm_Started(object sender, EventArgs e) {
    215       if (!Running) {
    216         OnStarted();
    217         Running = true;
    218         canceled = false;
    219       }
     258      stopPending = false;
     259      OnStarted();
    220260    }
    221261    private void Algorithm_Stopped(object sender, EventArgs e) {
    222       if (!canceled) {
    223         ExecutionTime += Algorithm.ExecutionTime;
    224         runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
     262      ExecutionTime += Algorithm.ExecutionTime;
     263      runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
     264      OnStopped();
     265
     266      if (!stopPending && (runs.Count < repetitions)) {
    225267        Algorithm.Prepare();
    226 
    227         if (runs.Count < repetitions)
    228           Algorithm.Start();
    229         else {
    230           Running = false;
    231           OnStopped();
    232         }
    233       } else {
    234         canceled = false;
    235         Running = false;
    236         OnStopped();
     268        Algorithm.Start();
    237269      }
    238270    }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3262 r3265  
    8686    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    8787    <Compile Include="Algorithm.cs" />
     88    <Compile Include="BatchRun.cs" />
    8889    <Compile Include="RunCollection.cs" />
    8990    <Compile Include="Run.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r3264 r3265  
    9797    <Compile Include="Properties\AssemblyInfo.cs" />
    9898    <Compile Include="Symbolic\SymbolicRegressionProblemView.cs">
     99      <SubType>UserControl</SubType>
    99100    </Compile>
    100101    <Compile Include="Symbolic\SymbolicRegressionProblemView.Designer.cs">
Note: See TracChangeset for help on using the changeset viewer.