Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/04/14 18:35:25 (9 years ago)
Author:
abeham
Message:

#2120: merged to stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization/3.3/Interfaces/IRun.cs

    r11170 r11522  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
     22using System.ComponentModel;
    2423using System.Drawing;
     24using HeuristicLab.Collections;
    2525using HeuristicLab.Core;
    2626
     
    2929  /// Represents the parameters and results of an algorithm run.
    3030  /// </summary>
    31   public interface IRun : INamedItem {
     31  public interface IRun : INamedItem, INotifyPropertyChanged {
    3232    IAlgorithm Algorithm { get; }
    33     IDictionary<string, IItem> Parameters { get; }
    34     IDictionary<string, IItem> Results { get; }
     33    IObservableDictionary<string, IItem> Parameters { get; }
     34    IObservableDictionary<string, IItem> Results { get; }
    3535
    3636    Color Color { get; set; }
    3737    bool Visible { get; set; }
    38     event EventHandler Changed;
    3938  }
    4039}
  • stable/HeuristicLab.Optimization/3.3/Run.cs

    r11170 r11522  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    25 using System.Linq;
     26using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
     
    4445      algorithm = cloner.Clone(original.algorithm);
    4546
    46       parameters = new Dictionary<string, IItem>();
     47      parameters = new ObservableDictionary<string, IItem>();
    4748      foreach (string key in original.parameters.Keys)
    4849        parameters.Add(key, cloner.Clone(original.parameters[key]));
    4950
    50       results = new Dictionary<string, IItem>();
     51      results = new ObservableDictionary<string, IItem>();
    5152      foreach (string key in original.results.Keys)
    5253        results.Add(key, cloner.Clone(original.results[key]));
    5354    }
     55
    5456    public override IDeepCloneable Clone(Cloner cloner) {
    5557      return new Run(this, cloner);
     
    6264      color = Color.Black;
    6365      algorithm = null;
    64       parameters = new Dictionary<string, IItem>();
    65       results = new Dictionary<string, IItem>();
     66      parameters = new ObservableDictionary<string, IItem>();
     67      results = new ObservableDictionary<string, IItem>();
    6668    }
    6769    public Run(IAlgorithm algorithm)
     
    8890
    8991    private void Initialize(IAlgorithm algorithm) {
    90       parameters = new Dictionary<string, IItem>();
    91       results = new Dictionary<string, IItem>();
     92      parameters = new ObservableDictionary<string, IItem>();
     93      results = new ObservableDictionary<string, IItem>();
    9294
    9395      if (algorithm.StoreAlgorithmInEachRun) {
    94         IAlgorithm clone = (IAlgorithm)algorithm.Clone();
     96        var clone = (IAlgorithm)algorithm.Clone();
    9597        clone.CollectParameterValues(parameters);
    9698        clone.CollectResultValues(results);
     
    98100        this.algorithm = clone;
    99101      } else {
    100         algorithm.CollectParameterValues(parameters);
    101         algorithm.CollectResultValues(results);
    102         Cloner cloner = new Cloner();
    103         parameters = parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value);
    104         results = results.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value);
     102        var par = new Dictionary<string, IItem>();
     103        var res = new Dictionary<string, IItem>();
     104        algorithm.CollectParameterValues(par);
     105        algorithm.CollectResultValues(res);
     106        var cloner = new Cloner();
     107        foreach (var k in par) parameters.Add(k.Key, cloner.Clone(k.Value));
     108        foreach (var k in res) results.Add(k.Key, cloner.Clone(k.Value));
    105109      }
    106110    }
     
    115119      get { return algorithm; }
    116120    }
    117     [Storable]
    118     private Dictionary<string, IItem> parameters;
    119     public IDictionary<string, IItem> Parameters {
     121
     122    [Storable(Name = "parameters")]
     123    private IDictionary<string, IItem> StorableParameters {
    120124      get { return parameters; }
     125      set {
     126        if (!(value is IObservableDictionary<string, IItem>))
     127          parameters = new ObservableDictionary<string, IItem>(value);
     128        else parameters = (IObservableDictionary<string, IItem>)value;
     129      }
    121130    }
    122     [Storable]
    123     private Dictionary<string, IItem> results;
    124     public IDictionary<string, IItem> Results {
     131    private IObservableDictionary<string, IItem> parameters;
     132    public IObservableDictionary<string, IItem> Parameters {
     133      get { return parameters; }
     134      private set {
     135        if (parameters != value) {
     136          parameters = value;
     137          OnPropertyChanged("Parameters");
     138        }
     139      }
     140    }
     141
     142    [Storable(Name = "results")]
     143    private IDictionary<string, IItem> StorableResults {
    125144      get { return results; }
     145      set {
     146        if (!(value is IObservableDictionary<string, IItem>))
     147          results = new ObservableDictionary<string, IItem>(value);
     148        else results = (IObservableDictionary<string, IItem>)value;
     149      }
     150    }
     151    private IObservableDictionary<string, IItem> results;
     152    public IObservableDictionary<string, IItem> Results {
     153      get { return results; }
     154      private set {
     155        if (results != value) {
     156          results = value;
     157          OnPropertyChanged("Results");
     158        }
     159      }
    126160    }
    127161
     
    133167        if (color != value) {
    134168          this.color = value;
    135           this.OnChanged();
     169          OnPropertyChanged("Color");
    136170        }
    137171      }
     
    143177        if (visible != value) {
    144178          this.visible = value;
    145           this.OnChanged();
     179          OnPropertyChanged("Visible");
    146180        }
    147181      }
    148182    }
    149     public event EventHandler Changed;
    150     private void OnChanged() {
    151       EventHandler handler = Changed;
    152       if (handler != null)
    153         handler(this, EventArgs.Empty);
     183
     184    public event PropertyChangedEventHandler PropertyChanged;
     185    private void OnPropertyChanged(string property) {
     186      var handler = PropertyChanged;
     187      if (handler != null) handler(this, new PropertyChangedEventArgs(property));
    154188    }
    155189  }
  • stable/HeuristicLab.Optimization/3.3/RunCollection.cs

    r11170 r11522  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using HeuristicLab.Collections;
     
    160161        foreach (KeyValuePair<string, IItem> result in run.Results)
    161162          AddResult(result.Key, result.Value);
     163        run.PropertyChanged += RunOnPropertyChanged;
     164        RegisterRunParametersEvents(run);
     165        RegisterRunResultsEvents(run);
     166      }
     167      foreach (IRun run in oldItems) {
     168        run.PropertyChanged -= RunOnPropertyChanged;
     169        DeregisterRunParametersEvents(run);
     170        DeregisterRunResultsEvents(run);
    162171      }
    163172      columnNameCache = null;
     
    178187        foreach (KeyValuePair<string, IItem> result in run.Results)
    179188          columnsChanged |= AddResult(result.Key, result.Value);
     189        run.PropertyChanged += RunOnPropertyChanged;
     190        RegisterRunParametersEvents(run);
     191        RegisterRunResultsEvents(run);
    180192      }
    181193      if (columnsChanged) columnNameCache = null;
     
    198210        foreach (string resultName in run.Results.Keys)
    199211          columnsChanged |= RemoveResultName(resultName);
     212        run.PropertyChanged -= RunOnPropertyChanged;
     213        DeregisterRunParametersEvents(run);
     214        DeregisterRunResultsEvents(run);
    200215      }
    201216      if (columnsChanged) columnNameCache = null;
     
    205220      OnRowsChanged();
    206221      OnRowNamesChanged();
     222      if (columnsChanged) {
     223        OnColumnsChanged();
     224        OnColumnNamesChanged();
     225      }
     226    }
     227
     228    private void RunOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
     229      if (e.PropertyName == "Parameters") {
     230        RegisterRunParametersEvents((IRun)sender);
     231      } else if (e.PropertyName == "Results") {
     232        RegisterRunResultsEvents((IRun)sender);
     233      }
     234    }
     235
     236    private void RegisterRunParametersEvents(IRun run) {
     237      IObservableDictionary<string, IItem> dict = run.Parameters;
     238      dict.ItemsAdded += RunOnParameterChanged;
     239      dict.ItemsRemoved += RunOnParameterRemoved;
     240      dict.ItemsReplaced += RunOnParameterChanged;
     241      dict.CollectionReset += RunOnParameterChanged;
     242    }
     243
     244    private void RegisterRunResultsEvents(IRun run) {
     245      IObservableDictionary<string, IItem> dict = run.Results;
     246      dict.ItemsAdded += RunOnResultChanged;
     247      dict.ItemsRemoved += RunOnResultRemoved;
     248      dict.ItemsReplaced += RunOnResultChanged;
     249      dict.CollectionReset += RunOnResultChanged;
     250    }
     251
     252    private void DeregisterRunParametersEvents(IRun run) {
     253      IObservableDictionary<string, IItem> dict = run.Parameters;
     254      dict.ItemsAdded -= RunOnParameterChanged;
     255      dict.ItemsRemoved -= RunOnParameterRemoved;
     256      dict.ItemsReplaced -= RunOnParameterChanged;
     257      dict.CollectionReset -= RunOnParameterChanged;
     258    }
     259
     260    private void DeregisterRunResultsEvents(IRun run) {
     261      IObservableDictionary<string, IItem> dict = run.Results;
     262      dict.ItemsAdded -= RunOnResultChanged;
     263      dict.ItemsRemoved -= RunOnResultRemoved;
     264      dict.ItemsReplaced -= RunOnResultChanged;
     265      dict.CollectionReset -= RunOnResultChanged;
     266    }
     267
     268    private void RunOnParameterChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     269      bool columnsChanged = false;
     270      foreach (var param in e.Items)
     271        columnsChanged |= AddParameter(param.Key, param.Value);
     272      foreach (var param in e.OldItems)
     273        columnsChanged |= RemoveParameterName(param.Key);
     274      if (columnsChanged) columnNameCache = null;
     275      OnReset();
     276      if (columnsChanged) {
     277        OnColumnsChanged();
     278        OnColumnNamesChanged();
     279      }
     280    }
     281
     282    private void RunOnParameterRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     283      bool columnsChanged = false;
     284      foreach (var param in e.Items)
     285        columnsChanged |= RemoveParameterName(param.Key);
     286      if (columnsChanged) columnNameCache = null;
     287      OnReset();
     288      if (columnsChanged) {
     289        OnColumnsChanged();
     290        OnColumnNamesChanged();
     291      }
     292    }
     293
     294    private void RunOnResultChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     295      bool columnsChanged = false;
     296      foreach (var result in e.Items)
     297        columnsChanged |= AddResult(result.Key, result.Value);
     298      foreach (var result in e.OldItems)
     299        columnsChanged |= RemoveResultName(result.Key);
     300      if (columnsChanged) columnNameCache = null;
     301      OnReset();
     302      if (columnsChanged) {
     303        OnColumnsChanged();
     304        OnColumnNamesChanged();
     305      }
     306    }
     307
     308    private void RunOnResultRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     309      bool columnsChanged = false;
     310      foreach (var result in e.Items)
     311        columnsChanged |= RemoveResultName(result.Key);
     312      if (columnsChanged) columnNameCache = null;
     313      OnReset();
    207314      if (columnsChanged) {
    208315        OnColumnsChanged();
Note: See TracChangeset for help on using the changeset viewer.