Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3274


Ignore:
Timestamp:
04/06/10 01:57:29 (14 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

Location:
trunk/sources
Files:
4 added
3 deleted
21 edited

Legend:

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

    r3265 r3274  
    179179    }
    180180
    181     public override void Prepare() {
    182       if (Problem != null) base.Prepare();
     181    public override void Prepare(bool clearResults) {
     182      if (Problem != null) base.Prepare(clearResults);
    183183    }
    184184
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r3265 r3274  
    154154    }
    155155
    156     public override void Prepare() {
     156    public override void Prepare(bool clearResults) {
    157157      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
    158         base.Prepare();
     158        base.Prepare(clearResults);
    159159    }
    160160
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3265 r3274  
    182182    }
    183183
    184     public override void Prepare() {
     184    public override void Prepare(bool clearResults) {
    185185      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
    186         base.Prepare();
     186        base.Prepare(clearResults);
    187187    }
    188188
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3265 r3274  
    176176    }
    177177
    178     public override void Prepare() {
     178    public override void Prepare(bool clearResults) {
    179179      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
    180180          TabuMoveEvaluator != null && TabuMoveMaker != null)
    181         base.Prepare();
     181        base.Prepare(clearResults);
    182182    }
    183183
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorListView.cs

    r2924 r3274  
    1 using System.Windows.Forms;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Windows.Forms;
    223using HeuristicLab.Collections;
    324using HeuristicLab.MainForm;
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3265 r3274  
    237237    }
    238238    protected virtual void resetButton_Click(object sender, EventArgs e) {
    239       Content.Prepare();
     239      if (Content.Results.Count > 0) {
     240        if (MessageBox.Show(this, "Clear all results of this run?", "Clear All Results?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
     241          Content.Prepare(true);
     242        else
     243          Content.Prepare(false);
     244      } else {
     245        Content.Prepare();
     246      }
    240247    }
    241248    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r3265 r3274  
    227227    private void resetButton_Click(object sender, EventArgs e) {
    228228      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)
     229        if (MessageBox.Show(this, "Clear all runs executed so far?", "Clear All Runs?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
    230230          Content.Prepare(true);
    231231        else
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.Designer.cs

    r3267 r3274  
    4646    private void InitializeComponent() {
    4747      this.tabControl = new System.Windows.Forms.TabControl();
    48       this.batchRunsTabPage = new System.Windows.Forms.TabPage();
    49       this.resultsTabPage = new System.Windows.Forms.TabPage();
    50       this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     48      this.optimizersTabPage = new System.Windows.Forms.TabPage();
    5149      this.startButton = new System.Windows.Forms.Button();
    5250      this.stopButton = new System.Windows.Forms.Button();
     
    5553      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
    5654      this.pauseButton = new System.Windows.Forms.Button();
    57       this.batchRunListView = new HeuristicLab.Optimization.Views.BatchRunListView();
     55      this.optimizerListView = new HeuristicLab.Optimization.Views.OptimizerListView();
    5856      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5957      this.tabControl.SuspendLayout();
    60       this.batchRunsTabPage.SuspendLayout();
    61       this.resultsTabPage.SuspendLayout();
     58      this.optimizersTabPage.SuspendLayout();
    6259      this.SuspendLayout();
    6360      //
     
    7774                  | System.Windows.Forms.AnchorStyles.Left)
    7875                  | System.Windows.Forms.AnchorStyles.Right)));
    79       this.tabControl.Controls.Add(this.batchRunsTabPage);
    80       this.tabControl.Controls.Add(this.resultsTabPage);
     76      this.tabControl.Controls.Add(this.optimizersTabPage);
    8177      this.tabControl.Location = new System.Drawing.Point(0, 52);
    8278      this.tabControl.Name = "tabControl";
     
    8581      this.tabControl.TabIndex = 4;
    8682      //
    87       // batchRunsTabPage
    88       //
    89       this.batchRunsTabPage.Controls.Add(this.batchRunListView);
    90       this.batchRunsTabPage.Location = new System.Drawing.Point(4, 22);
    91       this.batchRunsTabPage.Name = "batchRunsTabPage";
    92       this.batchRunsTabPage.Padding = new System.Windows.Forms.Padding(3);
    93       this.batchRunsTabPage.Size = new System.Drawing.Size(671, 374);
    94       this.batchRunsTabPage.TabIndex = 1;
    95       this.batchRunsTabPage.Text = "Batch Runs";
    96       this.batchRunsTabPage.UseVisualStyleBackColor = true;
    97       //
    98       // resultsTabPage
    99       //
    100       this.resultsTabPage.Controls.Add(this.runsView);
    101       this.resultsTabPage.Location = new System.Drawing.Point(4, 22);
    102       this.resultsTabPage.Name = "resultsTabPage";
    103       this.resultsTabPage.Padding = new System.Windows.Forms.Padding(3);
    104       this.resultsTabPage.Size = new System.Drawing.Size(671, 374);
    105       this.resultsTabPage.TabIndex = 2;
    106       this.resultsTabPage.Text = "Results";
    107       this.resultsTabPage.UseVisualStyleBackColor = true;
    108       //
    109       // runsView
    110       //
    111       this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    112                   | System.Windows.Forms.AnchorStyles.Left)
    113                   | System.Windows.Forms.AnchorStyles.Right)));
    114       this.runsView.Caption = "RunCollection";
    115       this.runsView.Content = null;
    116       this.runsView.Location = new System.Drawing.Point(6, 6);
    117       this.runsView.Name = "runsView";
    118       this.runsView.Size = new System.Drawing.Size(659, 362);
    119       this.runsView.TabIndex = 0;
     83      // optimizersTabPage
     84      //
     85      this.optimizersTabPage.Controls.Add(this.optimizerListView);
     86      this.optimizersTabPage.Location = new System.Drawing.Point(4, 22);
     87      this.optimizersTabPage.Name = "optimizersTabPage";
     88      this.optimizersTabPage.Padding = new System.Windows.Forms.Padding(3);
     89      this.optimizersTabPage.Size = new System.Drawing.Size(671, 374);
     90      this.optimizersTabPage.TabIndex = 1;
     91      this.optimizersTabPage.Text = "Optimizers";
     92      this.optimizersTabPage.UseVisualStyleBackColor = true;
    12093      //
    12194      // startButton
     
    186159      this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click);
    187160      //
    188       // batchRunListView
    189       //
    190       this.batchRunListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     161      // optimizerListView
     162      //
     163      this.optimizerListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    191164                  | System.Windows.Forms.AnchorStyles.Left)
    192165                  | System.Windows.Forms.AnchorStyles.Right)));
    193       this.batchRunListView.Caption = "BatchRunList";
    194       this.batchRunListView.Content = null;
    195       this.batchRunListView.Location = new System.Drawing.Point(6, 6);
    196       this.batchRunListView.Name = "batchRunListView";
    197       this.batchRunListView.Size = new System.Drawing.Size(659, 362);
    198       this.batchRunListView.TabIndex = 0;
     166      this.optimizerListView.Caption = "OptimizerList";
     167      this.optimizerListView.Content = null;
     168      this.optimizerListView.Location = new System.Drawing.Point(6, 6);
     169      this.optimizerListView.Name = "optimizerListView";
     170      this.optimizerListView.Size = new System.Drawing.Size(659, 362);
     171      this.optimizerListView.TabIndex = 0;
    199172      //
    200173      // ExperimentView
     
    224197      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    225198      this.tabControl.ResumeLayout(false);
    226       this.batchRunsTabPage.ResumeLayout(false);
    227       this.resultsTabPage.ResumeLayout(false);
     199      this.optimizersTabPage.ResumeLayout(false);
    228200      this.ResumeLayout(false);
    229201      this.PerformLayout();
     
    233205
    234206    private System.Windows.Forms.TabControl tabControl;
    235     private System.Windows.Forms.TabPage batchRunsTabPage;
     207    private System.Windows.Forms.TabPage optimizersTabPage;
    236208    private System.Windows.Forms.Button startButton;
    237209    private System.Windows.Forms.Button stopButton;
     
    239211    private System.Windows.Forms.Label executionTimeLabel;
    240212    private System.Windows.Forms.TextBox executionTimeTextBox;
    241     private System.Windows.Forms.TabPage resultsTabPage;
    242     private RunCollectionView runsView;
    243213    private System.Windows.Forms.Button pauseButton;
    244     private BatchRunListView batchRunListView;
     214    private OptimizerListView optimizerListView;
    245215
    246216  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.cs

    r3267 r3274  
    7070      base.OnContentChanged();
    7171      if (Content == null) {
    72         batchRunListView.Content = null;
    73         runsView.Content = null;
     72        optimizerListView.Content = null;
    7473        tabControl.Enabled = false;
    7574        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
     
    7776        executionTimeTextBox.Enabled = false;
    7877      } else {
    79         batchRunListView.Content = Content.BatchRuns;
    80         runsView.Content = Content.Runs;
     78        optimizerListView.Content = Content.Optimizers;
    8179        tabControl.Enabled = true;
    8280        EnableDisableButtons();
     
    127125    }
    128126    private void resetButton_Click(object sender, EventArgs e) {
    129       if (Content.Runs.Count > 0) {
    130         if (MessageBox.Show(this, "Clear all runs executed so far?", "Clear All Runs?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
    131           Content.Prepare(true);
    132         else
    133           Content.Prepare(false);
    134       } else {
    135         Content.Prepare();
    136       }
     127      if (MessageBox.Show(this, "Clear all runs executed so far?", "Clear All Runs?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     128        Content.Prepare(true);
     129      else
     130        Content.Prepare(false);
    137131    }
    138132    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r3267 r3274  
    9898      <DependentUpon>BatchRunView.cs</DependentUpon>
    9999    </Compile>
    100     <Compile Include="BatchRunListView.cs">
    101       <SubType>UserControl</SubType>
    102     </Compile>
    103     <Compile Include="BatchRunListView.Designer.cs">
    104       <DependentUpon>BatchRunListView.cs</DependentUpon>
     100    <Compile Include="OptimizerListView.cs">
     101      <SubType>UserControl</SubType>
     102    </Compile>
     103    <Compile Include="OptimizerListView.Designer.cs">
     104      <DependentUpon>OptimizerListView.cs</DependentUpon>
    105105    </Compile>
    106106    <Compile Include="ExperimentView.cs">
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ResultCollectionView.cs

    r3226 r3274  
    2121
    2222using HeuristicLab.Collections;
     23using HeuristicLab.Core;
    2324using HeuristicLab.Core.Views;
    2425using HeuristicLab.MainForm;
     
    5051    protected override IResult CreateItem() {
    5152      IResult item = new Result();
    52       item.Name = GetUniqueName(item.Name);
     53      if (Content.ContainsKey(item.Name))
     54        item = new Result(GetUniqueName(item.Name), typeof(IItem));
    5355      return item;
    5456    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r3260 r3274  
    2020#endregion
    2121
     22using HeuristicLab.Collections;
    2223using HeuristicLab.Core.Views;
    2324using HeuristicLab.MainForm;
     
    2627  [View("RunCollection View")]
    2728  [Content(typeof(RunCollection), true)]
     29  [Content(typeof(IObservableCollection<Run>), false)]
    2830  public partial class RunCollectionView : ItemCollectionView<Run> {
    2931    /// <summary>
     
    4143    /// <remarks>Calls <see cref="VariablesScopeView()"/>.</remarks>
    4244    /// <param name="scope">The scope whose variables should be represented visually.</param>
    43     public RunCollectionView(RunCollection content)
     45    public RunCollectionView(IObservableCollection<Run> content)
    4446      : this() {
    4547      Content = content;
     
    4749
    4850    protected override Run CreateItem() {
    49       return null;
     51      return new Run();
    5052    }
    5153  }
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r3262 r3274  
    124124    }
    125125
    126     public virtual void Prepare() {
     126    public void Prepare() {
     127      Prepare(true);
     128    }
     129    public virtual void Prepare(bool clearResults) {
    127130      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    128131        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3265 r3274  
    3333  [Creatable("Testing & Analysis")]
    3434  [StorableClass]
    35   public sealed class BatchRun : NamedItem, IExecutable {
     35  public sealed class BatchRun : NamedItem, IOptimizer {
    3636    public override Image ItemImage {
    3737      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event; }
     
    147147      Prepare(true);
    148148    }
    149     public void Prepare(bool clearRuns) {
     149    public void Prepare(bool clearResults) {
    150150      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    151151        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    152152      if (Algorithm != null) {
    153         if (clearRuns) {
     153        if (clearResults) {
    154154          ExecutionTime = TimeSpan.Zero;
    155155          runs.Clear();
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3262 r3274  
    2222using System;
    2323using System.Linq;
    24 using HeuristicLab.Collections;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    158157    }
    159158
    160     public override void Prepare() {
    161       base.Prepare();
     159    public override void Prepare(bool clearResults) {
     160      base.Prepare(clearResults);
     161
     162      ResultCollection results = Results;
    162163      globalScope.Clear();
    163       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     164      if (clearResults)
     165        globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     166      else
     167        globalScope.Variables.Add(new Variable("Results", results));
    164168
    165169      if (engine != null) {
  • trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs

    r3267 r3274  
    3535  [Creatable("Testing & Analysis")]
    3636  [StorableClass]
    37   public sealed class Experiment : NamedItem, IExecutable {
     37  public sealed class Experiment : NamedItem, IOptimizer {
    3838    public override Image ItemImage {
    3939      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event; }
     
    6262    }
    6363
    64     private BatchRunList batchRuns;
     64    private OptimizerList optimizers;
    6565    [Storable]
    66     public BatchRunList BatchRuns {
    67       get { return batchRuns; }
     66    public OptimizerList Optimizers {
     67      get { return optimizers; }
    6868      private set {
    69         if (batchRuns != value) {
    70           if (batchRuns != null) DeregisterBatchRunsEvents();
    71           batchRuns = value;
    72           if (batchRuns != null) RegisterBatchRunsEvents();
    73           foreach (BatchRun batchRun in batchRuns)
    74             RegisterBatchRunEvents(batchRun);
     69        if (optimizers != value) {
     70          if (optimizers != null) DeregisterOptimizersEvents();
     71          optimizers = value;
     72          if (optimizers != null) RegisterOptimizersEvents();
     73          foreach (IOptimizer optimizer in optimizers)
     74            RegisterOptimizerEvents(optimizer);
    7575        }
    7676      }
    77     }
    78 
    79     [Storable]
    80     private RunCollection runs;
    81     public RunCollection Runs {
    82       get { return runs; }
    8377    }
    8478
     
    8983      executionState = ExecutionState.Stopped;
    9084      executionTime = TimeSpan.Zero;
    91       BatchRuns = new BatchRunList();
    92       runs = new RunCollection();
     85      Optimizers = new OptimizerList();
    9386      stopPending = false;
    9487    }
     
    9689      executionState = ExecutionState.Stopped;
    9790      executionTime = TimeSpan.Zero;
    98       BatchRuns = new BatchRunList();
    99       runs = new RunCollection();
     91      Optimizers = new OptimizerList();
    10092      stopPending = false;
    10193    }
     
    10395      executionState = ExecutionState.Stopped;
    10496      executionTime = TimeSpan.Zero;
    105       BatchRuns = new BatchRunList();
    106       runs = new RunCollection();
     97      Optimizers = new OptimizerList();
    10798      stopPending = false;
    10899    }
     
    112103      clone.executionState = executionState;
    113104      clone.executionTime = executionTime;
    114       clone.BatchRuns = (BatchRunList)cloner.Clone(batchRuns);
    115       clone.runs = (RunCollection)cloner.Clone(runs);
     105      clone.Optimizers = (OptimizerList)cloner.Clone(optimizers);
    116106      clone.stopPending = stopPending;
    117107      return clone;
     
    121111      Prepare(true);
    122112    }
    123     public void Prepare(bool clearRuns) {
     113    public void Prepare(bool clearResults) {
    124114      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    125115        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    126       if (BatchRuns.Count > 0) {
    127         if (clearRuns) {
    128           ExecutionTime = TimeSpan.Zero;
    129           runs.Clear();
    130         }
    131         foreach (BatchRun batchRun in BatchRuns.Where(x => x.ExecutionState != ExecutionState.Started))
    132           batchRun.Prepare(clearRuns);
     116      if (Optimizers.Count > 0) {
     117        foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started))
     118          optimizer.Prepare(clearResults);
    133119      }
    134120    }
     
    137123        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
    138124      stopPending = false;
    139       if (BatchRuns.Count > 0) {
    140         BatchRun batchRun = BatchRuns.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
    141         if (batchRun != null) batchRun.Start();
     125      if (Optimizers.Count > 0) {
     126        IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
     127        if (optimizer != null) optimizer.Start();
    142128      }
    143129    }
     
    145131      if (ExecutionState != ExecutionState.Started)
    146132        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
    147       if (BatchRuns.Count > 0) {
    148         foreach (BatchRun batchRun in BatchRuns.Where(x => x.ExecutionState == ExecutionState.Started))
    149           batchRun.Pause();
     133      if (Optimizers.Count > 0) {
     134        foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started))
     135          optimizer.Pause();
    150136      }
    151137    }
     
    154140        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
    155141      stopPending = true;
    156       if (BatchRuns.Count > 0) {
    157         foreach (BatchRun batchRun in BatchRuns.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused)))
    158           batchRun.Stop();
     142      if (Optimizers.Count > 0) {
     143        foreach (IOptimizer optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused)))
     144          optimizer.Stop();
    159145      }
    160146    }
     
    201187    }
    202188
    203     private void RegisterBatchRunsEvents() {
    204       BatchRuns.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_CollectionReset);
    205       BatchRuns.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsAdded);
    206       BatchRuns.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsRemoved);
    207       BatchRuns.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsReplaced);
    208     }
    209     private void DeregisterBatchRunsEvents() {
    210       BatchRuns.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_CollectionReset);
    211       BatchRuns.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsAdded);
    212       BatchRuns.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsRemoved);
    213       BatchRuns.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<BatchRun>>(BatchRuns_ItemsReplaced);
    214     }
    215     private void BatchRuns_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<BatchRun>> e) {
    216       foreach (IndexedItem<BatchRun> item in e.OldItems) {
    217         DeregisterBatchRunEvents(item.Value);
    218       }
    219       foreach (IndexedItem<BatchRun> item in e.Items) {
    220         RegisterBatchRunEvents(item.Value);
    221       }
    222     }
    223     private void BatchRuns_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<BatchRun>> e) {
    224       foreach (IndexedItem<BatchRun> item in e.Items) {
    225         RegisterBatchRunEvents(item.Value);
    226       }
    227     }
    228     private void BatchRuns_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<BatchRun>> e) {
    229       foreach (IndexedItem<BatchRun> item in e.Items) {
    230         DeregisterBatchRunEvents(item.Value);
    231       }
    232     }
    233     private void BatchRuns_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<BatchRun>> e) {
    234       foreach (IndexedItem<BatchRun> item in e.OldItems) {
    235         DeregisterBatchRunEvents(item.Value);
    236       }
    237       foreach (IndexedItem<BatchRun> item in e.Items) {
    238         RegisterBatchRunEvents(item.Value);
    239       }
    240     }
    241 
    242     private void RegisterBatchRunEvents(BatchRun batchRun) {
    243       batchRun.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(batchRun_ExceptionOccurred);
    244       batchRun.Paused += new EventHandler(batchRun_Paused);
    245       batchRun.Prepared += new EventHandler(batchRun_Prepared);
    246       batchRun.Started += new EventHandler(batchRun_Started);
    247       batchRun.Stopped += new EventHandler(batchRun_Stopped);
    248     }
    249     private void DeregisterBatchRunEvents(BatchRun batchRun) {
    250       batchRun.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(batchRun_ExceptionOccurred);
    251       batchRun.Paused -= new EventHandler(batchRun_Paused);
    252       batchRun.Prepared -= new EventHandler(batchRun_Prepared);
    253       batchRun.Started -= new EventHandler(batchRun_Started);
    254       batchRun.Stopped -= new EventHandler(batchRun_Stopped);
    255     }
    256     private void batchRun_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     189    private void RegisterOptimizersEvents() {
     190      Optimizers.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
     191      Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
     192      Optimizers.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
     193      Optimizers.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
     194    }
     195    private void DeregisterOptimizersEvents() {
     196      Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
     197      Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
     198      Optimizers.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
     199      Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
     200    }
     201    private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
     202      foreach (IndexedItem<IOptimizer> item in e.OldItems) {
     203        DeregisterOptimizerEvents(item.Value);
     204      }
     205      foreach (IndexedItem<IOptimizer> item in e.Items) {
     206        RegisterOptimizerEvents(item.Value);
     207      }
     208    }
     209    private void Optimizers_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
     210      foreach (IndexedItem<IOptimizer> item in e.Items) {
     211        RegisterOptimizerEvents(item.Value);
     212      }
     213    }
     214    private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
     215      foreach (IndexedItem<IOptimizer> item in e.Items) {
     216        DeregisterOptimizerEvents(item.Value);
     217      }
     218    }
     219    private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
     220      foreach (IndexedItem<IOptimizer> item in e.OldItems) {
     221        DeregisterOptimizerEvents(item.Value);
     222      }
     223      foreach (IndexedItem<IOptimizer> item in e.Items) {
     224        RegisterOptimizerEvents(item.Value);
     225      }
     226    }
     227
     228    private void RegisterOptimizerEvents(IOptimizer optimizer) {
     229      optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
     230      optimizer.ExecutionTimeChanged += new EventHandler(optimizer_ExecutionTimeChanged);
     231      optimizer.Paused += new EventHandler(optimizer_Paused);
     232      optimizer.Prepared += new EventHandler(optimizer_Prepared);
     233      optimizer.Started += new EventHandler(optimizer_Started);
     234      optimizer.Stopped += new EventHandler(optimizer_Stopped);
     235    }
     236
     237    private void DeregisterOptimizerEvents(IOptimizer optimizer) {
     238      optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
     239      optimizer.ExecutionTimeChanged -= new EventHandler(optimizer_ExecutionTimeChanged);
     240      optimizer.Paused -= new EventHandler(optimizer_Paused);
     241      optimizer.Prepared -= new EventHandler(optimizer_Prepared);
     242      optimizer.Started -= new EventHandler(optimizer_Started);
     243      optimizer.Stopped -= new EventHandler(optimizer_Stopped);
     244    }
     245    private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    257246      OnExceptionOccurred(e.Value);
    258247    }
    259     private void batchRun_Paused(object sender, EventArgs e) {
    260       if (BatchRuns.All(x => x.ExecutionState != ExecutionState.Started))
     248    private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
     249      ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
     250    }
     251    private void optimizer_Paused(object sender, EventArgs e) {
     252      if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started))
    261253        OnPaused();
    262254    }
    263     void batchRun_Prepared(object sender, EventArgs e) {
     255    private void optimizer_Prepared(object sender, EventArgs e) {
    264256      if (ExecutionState == ExecutionState.Stopped)
    265257        OnPrepared();
    266258    }
    267     private void batchRun_Started(object sender, EventArgs e) {
     259    private void optimizer_Started(object sender, EventArgs e) {
    268260      if (ExecutionState != ExecutionState.Started)
    269261        OnStarted();
    270262    }
    271     private void batchRun_Stopped(object sender, EventArgs e) {
     263    private void optimizer_Stopped(object sender, EventArgs e) {
    272264      bool stop = stopPending;
    273       BatchRun batchRun = (BatchRun)sender;
    274       ExecutionTime += batchRun.ExecutionTime;
    275       runs.AddRange(batchRun.Runs);
    276 
    277       if (BatchRuns.All(x => (x.ExecutionState != ExecutionState.Started) && (x.ExecutionState != ExecutionState.Paused))) {
     265
     266      if (Optimizers.All(x => (x.ExecutionState != ExecutionState.Started) && (x.ExecutionState != ExecutionState.Paused))) {
    278267        stopPending = false;
    279268        OnStopped();
     
    281270
    282271      if (!stop) {
    283         BatchRun next = BatchRuns.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
     272        IOptimizer next = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
    284273        if (next != null)
    285274          next.Start();
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3267 r3274  
    8787    <Compile Include="Algorithm.cs" />
    8888    <Compile Include="BatchRun.cs" />
    89     <Compile Include="BatchRunList.cs" />
     89    <Compile Include="OptimizerList.cs" />
    9090    <Compile Include="Experiment.cs" />
     91    <Compile Include="Interfaces\IOptimizer.cs" />
    9192    <Compile Include="RunCollection.cs" />
    9293    <Compile Include="Run.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IAlgorithm.cs

    r3262 r3274  
    2222using System;
    2323using System.Collections.Generic;
    24 using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    2625
     
    2928  /// Interface to represent an algorithm.
    3029  /// </summary>
    31   public interface IAlgorithm : IParameterizedNamedItem, IExecutable {
     30  public interface IAlgorithm : IParameterizedNamedItem, IOptimizer {
    3231    Type ProblemType { get; }
    3332    IProblem Problem { get; set; }
  • trunk/sources/HeuristicLab.Optimization/3.3/ResultCollection.cs

    r3226 r3274  
    2828  [StorableClass]
    2929  [Item("ResultCollection", "Represents a collection of results.")]
    30   public sealed class ResultCollection : NamedItemCollection<IResult> {
     30  public class ResultCollection : NamedItemCollection<IResult> {
    3131    public ResultCollection() : base() { }
    3232    public ResultCollection(int capacity) : base(capacity) { }
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3260 r3274  
    2828  [StorableClass]
    2929  [Item("RunCollection", "Represents a collection of runs.")]
    30   public sealed class RunCollection : ItemCollection<Run> {
     30  public class RunCollection : ItemCollection<Run> {
    3131    public RunCollection() : base() { }
    3232    public RunCollection(int capacity) : base(capacity) { }
Note: See TracChangeset for help on using the changeset viewer.