1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Threading;
|
---|
27 | using HeuristicLab.Collections;
|
---|
28 | using HeuristicLab.Common;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Persistence;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Optimization {
|
---|
33 | /// <summary>
|
---|
34 | /// An experiment which contains multiple algorithms, batch runs or other experiments.
|
---|
35 | /// </summary>
|
---|
36 | [Item("Experiment", "An experiment which contains multiple algorithms, batch runs or other experiments.")]
|
---|
37 | [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 100)]
|
---|
38 | [StorableType("4caf8199-dc27-407b-bea9-085857f25029")]
|
---|
39 | public sealed class Experiment : NamedItem, IOptimizer, IStorableContent {
|
---|
40 | public string Filename { get; set; }
|
---|
41 |
|
---|
42 | public static new Image StaticItemImage {
|
---|
43 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
|
---|
44 | }
|
---|
45 | public override Image ItemImage {
|
---|
46 | get {
|
---|
47 | if (ExecutionState == ExecutionState.Prepared) return HeuristicLab.Common.Resources.VSImageLibrary.ExperimentPrepared;
|
---|
48 | else if (ExecutionState == ExecutionState.Started) return HeuristicLab.Common.Resources.VSImageLibrary.ExperimentStarted;
|
---|
49 | else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VSImageLibrary.ExperimentPaused;
|
---|
50 | else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VSImageLibrary.ExperimentStopped;
|
---|
51 | else return base.ItemImage;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | [Storable]
|
---|
56 | private ExecutionState executionState;
|
---|
57 | public ExecutionState ExecutionState {
|
---|
58 | get { return executionState; }
|
---|
59 | private set {
|
---|
60 | if (executionState != value) {
|
---|
61 | executionState = value;
|
---|
62 | OnExecutionStateChanged();
|
---|
63 | OnItemImageChanged();
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | [Storable]
|
---|
69 | private TimeSpan executionTime;
|
---|
70 | public TimeSpan ExecutionTime {
|
---|
71 | get { return executionTime; }
|
---|
72 | private set {
|
---|
73 | executionTime = value;
|
---|
74 | OnExecutionTimeChanged();
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | [Storable]
|
---|
79 | private OptimizerList optimizers;
|
---|
80 | public OptimizerList Optimizers {
|
---|
81 | get { return optimizers; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | [Storable]
|
---|
85 | private RunCollection runs;
|
---|
86 | public RunCollection Runs {
|
---|
87 | get { return runs; }
|
---|
88 | private set {
|
---|
89 | if (value == null) throw new ArgumentNullException();
|
---|
90 | if (runs != value) {
|
---|
91 | if (runs != null) DeregisterRunsEvents();
|
---|
92 | runs = value;
|
---|
93 | if (runs != null) RegisterRunsEvents();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | public IEnumerable<IOptimizer> NestedOptimizers {
|
---|
99 | get {
|
---|
100 | if (Optimizers == null) yield break;
|
---|
101 |
|
---|
102 | foreach (IOptimizer opt in Optimizers) {
|
---|
103 | yield return opt;
|
---|
104 | foreach (IOptimizer nestedOpt in opt.NestedOptimizers)
|
---|
105 | yield return nestedOpt;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | private bool experimentStarted = false;
|
---|
111 | private bool experimentStopped = false;
|
---|
112 |
|
---|
113 | public Experiment()
|
---|
114 | : base() {
|
---|
115 | name = ItemName;
|
---|
116 | description = ItemDescription;
|
---|
117 | executionState = ExecutionState.Stopped;
|
---|
118 | executionTime = TimeSpan.Zero;
|
---|
119 | optimizers = new OptimizerList();
|
---|
120 | Runs = new RunCollection { OptimizerName = Name };
|
---|
121 | Initialize();
|
---|
122 | }
|
---|
123 | public Experiment(string name)
|
---|
124 | : base(name) {
|
---|
125 | description = ItemDescription;
|
---|
126 | executionState = ExecutionState.Stopped;
|
---|
127 | executionTime = TimeSpan.Zero;
|
---|
128 | optimizers = new OptimizerList();
|
---|
129 | Runs = new RunCollection { OptimizerName = Name };
|
---|
130 | Initialize();
|
---|
131 | }
|
---|
132 | public Experiment(string name, string description)
|
---|
133 | : base(name, description) {
|
---|
134 | executionState = ExecutionState.Stopped;
|
---|
135 | executionTime = TimeSpan.Zero;
|
---|
136 | optimizers = new OptimizerList();
|
---|
137 | Runs = new RunCollection { OptimizerName = Name };
|
---|
138 | Initialize();
|
---|
139 | }
|
---|
140 | [StorableConstructor]
|
---|
141 | private Experiment(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
142 | [StorableHook(HookType.AfterDeserialization)]
|
---|
143 | private void AfterDeserialization() {
|
---|
144 | Initialize();
|
---|
145 | }
|
---|
146 | private Experiment(Experiment original, Cloner cloner)
|
---|
147 | : base(original, cloner) {
|
---|
148 | executionState = original.executionState;
|
---|
149 | executionTime = original.executionTime;
|
---|
150 | optimizers = cloner.Clone(original.optimizers);
|
---|
151 | runs = cloner.Clone(original.runs);
|
---|
152 |
|
---|
153 | experimentStarted = original.experimentStarted;
|
---|
154 | experimentStopped = original.experimentStopped;
|
---|
155 | Initialize();
|
---|
156 | }
|
---|
157 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
158 | if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
|
---|
159 | return new Experiment(this, cloner);
|
---|
160 | }
|
---|
161 |
|
---|
162 | private void Initialize() {
|
---|
163 | RegisterOptimizersEvents();
|
---|
164 | foreach (IOptimizer optimizer in optimizers)
|
---|
165 | RegisterOptimizerEvents(optimizer);
|
---|
166 | if (runs != null) RegisterRunsEvents();
|
---|
167 | }
|
---|
168 |
|
---|
169 | public void Prepare() {
|
---|
170 | Prepare(false);
|
---|
171 | }
|
---|
172 | public void Prepare(bool clearRuns) {
|
---|
173 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
|
---|
174 | throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
|
---|
175 | if (Optimizers.Count == 0) return;
|
---|
176 |
|
---|
177 | if (clearRuns) runs.Clear();
|
---|
178 |
|
---|
179 | experimentStarted = false;
|
---|
180 | experimentStopped = false;
|
---|
181 | foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) {
|
---|
182 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
183 | try { optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { }
|
---|
184 | }
|
---|
185 | }
|
---|
186 | public void Start() {
|
---|
187 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
|
---|
188 | throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
|
---|
189 | if (Optimizers.Count == 0) return;
|
---|
190 |
|
---|
191 | experimentStarted = true;
|
---|
192 | experimentStopped = false;
|
---|
193 | IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
|
---|
194 | if (optimizer != null) {
|
---|
195 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
196 | try { optimizer.Start(); } catch (InvalidOperationException) { }
|
---|
197 | }
|
---|
198 | }
|
---|
199 | public void Pause() {
|
---|
200 | if (ExecutionState != ExecutionState.Started)
|
---|
201 | throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
|
---|
202 | if (Optimizers.Count == 0) return;
|
---|
203 |
|
---|
204 | experimentStarted = false;
|
---|
205 | experimentStopped = false;
|
---|
206 | foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) {
|
---|
207 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
208 | try { optimizer.Pause(); } catch (InvalidOperationException) { }
|
---|
209 | }
|
---|
210 | }
|
---|
211 | public void Stop() {
|
---|
212 | if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
|
---|
213 | throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
|
---|
214 | if (Optimizers.Count == 0) return;
|
---|
215 |
|
---|
216 | experimentStarted = false;
|
---|
217 | experimentStopped = true;
|
---|
218 | if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) {
|
---|
219 | foreach (var optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) {
|
---|
220 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
221 | try { optimizer.Stop(); } catch (InvalidOperationException) { }
|
---|
222 | }
|
---|
223 | } else {
|
---|
224 | OnStopped();
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | #region Events
|
---|
229 | protected override void OnNameChanged() {
|
---|
230 | base.OnNameChanged();
|
---|
231 | Runs.OptimizerName = Name;
|
---|
232 | }
|
---|
233 |
|
---|
234 | public event EventHandler ExecutionStateChanged;
|
---|
235 | private void OnExecutionStateChanged() {
|
---|
236 | EventHandler handler = ExecutionStateChanged;
|
---|
237 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
238 | }
|
---|
239 | public event EventHandler ExecutionTimeChanged;
|
---|
240 | private void OnExecutionTimeChanged() {
|
---|
241 | EventHandler handler = ExecutionTimeChanged;
|
---|
242 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
243 | }
|
---|
244 | public event EventHandler Prepared;
|
---|
245 | private void OnPrepared() {
|
---|
246 | ExecutionState = ExecutionState.Prepared;
|
---|
247 | EventHandler handler = Prepared;
|
---|
248 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
249 | }
|
---|
250 | public event EventHandler Started;
|
---|
251 | private void OnStarted() {
|
---|
252 | ExecutionState = ExecutionState.Started;
|
---|
253 | EventHandler handler = Started;
|
---|
254 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
255 | }
|
---|
256 | public event EventHandler Paused;
|
---|
257 | private void OnPaused() {
|
---|
258 | ExecutionState = ExecutionState.Paused;
|
---|
259 | EventHandler handler = Paused;
|
---|
260 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
261 | }
|
---|
262 | public event EventHandler Stopped;
|
---|
263 | private void OnStopped() {
|
---|
264 | ExecutionState = ExecutionState.Stopped;
|
---|
265 | EventHandler handler = Stopped;
|
---|
266 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
267 | }
|
---|
268 | public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
|
---|
269 | private void OnExceptionOccurred(Exception exception) {
|
---|
270 | EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
|
---|
271 | if (handler != null) handler(this, new EventArgs<Exception>(exception));
|
---|
272 | }
|
---|
273 |
|
---|
274 | private void RegisterOptimizersEvents() {
|
---|
275 | Optimizers.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
|
---|
276 | Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
|
---|
277 | Optimizers.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
|
---|
278 | Optimizers.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
|
---|
279 | }
|
---|
280 | private void DeregisterOptimizersEvents() {
|
---|
281 | Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
|
---|
282 | Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
|
---|
283 | Optimizers.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
|
---|
284 | Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
|
---|
285 | }
|
---|
286 | private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
|
---|
287 | foreach (IndexedItem<IOptimizer> item in e.OldItems)
|
---|
288 | RemoveOptimizer(item.Value);
|
---|
289 | foreach (IndexedItem<IOptimizer> item in e.Items)
|
---|
290 | AddOptimizer(item.Value);
|
---|
291 | }
|
---|
292 | private void Optimizers_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
|
---|
293 | foreach (IndexedItem<IOptimizer> item in e.Items)
|
---|
294 | AddOptimizer(item.Value);
|
---|
295 | }
|
---|
296 | private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
|
---|
297 | foreach (IndexedItem<IOptimizer> item in e.Items)
|
---|
298 | RemoveOptimizer(item.Value);
|
---|
299 | }
|
---|
300 | private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
|
---|
301 | foreach (IndexedItem<IOptimizer> item in e.OldItems)
|
---|
302 | RemoveOptimizer(item.Value);
|
---|
303 | foreach (IndexedItem<IOptimizer> item in e.Items)
|
---|
304 | AddOptimizer(item.Value);
|
---|
305 | }
|
---|
306 | private void AddOptimizer(IOptimizer optimizer) {
|
---|
307 | RegisterOptimizerEvents(optimizer);
|
---|
308 | Runs.AddRange(optimizer.Runs);
|
---|
309 | optimizer.Prepare();
|
---|
310 | if (ExecutionState == ExecutionState.Stopped && optimizer.ExecutionState == ExecutionState.Prepared)
|
---|
311 | OnPrepared();
|
---|
312 | }
|
---|
313 | private void RemoveOptimizer(IOptimizer optimizer) {
|
---|
314 | DeregisterOptimizerEvents(optimizer);
|
---|
315 | Runs.RemoveRange(optimizer.Runs);
|
---|
316 | if (ExecutionState == ExecutionState.Prepared && !optimizers.Any(opt => opt.ExecutionState == ExecutionState.Prepared))
|
---|
317 | OnStopped();
|
---|
318 | }
|
---|
319 |
|
---|
320 | private void RegisterOptimizerEvents(IOptimizer optimizer) {
|
---|
321 | optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
|
---|
322 | optimizer.ExecutionTimeChanged += new EventHandler(optimizer_ExecutionTimeChanged);
|
---|
323 | optimizer.Paused += new EventHandler(optimizer_Paused);
|
---|
324 | optimizer.Prepared += new EventHandler(optimizer_Prepared);
|
---|
325 | optimizer.Started += new EventHandler(optimizer_Started);
|
---|
326 | optimizer.Stopped += new EventHandler(optimizer_Stopped);
|
---|
327 | optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset);
|
---|
328 | optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded);
|
---|
329 | optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved);
|
---|
330 | }
|
---|
331 | private void DeregisterOptimizerEvents(IOptimizer optimizer) {
|
---|
332 | optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
|
---|
333 | optimizer.ExecutionTimeChanged -= new EventHandler(optimizer_ExecutionTimeChanged);
|
---|
334 | optimizer.Paused -= new EventHandler(optimizer_Paused);
|
---|
335 | optimizer.Prepared -= new EventHandler(optimizer_Prepared);
|
---|
336 | optimizer.Started -= new EventHandler(optimizer_Started);
|
---|
337 | optimizer.Stopped -= new EventHandler(optimizer_Stopped);
|
---|
338 | optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset);
|
---|
339 | optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded);
|
---|
340 | optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved);
|
---|
341 | }
|
---|
342 |
|
---|
343 | private readonly object locker = new object();
|
---|
344 | private readonly object runsLocker = new object();
|
---|
345 | private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
346 | lock (locker)
|
---|
347 | OnExceptionOccurred(e.Value);
|
---|
348 | }
|
---|
349 | private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
350 | // only wait for maximally 100ms to acquire lock, otherwise return and don't update the execution time
|
---|
351 | var success = Monitor.TryEnter(locker, 100);
|
---|
352 | if (!success) return;
|
---|
353 | try {
|
---|
354 | ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
|
---|
355 | } finally {
|
---|
356 | Monitor.Exit(locker);
|
---|
357 | }
|
---|
358 | }
|
---|
359 | private void optimizer_Paused(object sender, EventArgs e) {
|
---|
360 | lock (locker)
|
---|
361 | if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused();
|
---|
362 | }
|
---|
363 | private void optimizer_Prepared(object sender, EventArgs e) {
|
---|
364 | lock (locker)
|
---|
365 | if (Optimizers.All(x => x.ExecutionState == ExecutionState.Prepared)) OnPrepared();
|
---|
366 | }
|
---|
367 | private void optimizer_Started(object sender, EventArgs e) {
|
---|
368 | lock (locker)
|
---|
369 | if (ExecutionState != ExecutionState.Started) OnStarted();
|
---|
370 | }
|
---|
371 | private void optimizer_Stopped(object sender, EventArgs e) {
|
---|
372 | lock (locker) {
|
---|
373 | if (experimentStopped) {
|
---|
374 | if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped();
|
---|
375 | } else {
|
---|
376 | if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) {
|
---|
377 | Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start();
|
---|
378 | } else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped();
|
---|
379 | else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused();
|
---|
380 | }
|
---|
381 | }
|
---|
382 | }
|
---|
383 | private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
384 | lock (runsLocker) {
|
---|
385 | Runs.RemoveRange(e.OldItems);
|
---|
386 | Runs.AddRange(e.Items);
|
---|
387 | }
|
---|
388 | }
|
---|
389 | private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
390 | lock (runsLocker)
|
---|
391 | Runs.AddRange(e.Items);
|
---|
392 | }
|
---|
393 | private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
394 | lock (runsLocker)
|
---|
395 | Runs.RemoveRange(e.Items);
|
---|
396 | }
|
---|
397 |
|
---|
398 | private void RegisterRunsEvents() {
|
---|
399 | runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
|
---|
400 | runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
|
---|
401 | }
|
---|
402 | private void DeregisterRunsEvents() {
|
---|
403 | runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
|
---|
404 | runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
|
---|
405 | }
|
---|
406 | private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
407 | foreach (IOptimizer optimizer in Optimizers)
|
---|
408 | optimizer.Runs.RemoveRange(e.OldItems);
|
---|
409 | }
|
---|
410 | private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
411 | foreach (IOptimizer optimizer in Optimizers)
|
---|
412 | optimizer.Runs.RemoveRange(e.Items);
|
---|
413 | }
|
---|
414 | #endregion
|
---|
415 | }
|
---|
416 | }
|
---|