Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4115 for trunk/sources


Ignore:
Timestamp:
07/27/10 17:05:00 (14 years ago)
Author:
mkommend
Message:

Added correct handling of adding and removing runs in experiments and batch runs (ticket #1111).

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3716 r4115  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System.Collections.Generic;
    2930
    3031namespace HeuristicLab.Optimization {
     
    8081      set {
    8182        if (algorithm != value) {
    82           if (algorithm != null) DeregisterAlgorithmEvents();
     83          if (algorithm != null) {
     84            DeregisterAlgorithmEvents();
     85            IEnumerable<IRun> runs = algorithm.Runs;
     86            algorithm = null; //necessary to avoid removing the runs from the old algorithm
     87            Runs.RemoveRange(runs);
     88          }
    8389          algorithm = value;
    84           if (algorithm != null) RegisterAlgorithmEvents();
     90          if (algorithm != null) {
     91            RegisterAlgorithmEvents();
     92            Runs.AddRange(algorithm.Runs);
     93          }
    8594          OnAlgorithmChanged();
    8695          Prepare();
     
    324333    private void RegisterRunsEvents() {
    325334      runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
     335      runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
    326336      runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
    327337    }
     338
    328339    private void DeregisterRunsEvents() {
    329340      runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
     341      runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
    330342      runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
    331343    }
     
    345357      }
    346358    }
     359    private void Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     360      foreach (IRun run in e.Items) {
     361        IItem item;
     362        run.Results.TryGetValue("Execution Time", out item);
     363        TimeSpanValue executionTime = item as TimeSpanValue;
     364        if (executionTime != null) ExecutionTime += executionTime.Value;
     365      }
     366    }
    347367    private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    348368      foreach (IRun run in e.Items) {
  • trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs

    r4110 r4115  
    240240    }
    241241    private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    242       foreach (IndexedItem<IOptimizer> item in e.OldItems) {
    243         DeregisterOptimizerEvents(item.Value);
    244       }
     242      foreach (IndexedItem<IOptimizer> item in e.OldItems)
     243        RemoveOptimizer(item.Value);
    245244      foreach (IndexedItem<IOptimizer> item in e.Items)
    246245        AddOptimizer(item.Value);
     
    251250    }
    252251    private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    253       foreach (IndexedItem<IOptimizer> item in e.Items) {
    254         DeregisterOptimizerEvents(item.Value);
    255       }
     252      foreach (IndexedItem<IOptimizer> item in e.Items)
     253        RemoveOptimizer(item.Value);
    256254    }
    257255    private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    258       foreach (IndexedItem<IOptimizer> item in e.OldItems) {
    259         DeregisterOptimizerEvents(item.Value);
    260       }
     256      foreach (IndexedItem<IOptimizer> item in e.OldItems)
     257        RemoveOptimizer(item.Value);
    261258      foreach (IndexedItem<IOptimizer> item in e.Items)
    262259        AddOptimizer(item.Value);
     
    266263      Runs.AddRange(optimizer.Runs);
    267264      optimizer.Prepare();
     265    }
     266    private void RemoveOptimizer(IOptimizer optimizer) {
     267      DeregisterOptimizerEvents(optimizer);
     268      Runs.RemoveRange(optimizer.Runs);
    268269    }
    269270
Note: See TracChangeset for help on using the changeset viewer.