Changeset 4115 for trunk/sources
- Timestamp:
- 07/27/10 17:05:00 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r3716 r4115 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Collections.Generic; 29 30 30 31 namespace HeuristicLab.Optimization { … … 80 81 set { 81 82 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 } 83 89 algorithm = value; 84 if (algorithm != null) RegisterAlgorithmEvents(); 90 if (algorithm != null) { 91 RegisterAlgorithmEvents(); 92 Runs.AddRange(algorithm.Runs); 93 } 85 94 OnAlgorithmChanged(); 86 95 Prepare(); … … 324 333 private void RegisterRunsEvents() { 325 334 runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 335 runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded); 326 336 runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved); 327 337 } 338 328 339 private void DeregisterRunsEvents() { 329 340 runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 341 runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded); 330 342 runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved); 331 343 } … … 345 357 } 346 358 } 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 } 347 367 private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 348 368 foreach (IRun run in e.Items) { -
trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs
r4110 r4115 240 240 } 241 241 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); 245 244 foreach (IndexedItem<IOptimizer> item in e.Items) 246 245 AddOptimizer(item.Value); … … 251 250 } 252 251 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); 256 254 } 257 255 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); 261 258 foreach (IndexedItem<IOptimizer> item in e.Items) 262 259 AddOptimizer(item.Value); … … 266 263 Runs.AddRange(optimizer.Runs); 267 264 optimizer.Prepare(); 265 } 266 private void RemoveOptimizer(IOptimizer optimizer) { 267 DeregisterOptimizerEvents(optimizer); 268 Runs.RemoveRange(optimizer.Runs); 268 269 } 269 270
Note: See TracChangeset
for help on using the changeset viewer.