Changeset 11522 for stable/HeuristicLab.Optimization
- Timestamp:
- 11/04/14 18:35:25 (9 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11344-11345,11419
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization/3.3/Interfaces/IRun.cs
r11170 r11522 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 using System.ComponentModel; 24 23 using System.Drawing; 24 using HeuristicLab.Collections; 25 25 using HeuristicLab.Core; 26 26 … … 29 29 /// Represents the parameters and results of an algorithm run. 30 30 /// </summary> 31 public interface IRun : INamedItem {31 public interface IRun : INamedItem, INotifyPropertyChanged { 32 32 IAlgorithm Algorithm { get; } 33 I Dictionary<string, IItem> Parameters { get; }34 I Dictionary<string, IItem> Results { get; }33 IObservableDictionary<string, IItem> Parameters { get; } 34 IObservableDictionary<string, IItem> Results { get; } 35 35 36 36 Color Color { get; set; } 37 37 bool Visible { get; set; } 38 event EventHandler Changed;39 38 } 40 39 } -
stable/HeuristicLab.Optimization/3.3/Run.cs
r11170 r11522 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 using System.Linq;26 using HeuristicLab.Collections; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; … … 44 45 algorithm = cloner.Clone(original.algorithm); 45 46 46 parameters = new Dictionary<string, IItem>();47 parameters = new ObservableDictionary<string, IItem>(); 47 48 foreach (string key in original.parameters.Keys) 48 49 parameters.Add(key, cloner.Clone(original.parameters[key])); 49 50 50 results = new Dictionary<string, IItem>();51 results = new ObservableDictionary<string, IItem>(); 51 52 foreach (string key in original.results.Keys) 52 53 results.Add(key, cloner.Clone(original.results[key])); 53 54 } 55 54 56 public override IDeepCloneable Clone(Cloner cloner) { 55 57 return new Run(this, cloner); … … 62 64 color = Color.Black; 63 65 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>(); 66 68 } 67 69 public Run(IAlgorithm algorithm) … … 88 90 89 91 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>(); 92 94 93 95 if (algorithm.StoreAlgorithmInEachRun) { 94 IAlgorithmclone = (IAlgorithm)algorithm.Clone();96 var clone = (IAlgorithm)algorithm.Clone(); 95 97 clone.CollectParameterValues(parameters); 96 98 clone.CollectResultValues(results); … … 98 100 this.algorithm = clone; 99 101 } 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)); 105 109 } 106 110 } … … 115 119 get { return algorithm; } 116 120 } 117 [Storable] 118 private Dictionary<string, IItem> parameters;119 p ublic IDictionary<string, IItem>Parameters {121 122 [Storable(Name = "parameters")] 123 private IDictionary<string, IItem> StorableParameters { 120 124 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 } 121 130 } 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 { 125 144 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 } 126 160 } 127 161 … … 133 167 if (color != value) { 134 168 this.color = value; 135 this.OnChanged();169 OnPropertyChanged("Color"); 136 170 } 137 171 } … … 143 177 if (visible != value) { 144 178 this.visible = value; 145 this.OnChanged();179 OnPropertyChanged("Visible"); 146 180 } 147 181 } 148 182 } 149 public event EventHandler Changed; 150 p rivate 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)); 154 188 } 155 189 } -
stable/HeuristicLab.Optimization/3.3/RunCollection.cs
r11170 r11522 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using HeuristicLab.Collections; … … 160 161 foreach (KeyValuePair<string, IItem> result in run.Results) 161 162 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); 162 171 } 163 172 columnNameCache = null; … … 178 187 foreach (KeyValuePair<string, IItem> result in run.Results) 179 188 columnsChanged |= AddResult(result.Key, result.Value); 189 run.PropertyChanged += RunOnPropertyChanged; 190 RegisterRunParametersEvents(run); 191 RegisterRunResultsEvents(run); 180 192 } 181 193 if (columnsChanged) columnNameCache = null; … … 198 210 foreach (string resultName in run.Results.Keys) 199 211 columnsChanged |= RemoveResultName(resultName); 212 run.PropertyChanged -= RunOnPropertyChanged; 213 DeregisterRunParametersEvents(run); 214 DeregisterRunResultsEvents(run); 200 215 } 201 216 if (columnsChanged) columnNameCache = null; … … 205 220 OnRowsChanged(); 206 221 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(); 207 314 if (columnsChanged) { 208 315 OnColumnsChanged();
Note: See TracChangeset
for help on using the changeset viewer.