Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4542


Ignore:
Timestamp:
09/30/10 14:35:21 (14 years ago)
Author:
mkommend
Message:

Added persistence, cloning to CrossValidation (ticket #1199)

Location:
branches/HeuristicLab.Classification
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.Designer.cs

    r4536 r4542  
    7373      this.openAlgorithmButton = new System.Windows.Forms.Button();
    7474      this.newAlgorithmButton = new System.Windows.Forms.Button();
    75       this.workerTabPage = new System.Windows.Forms.TabPage();
     75      this.foldsTabPage = new System.Windows.Forms.TabPage();
    7676      this.algorithmResultsCollectionView = new HeuristicLab.Algorithms.DataAnalysis.Views.AlgorithmResultsCollectionView();
    7777      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
     
    8484      this.algorithmProblemTabPage.SuspendLayout();
    8585      this.algorithmParametersTabPage.SuspendLayout();
    86       this.workerTabPage.SuspendLayout();
     86      this.foldsTabPage.SuspendLayout();
    8787      this.SuspendLayout();
    8888      //
     
    284284                  | System.Windows.Forms.AnchorStyles.Right)));
    285285      this.tabControl.Controls.Add(this.algorithmTabPage);
    286       this.tabControl.Controls.Add(this.workerTabPage);
     286      this.tabControl.Controls.Add(this.foldsTabPage);
    287287      this.tabControl.Location = new System.Drawing.Point(0, 157);
    288288      this.tabControl.Name = "tabControl";
     
    431431      this.newAlgorithmButton.Click += new System.EventHandler(this.newAlgorithmButton_Click);
    432432      //
    433       // workerTabPage
    434       //
    435       this.workerTabPage.Controls.Add(this.algorithmResultsCollectionView);
    436       this.workerTabPage.Location = new System.Drawing.Point(4, 22);
    437       this.workerTabPage.Name = "workerTabPage";
    438       this.workerTabPage.Padding = new System.Windows.Forms.Padding(3);
    439       this.workerTabPage.Size = new System.Drawing.Size(649, 325);
    440       this.workerTabPage.TabIndex = 1;
    441       this.workerTabPage.Text = "Worker";
    442       this.workerTabPage.UseVisualStyleBackColor = true;
     433      // foldsTabPage
     434      //
     435      this.foldsTabPage.Controls.Add(this.algorithmResultsCollectionView);
     436      this.foldsTabPage.Location = new System.Drawing.Point(4, 22);
     437      this.foldsTabPage.Name = "foldsTabPage";
     438      this.foldsTabPage.Padding = new System.Windows.Forms.Padding(3);
     439      this.foldsTabPage.Size = new System.Drawing.Size(649, 325);
     440      this.foldsTabPage.TabIndex = 1;
     441      this.foldsTabPage.Text = "Folds";
     442      this.foldsTabPage.UseVisualStyleBackColor = true;
    443443      //
    444444      // algorithmResultsCollectionView
     
    508508      this.algorithmProblemTabPage.ResumeLayout(false);
    509509      this.algorithmParametersTabPage.ResumeLayout(false);
    510       this.workerTabPage.ResumeLayout(false);
     510      this.foldsTabPage.ResumeLayout(false);
    511511      this.ResumeLayout(false);
    512512      this.PerformLayout();
     
    533533    private System.Windows.Forms.TabControl tabControl;
    534534    private System.Windows.Forms.TabPage algorithmTabPage;
    535     private System.Windows.Forms.TabPage workerTabPage;
     535    private System.Windows.Forms.TabPage foldsTabPage;
    536536    private System.Windows.Forms.Button openAlgorithmButton;
    537537    private System.Windows.Forms.Button newAlgorithmButton;
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.cs

    r4536 r4542  
    3131
    3232namespace HeuristicLab.Algorithms.DataAnalysis.Views {
     33  [View("Cross Validation View")]
    3334  [Content(typeof(CrossValidation), true)]
    34   public partial class CrossValidationView : NamedItemView {
     35  public sealed partial class CrossValidationView : NamedItemView {
    3536    private TypeSelectorDialog algorithmTypeSelectorDialog;
    3637    private TypeSelectorDialog problemTypeSelectorDialog;
     
    3839    public CrossValidationView() {
    3940      InitializeComponent();
     41      workersNumericUpDown.Maximum = Environment.ProcessorCount * 2;
    4042    }
    4143
     
    5759        algorithmResultsCollectionView.Content = null;
    5860      } else {
     61        Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
    5962        workersNumericUpDown.Value = Content.NumberOfWorkers.Value;
    6063        foldsNumericUpDown.Value = Content.Folds.Value;
     
    7881      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
    7982      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    80       Content.Prepared += new EventHandler(Content_Prepared);
    81       Content.Started += new EventHandler(Content_Started);
    82       Content.Paused += new EventHandler(Content_Paused);
    83       Content.Stopped += new EventHandler(Content_Stopped);
    8483    }
    8584
     
    9392      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
    9493      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
    95       Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    96       Content.Prepared -= new EventHandler(Content_Prepared);
    97       Content.Started -= new EventHandler(Content_Started);
    98       Content.Paused -= new EventHandler(Content_Paused);
    99       Content.Stopped -= new EventHandler(Content_Stopped);
     94      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    10095    }
    10196
     
    111106          samplesEndStringConvertibleValueView.Enabled = Content.Problem != null;
    112107        }
     108        SetEnabledStateOfExecutableButtons();
     109      }
     110    }
     111    private void SetEnabledStateOfExecutableButtons() {
     112      if (Content == null) {
     113        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
     114        foldsNumericUpDown.Enabled = workersNumericUpDown.Enabled = false;
     115        samplesStartStringConvertibleValueView.Enabled = samplesEndStringConvertibleValueView.Enabled = false;
     116      } else {
     117        startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
     118        pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
     119        stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
     120        resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
     121        foldsNumericUpDown.Enabled = Content.ExecutionState == ExecutionState.Prepared;
     122        samplesStartStringConvertibleValueView.Enabled = Content.ExecutionState == ExecutionState.Prepared;
     123        samplesEndStringConvertibleValueView.Enabled = Content.ExecutionState == ExecutionState.Prepared;
     124        workersNumericUpDown.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
    113125      }
    114126    }
     
    145157      if (InvokeRequired)
    146158        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    147       else
    148         startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    149     }
    150     private void Content_Prepared(object sender, EventArgs e) {
    151       if (InvokeRequired)
    152         Invoke(new EventHandler(Content_Prepared), sender, e);
    153159      else {
    154         ReadOnly = Locked = false;
     160        Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
    155161        SetEnabledStateOfExecutableButtons();
    156162      }
    157163    }
    158     private void Content_Started(object sender, EventArgs e) {
    159       if (InvokeRequired)
    160         Invoke(new EventHandler(Content_Started), sender, e);
    161       else {
    162         ReadOnly = Locked = true;
    163         SetEnabledStateOfExecutableButtons();
    164       }
    165     }
    166     private void Content_Paused(object sender, EventArgs e) {
    167       if (InvokeRequired)
    168         Invoke(new EventHandler(Content_Paused), sender, e);
    169       else {
    170         ReadOnly = Locked = false;
    171         SetEnabledStateOfExecutableButtons();
    172       }
    173     }
    174     private void Content_Stopped(object sender, EventArgs e) {
    175       if (InvokeRequired)
    176         Invoke(new EventHandler(Content_Stopped), sender, e);
    177       else {
    178         ReadOnly = Locked = false;
    179         SetEnabledStateOfExecutableButtons();
    180       }
    181     }
     164
    182165    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    183166      if (InvokeRequired)
     
    296279            if (error != null) throw error;
    297280            IDataAnalysisProblem problem = content as IDataAnalysisProblem;
    298             if (problem == null)
     281            if (problem == null && (Content.Algorithm.ProblemType.IsAssignableFrom(content.GetType())))
    299282              Invoke(new Action(() =>
    300283                MessageBox.Show(this, "The selected file does not contain a DataAnalysisProblem problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error)));
     
    336319    }
    337320
    338     protected virtual void algorithmProblemTabPage_DragEnterOver(object sender, DragEventArgs e) {
     321    private void algorithmProblemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    339322      e.Effect = DragDropEffects.None;
    340323      Type type = e.Data.GetData("Type") as Type;
    341       if ((type != null) && (typeof(IDataAnalysisProblem).IsAssignableFrom(type))) {
     324      if ((type != null) && (typeof(IDataAnalysisProblem).IsAssignableFrom(type)) &&
     325        (Content.Algorithm.ProblemType.IsAssignableFrom(type))) {
    342326        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    343327        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     
    347331      }
    348332    }
    349     protected virtual void algorithmProblemTabPage_DragDrop(object sender, DragEventArgs e) {
     333    private void algorithmProblemTabPage_DragDrop(object sender, DragEventArgs e) {
    350334      if (e.Effect != DragDropEffects.None) {
    351335        IDataAnalysisProblem problem = e.Data.GetData("Value") as IDataAnalysisProblem;
     
    355339    }
    356340    #endregion
    357 
    358     #region Helpers
    359     private void SetEnabledStateOfExecutableButtons() {
    360       if (Content == null) {
    361         startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    362       } else {
    363         startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
    364         pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
    365         stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
    366         resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
    367       }
    368     }
    369     #endregion
    370341  }
    371342}
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.resx

    r4536 r4542  
    121121    <value>107, 17</value>
    122122  </metadata>
    123   <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124     <value>107, 17</value>
    125   </metadata>
    126123  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    127124    <value>17, 17</value>
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/HeuristicLabAlgorithmsDataAnalysisViewsPlugin.cs.frame

    r4472 r4542  
    2626  /// Plugin class for HeuristicLab.Algorithms.DataAnalysis.Views plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Algorithms.DataAnalysis.Views", "3.3.0.$WCREV$")]
     28  [Plugin("HeuristicLab.Algorithms.DataAnalysis.Views", "3.3.1.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Algorithms.DataAnalysis.Views-3.3.dll", PluginFileType.Assembly)]
    3030  public class HeuristicLabAlgorithmsDataAnalysisViewsPlugin : PluginBase {
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/Properties/AssemblyInfo.frame

    r4472 r4542  
    5252// You can specify all the values or you can default the Revision and Build Numbers
    5353// by using the '*' as shown below:
    54 [assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
     54[assembly: AssemblyVersion("3.3.1.0")]
     55[assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/CrossValidation.cs

    r4536 r4542  
    3636  [StorableClass]
    3737  public sealed class CrossValidation : NamedItem, IOptimizer {
    38     //TODO cloning, persistence, creation of clonedAlgs, execution logic, ...
    3938    public CrossValidation()
    4039      : base() {
     
    4443      executionState = ExecutionState.Stopped;
    4544      executionTime = TimeSpan.Zero;
    46       Runs = new RunCollection();
     45      runs = new RunCollection();
    4746
    4847      algorithm = null;
    4948      clonedAlgorithms = new ItemCollection<IAlgorithm>();
    50       RegisterClonedAlgorithmEvents();
    5149      readOnlyClonedAlgorithms = null;
    5250
    5351      folds = new IntValue(1);
     52      numberOfWorkers = new IntValue(1);
    5453      samplesStart = new IntValue(0);
    5554      samplesEnd = new IntValue(0);
    56       numberOfWorkers = new IntValue(1);
    57     }
     55
     56
     57      RegisterEvents();
     58    }
     59
     60    #region persistence and cloning
     61    [StorableConstructor]
     62    private CrossValidation(bool deserializing)
     63      : base(deserializing) {
     64    }
     65    [StorableHook(HookType.AfterDeserialization)]
     66    private void AfterDeserialization() {
     67      RegisterEvents();
     68    }
     69
     70    public override IDeepCloneable Clone(Cloner cloner) {
     71      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
     72      CrossValidation clone = new CrossValidation(false);
     73      cloner.RegisterClonedObject(this, clone);
     74      clone.name = name;
     75      clone.description = description;
     76      clone.executionState = executionState;
     77      clone.executionTime = executionTime;
     78      clone.runs = (RunCollection)cloner.Clone(runs);
     79      clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
     80      clone.clonedAlgorithms = (ItemCollection<IAlgorithm>)cloner.Clone(clonedAlgorithms);
     81      clone.folds = (IntValue)cloner.Clone(folds);
     82      clone.numberOfWorkers = (IntValue)cloner.Clone(numberOfWorkers);
     83      clone.samplesStart = (IntValue)cloner.Clone(samplesStart);
     84      clone.samplesEnd = (IntValue)cloner.Clone(samplesEnd);
     85      clone.RegisterEvents();
     86      return clone;
     87    }
     88
     89    #endregion
    5890
    5991    #region properties
     92    [Storable]
    6093    private IAlgorithm algorithm;
    6194    public IAlgorithm Algorithm {
    6295      get { return algorithm; }
    6396      set {
     97        if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped)
     98          throw new InvalidOperationException("Changing the algorithm is only allowed if the CrossValidation is stopped or prepared.");
    6499        if (algorithm != value) {
    65100          if (value != null && value.Problem != null && !(value.Problem is IDataAnalysisProblem))
     
    67102          if (algorithm != null) DeregisterAlgorithmEvents();
    68103          algorithm = value;
    69           algorithm.Prepare(true);
    70           if (algorithm != null) RegisterAlgorithmEvents();
     104
     105          if (algorithm != null) {
     106            RegisterAlgorithmEvents();
     107            algorithm.Prepare(true);
     108          }
    71109          OnAlgorithmChanged();
    72         }
    73       }
    74     }
     110          Prepare();
     111        }
     112      }
     113    }
     114
     115    [Storable]
    75116    private IDataAnalysisProblem cachedProblem;
    76117    public IDataAnalysisProblem Problem {
     
    81122      }
    82123      set {
     124        if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped)
     125          throw new InvalidOperationException("Changing the problem is only allowed if the CrossValidation is stopped or prepared.");
    83126        if (algorithm == null) throw new ArgumentNullException("Could not set a problem before an algorithm was set.");
    84127        algorithm.Problem = value;
     
    87130    }
    88131
     132    [Storable]
    89133    private ItemCollection<IAlgorithm> clonedAlgorithms;
    90134    private ReadOnlyItemCollection<IAlgorithm> readOnlyClonedAlgorithms;
     
    96140    }
    97141
     142    [Storable]
    98143    private IntValue folds;
    99144    public IntValue Folds {
    100145      get { return folds; }
    101146    }
     147    [Storable]
    102148    private IntValue samplesStart;
    103149    public IntValue SamplesStart {
    104150      get { return samplesStart; }
    105151    }
     152    [Storable]
    106153    private IntValue samplesEnd;
    107154    public IntValue SamplesEnd {
    108155      get { return samplesEnd; }
    109156    }
     157    [Storable]
    110158    private IntValue numberOfWorkers;
    111159    public IntValue NumberOfWorkers {
     
    113161    }
    114162
     163    [Storable]
    115164    private RunCollection runs;
    116165    public RunCollection Runs {
    117166      get { return runs; }
    118       private set {
    119         if (value == null) throw new ArgumentNullException();
    120         if (runs != value) {
    121           if (runs != null) DeregisterRunsEvents();
    122           runs = value;
    123           if (runs != null) RegisterRunsEvents();
    124         }
    125       }
    126     }
     167    }
     168    [Storable]
    127169    private ExecutionState executionState;
    128170    public ExecutionState ExecutionState {
     
    146188    }
    147189
     190    [Storable]
    148191    private TimeSpan executionTime;
    149192    public TimeSpan ExecutionTime {
     
    162205
    163206    public void Prepare() {
     207      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
     208        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    164209      clonedAlgorithms.Clear();
    165       OnPrepared();
     210      if (Algorithm != null) {
     211        Algorithm.Prepare();
     212        if (Algorithm.ExecutionState == ExecutionState.Prepared) OnPrepared();
     213      }
    166214    }
    167215    public void Prepare(bool clearRuns) {
     
    169217      Prepare();
    170218    }
     219
     220    private bool startPending;
    171221    public void Start() {
    172       for (int i = 0; i < Folds.Value; i++) {
    173         IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone();
    174         clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
    175         clonedAlgorithms.Add(clonedAlgorithm);
    176       }
    177       for (int i = 0; i < NumberOfWorkers.Value && i < clonedAlgorithms.Count; i++)
    178         clonedAlgorithms.ElementAt(i).Start();
    179       OnStarted();
    180     }
     222      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
     223        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     224
     225      if (Algorithm != null && !startPending) {
     226        startPending = true;
     227        //create cloned algorithms
     228        if (clonedAlgorithms.Count == 0) {
     229          for (int i = 0; i < Folds.Value; i++) {
     230            IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone();
     231            clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
     232            clonedAlgorithms.Add(clonedAlgorithm);
     233          }
     234        }
     235
     236        //start prepared or paused cloned algorithms
     237        int startedAlgorithms = 0;
     238        foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) {
     239          if (startedAlgorithms < NumberOfWorkers.Value) {
     240            if (clonedAlgorithm.ExecutionState == ExecutionState.Prepared ||
     241                clonedAlgorithm.ExecutionState == ExecutionState.Paused) {
     242              clonedAlgorithm.Start();
     243              startedAlgorithms++;
     244            }
     245          }
     246        }
     247        OnStarted();
     248      }
     249    }
     250
     251    private bool pausePending;
    181252    public void Pause() {
    182       OnPaused();
    183     }
     253      if (ExecutionState != ExecutionState.Started)
     254        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
     255      if (!pausePending) {
     256        pausePending = true;
     257        if (!startPending) PauseAllClonedAlgorithms();
     258      }
     259    }
     260    private void PauseAllClonedAlgorithms() {
     261      foreach (IAlgorithm clonedAlgorithm in ClonedAlgorithms) {
     262        if (clonedAlgorithm.ExecutionState == ExecutionState.Started)
     263          clonedAlgorithm.Pause();
     264      }
     265    }
     266
     267    private bool stopPending;
    184268    public void Stop() {
    185       OnStopped();
     269      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
     270        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".",
     271                                                          ExecutionState));
     272      if (!stopPending) {
     273        stopPending = true;
     274        if (!startPending) StopAllClonedAlgorithms();
     275      }
     276    }
     277    private void StopAllClonedAlgorithms() {
     278      foreach (IAlgorithm clonedAlgorithm in ClonedAlgorithms) {
     279        if (clonedAlgorithm.ExecutionState == ExecutionState.Started ||
     280            clonedAlgorithm.ExecutionState == ExecutionState.Paused)
     281          clonedAlgorithm.Stop();
     282      }
    186283    }
    187284
    188285    #region events
     286    private void RegisterEvents() {
     287      Folds.ValueChanged += new EventHandler(Folds_ValueChanged);
     288      NumberOfWorkers.ValueChanged += new EventHandler(NumberOfWorkers_ValueChanged);
     289      RegisterClonedAlgorithmsEvents();
     290      RegisterRunsEvents();
     291    }
     292    private void Folds_ValueChanged(object sender, EventArgs e) {
     293      if (ExecutionState != ExecutionState.Prepared)
     294        throw new InvalidOperationException("Can not change number of folds if the execution state is not prepared.");
     295    }
     296    private void NumberOfWorkers_ValueChanged(object sender, EventArgs e) {
     297      if (ExecutionState == ExecutionState.Started) {
     298        int workers = numberOfWorkers.Value;
     299        int runningWorkers = clonedAlgorithms.Count(alg => alg.ExecutionState == ExecutionState.Started);
     300
     301        foreach (IAlgorithm algorithm in clonedAlgorithms) {
     302          if (algorithm.ExecutionState == ExecutionState.Prepared ||
     303              algorithm.ExecutionState == ExecutionState.Paused) {
     304            if (runningWorkers < workers) {
     305              algorithm.Start();
     306              runningWorkers++;
     307            }
     308          } else if (algorithm.ExecutionState == ExecutionState.Started) {
     309            if (runningWorkers > workers) {
     310              algorithm.Pause();
     311              runningWorkers--;
     312            }
     313          }
     314        }
     315      }
     316    }
     317
     318    #region template algorithms events
    189319    public event EventHandler AlgorithmChanged;
    190320    private void OnAlgorithmChanged() {
     
    192322      if (handler != null) handler(this, EventArgs.Empty);
    193323      OnProblemChanged();
     324      if (Problem == null) ExecutionState = ExecutionState.Stopped;
    194325    }
    195326    private void RegisterAlgorithmEvents() {
    196327      algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged);
     328      algorithm.ExecutionStateChanged += new EventHandler(Algorithm_ExecutionStateChanged);
    197329    }
    198330    private void DeregisterAlgorithmEvents() {
    199331      algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged);
     332      algorithm.ExecutionStateChanged -= new EventHandler(Algorithm_ExecutionStateChanged);
    200333    }
    201334    private void Algorithm_ProblemChanged(object sender, EventArgs e) {
     
    218351    }
    219352
    220     private void RegisterClonedAlgorithmEvents() {
     353    private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
     354      switch (Algorithm.ExecutionState) {
     355        case ExecutionState.Prepared: OnPrepared();
     356          break;
     357        case ExecutionState.Started: throw new InvalidOperationException("Algorithm template can not be started.");
     358        case ExecutionState.Paused: throw new InvalidOperationException("Algorithm template can not be paused.");
     359        case ExecutionState.Stopped: OnStopped();
     360          break;
     361      }
     362    }
     363    #endregion
     364
     365    #region clonedAlgorithms events
     366    private void RegisterClonedAlgorithmsEvents() {
    221367      clonedAlgorithms.ItemsAdded += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsAdded);
    222368      clonedAlgorithms.ItemsRemoved += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsRemoved);
    223369      clonedAlgorithms.CollectionReset += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_CollectionReset);
     370      foreach (IAlgorithm algorithm in clonedAlgorithms)
     371        RegisterClonedAlgorithmEvents(algorithm);
    224372    }
    225373    private void ClonedAlgorithms_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) {
     
    232380    }
    233381    private void ClonedAlgorithms_CollectionReset(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) {
     382      foreach (IAlgorithm algorithm in e.OldItems)
     383        DeregisterClonedAlgorithmEvents(algorithm);
    234384      foreach (IAlgorithm algorithm in e.Items)
    235385        RegisterClonedAlgorithmEvents(algorithm);
    236       foreach (IAlgorithm algorithm in e.OldItems)
    237         DeregisterClonedAlgorithmEvents(algorithm);
    238386    }
    239387    private void RegisterClonedAlgorithmEvents(IAlgorithm algorithm) {
    240       algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
    241       algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
    242       algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);
    243       algorithm.Paused += new EventHandler(Algorithm_Paused);
    244       algorithm.Stopped += new EventHandler(Algorithm_Stopped);
     388      algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred);
     389      algorithm.ExecutionTimeChanged += new EventHandler(ClonedAlgorithm_ExecutionTimeChanged);
     390      algorithm.Started += new EventHandler(ClonedAlgorithm_Started);
     391      algorithm.Paused += new EventHandler(ClonedAlgorithm_Paused);
     392      algorithm.Stopped += new EventHandler(ClonedAlgorithm_Stopped);
    245393    }
    246394    private void DeregisterClonedAlgorithmEvents(IAlgorithm algorithm) {
    247       algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
    248       algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
    249       algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);
    250       algorithm.Paused -= new EventHandler(Algorithm_Paused);
    251       algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
    252     }
    253     private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     395      algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred);
     396      algorithm.ExecutionTimeChanged -= new EventHandler(ClonedAlgorithm_ExecutionTimeChanged);
     397      algorithm.Started -= new EventHandler(ClonedAlgorithm_Started);
     398      algorithm.Paused -= new EventHandler(ClonedAlgorithm_Paused);
     399      algorithm.Stopped -= new EventHandler(ClonedAlgorithm_Stopped);
     400    }
     401    private void ClonedAlgorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    254402      OnExceptionOccurred(e.Value);
    255403    }
    256     private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
     404    private void ClonedAlgorithm_ExecutionTimeChanged(object sender, EventArgs e) {
    257405      OnExecutionTimeChanged();
    258406    }
    259     private void Algorithm_Runs_Added(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    260       throw new NotImplementedException("TODO added finished run to actual results if the cross validation is running");
    261     }
    262     private void Algorithm_Paused(object sender, EventArgs e) {
    263       throw new NotImplementedException("TODO pause the cross validation if an algorithm no algorithm is running.");
    264     }
    265     private void Algorithm_Stopped(object sender, EventArgs e) {
    266       throw new NotImplementedException("TODO stop the cross validation if all algorithms are stopped. and start remaining prepared algs");
    267     }
    268 
    269     public event EventHandler ExecutionStateChanged;
    270     private void OnExecutionStateChanged() {
    271       EventHandler handler = ExecutionStateChanged;
    272       if (handler != null) handler(this, EventArgs.Empty);
    273     }
    274     public event EventHandler ExecutionTimeChanged;
    275     private void OnExecutionTimeChanged() {
    276       EventHandler handler = ExecutionTimeChanged;
    277       if (handler != null) handler(this, EventArgs.Empty);
    278     }
    279     public event EventHandler Prepared;
    280     private void OnPrepared() {
    281       ExecutionState = ExecutionState.Prepared;
    282       EventHandler handler = Prepared;
    283       if (handler != null) handler(this, EventArgs.Empty);
    284     }
    285     public event EventHandler Started;
    286     private void OnStarted() {
    287       ExecutionState = ExecutionState.Started;
    288       EventHandler handler = Started;
    289       if (handler != null) handler(this, EventArgs.Empty);
    290     }
    291     public event EventHandler Paused;
    292     private void OnPaused() {
    293       ExecutionState = ExecutionState.Paused;
    294       EventHandler handler = Paused;
    295       if (handler != null) handler(this, EventArgs.Empty);
    296     }
    297     public event EventHandler Stopped;
    298     private void OnStopped() {
    299       ExecutionState = ExecutionState.Stopped;
    300       EventHandler handler = Stopped;
    301       if (handler != null) handler(this, EventArgs.Empty);
    302     }
    303     public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    304     private void OnExceptionOccurred(Exception exception) {
    305       EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
    306       if (handler != null) handler(this, new EventArgs<Exception>(exception));
    307     }
    308 
     407
     408    private readonly object locker = new object();
     409    private void ClonedAlgorithm_Started(object sender, EventArgs e) {
     410      lock (locker) {
     411        if (startPending) {
     412          int startedAlgorithms = clonedAlgorithms.Count(alg => alg.ExecutionState == ExecutionState.Started);
     413          if (startedAlgorithms == NumberOfWorkers.Value ||
     414             clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Prepared))
     415            startPending = false;
     416
     417          if (pausePending) PauseAllClonedAlgorithms();
     418          if (stopPending) StopAllClonedAlgorithms();
     419        }
     420      }
     421    }
     422
     423    private void ClonedAlgorithm_Paused(object sender, EventArgs e) {
     424      lock (locker) {
     425        if (pausePending && clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Started))
     426          OnPaused();
     427      }
     428    }
     429
     430    private void ClonedAlgorithm_Stopped(object sender, EventArgs e) {
     431      lock (locker) {
     432        if (!stopPending && ExecutionState == ExecutionState.Started) {
     433          IAlgorithm preparedAlgorithm = clonedAlgorithms.Where(alg => alg.ExecutionState == ExecutionState.Prepared ||
     434                                                                       alg.ExecutionState == ExecutionState.Paused).FirstOrDefault();
     435          if (preparedAlgorithm != null) preparedAlgorithm.Start();
     436        }
     437        if (clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Stopped))
     438          OnStopped();
     439        else if (stopPending && clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Prepared || alg.ExecutionState == ExecutionState.Stopped))
     440          OnStopped();
     441      }
     442    }
     443    #endregion
     444
     445    #region run events
    309446    private void RegisterRunsEvents() {
    310447      runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
    311448      runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
    312449      runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
    313     }
    314     private void DeregisterRunsEvents() {
    315       runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
    316       runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
    317       runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
    318450    }
    319451    private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     
    348480    }
    349481    #endregion
     482    #endregion
     483
     484    #region event firing
     485    public event EventHandler ExecutionStateChanged;
     486    private void OnExecutionStateChanged() {
     487      EventHandler handler = ExecutionStateChanged;
     488      if (handler != null) handler(this, EventArgs.Empty);
     489    }
     490    public event EventHandler ExecutionTimeChanged;
     491    private void OnExecutionTimeChanged() {
     492      EventHandler handler = ExecutionTimeChanged;
     493      if (handler != null) handler(this, EventArgs.Empty);
     494    }
     495    public event EventHandler Prepared;
     496    private void OnPrepared() {
     497      ExecutionState = ExecutionState.Prepared;
     498      EventHandler handler = Prepared;
     499      if (handler != null) handler(this, EventArgs.Empty);
     500    }
     501    public event EventHandler Started;
     502    private void OnStarted() {
     503      startPending = false;
     504      ExecutionState = ExecutionState.Started;
     505      EventHandler handler = Started;
     506      if (handler != null) handler(this, EventArgs.Empty);
     507    }
     508    public event EventHandler Paused;
     509    private void OnPaused() {
     510      pausePending = false;
     511      ExecutionState = ExecutionState.Paused;
     512      EventHandler handler = Paused;
     513      if (handler != null) handler(this, EventArgs.Empty);
     514    }
     515    public event EventHandler Stopped;
     516    private void OnStopped() {
     517      stopPending = false;
     518      ExecutionState = ExecutionState.Stopped;
     519      //TODO create run;
     520      EventHandler handler = Stopped;
     521      if (handler != null) handler(this, EventArgs.Empty);
     522    }
     523    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
     524    private void OnExceptionOccurred(Exception exception) {
     525      EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
     526      if (handler != null) handler(this, new EventArgs<Exception>(exception));
     527    }
     528    #endregion
    350529  }
    351530}
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/HeuristicLabAlgorithmsDataAnalysisPlugin.cs.frame

    r3877 r4542  
    2626  /// Plugin class for HeuristicLab.Algorithms.DataAnalysis plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3.0.$WCREV$")]
     28  [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3.1.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.3.dll", PluginFileType.Assembly)]
    3030  public class HeuristicLabAlgorithmsDataAnalysisPlugin : PluginBase {
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/Properties/AssemblyInfo.frame

    r3877 r4542  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification.Views/3.3/HeuristicLabProblemsDataAnalysisClassificationViewsPlugin.cs.frame

    r4417 r4542  
    2323
    2424namespace HeuristicLab.Problems.DataAnalysis.Classification.Views {
    25   [Plugin("HeuristicLab.Problems.DataAnalysis.Classification.Views", "3.3.0.$WCREV$")]
     25  [Plugin("HeuristicLab.Problems.DataAnalysis.Classification.Views", "3.3.1.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.DataAnalysis.Classification.Views-3.3.dll", PluginFileType.Assembly)]
    2727  public class HeuristicLabProblemsDataAnalysisClassificationViewsPlugin : PluginBase {
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification.Views/3.3/Properties/AssemblyInfo.frame

    r4417 r4542  
    5252// You can specify all the values or you can default the Build and Revision Numbers
    5353// by using the '*' as shown below:
    54 [assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
     54[assembly: AssemblyVersion("3.3.1.0")]
     55[assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/HeuristicLabProblemsDataAnalysisClassificationPlugin.cs.frame

    r4366 r4542  
    2323
    2424namespace HeuristicLab.Problems.DataAnalysis.Classification {
    25   [Plugin("HeuristicLab.Problems.DataAnalysis.Classification", "3.3.0.$WCREV$")]
     25  [Plugin("HeuristicLab.Problems.DataAnalysis.Classification", "3.3.1.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.DataAnalysis.Classification-3.3.dll", PluginFileType.Assembly)]
    2727  public class HeuristicLabProblemsDataAnalysisClassificationPlugin : PluginBase {
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Properties/AssemblyInfo.frame

    r4323 r4542  
    5252// You can specify all the values or you can default the Build and Revision Numbers
    5353// by using the '*' as shown below:
    54 [assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
     54[assembly: AssemblyVersion("3.3.1.0")]
     55[assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
Note: See TracChangeset for help on using the changeset viewer.