Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/AlgorithmIterator.cs @ 12856

Last change on this file since 12856 was 12856, checked in by abeham, 9 years ago

#2431: Added AlgorithmIterator instead of IRRestarter

  • AlgorithmIterator implements IAlgorithm whereas IRRestarter implemented only IOptimizer
  • Deriving from Algorithm leads to better design
File size: 23.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Linq;
24using System.Threading;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using System.Threading.Tasks;
32
33namespace HeuristicLab.Analysis {
34  /// <summary>
35  /// A run in which an algorithm is executed for a certain maximum time only.
36  /// </summary>
37  [Item("Algorithm Iterator", "An algorithm that repeats an algorithm until either a certain target value is reached or a maximum budget is exceeded.")]
38  [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 116)]
39  [StorableClass]
40  public sealed class AlgorithmIterator : Algorithm, IStorableContent {
41    private const string ExecutionTimeResultName = "Execution Time";
42    private const string BestQualityResultName = "BestQuality";
43    private const string RandomRestartsResultName = "RandomRestarts";
44    private const string EvaluatedSolutionsResultName = "EvaluatedSolutions";
45    private const string EvaluatedMovesResultName = "EvaluatedMoves";
46    private const string QualityPerClockResultName = "QualityPerClock";
47    private const string QualityPerEvaluationsResultName = "QualityPerEvaluations";
48    private const string EvaluationsResultName = "Evaluations";
49
50    public string Filename { get; set; }
51
52    public override Type ProblemType { get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); } }
53    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
54      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
55      set {
56        base.Problem = value;
57        if (Algorithm != null) Algorithm.Problem = Problem;
58        if (Problem != null) UpdateTargetValueFromBestKnownQuality();
59      }
60    }
61
62    public IValueParameter<TimeSpanValue> MaximumExecutionTimeParameter {
63      get { return (IValueParameter<TimeSpanValue>)Parameters["MaximumExecutionTime"]; }
64    }
65
66    public IValueParameter<IntValue> MaximumEvaluationsParameter {
67      get { return (IValueParameter<IntValue>)Parameters["MaximumEvaluations"]; }
68    }
69
70    public IValueParameter<DoubleValue> TargetValueParameter {
71      get { return (IValueParameter<DoubleValue>)Parameters["TargetValue"]; }
72    }
73
74    private IFixedValueParameter<DoubleValue> MoveCostPerSolutionParameter {
75      get { return (IFixedValueParameter<DoubleValue>)Parameters["MoveCostPerSolution"]; }
76    }
77
78    private IFixedValueParameter<BoolValue> StoreSolutionInRunParameter {
79      get { return (IFixedValueParameter<BoolValue>)Parameters["StoreSolutionInRun"]; }
80    }
81
82    private IValueParameter<IAlgorithm> AlgorithmParameter {
83      get { return (IValueParameter<IAlgorithm>)Parameters["Algorithm"]; }
84    }
85
86    [Storable]
87    private ResultCollection results;
88    public override ResultCollection Results {
89      get { return results; }
90    }
91
92    [Storable]
93    private QualityPerClockAnalyzer perClockAnalyzer;
94    [Storable]
95    private QualityPerEvaluationsAnalyzer perEvaluationsAnalyzer;
96
97    public double MoveCostPerSolution {
98      get { return MoveCostPerSolutionParameter.Value.Value; }
99      set { MoveCostPerSolutionParameter.Value.Value = value; }
100    }
101
102    public bool StoreSolutionInRun {
103      get { return StoreSolutionInRunParameter.Value.Value; }
104      set { StoreSolutionInRunParameter.Value.Value = value; }
105    }
106
107    [Storable]
108    private IAlgorithm algorithm;
109    public IAlgorithm Algorithm {
110      get { return algorithm; }
111      set {
112        if (algorithm == value) return;
113        if (algorithm != null) {
114          DeregisterAlgorithmEvents();
115          RemoveAlgorithmAnalyzers();
116        }
117        algorithm = value;
118        if (algorithm != null) {
119          if (algorithm.ExecutionState != ExecutionState.Prepared)
120            algorithm.Prepare(true);
121          algorithm.Problem = Problem;
122          RegisterAlgorithmEvents();
123          AddAlgorithmAnalyzers();
124        }
125        if (AlgorithmParameter.Value != algorithm)
126          AlgorithmParameter.Value = algorithm;
127        Prepare();
128      }
129    }
130
131    private bool Maximization {
132      get { return Problem != null && ((IValueParameter<BoolValue>)Problem.MaximizationParameter).Value.Value; }
133    }
134
135    private bool IsFinished {
136      get {
137        var executionTime = Results.ContainsKey(ExecutionTimeResultName) ? ((TimeSpanValue)Results[ExecutionTimeResultName].Value).Value : TimeSpan.Zero;
138        var evaluations = Results.ContainsKey(EvaluationsResultName) ? ((DoubleValue)Results[EvaluationsResultName].Value).Value : 0;
139        var bestQuality = Results.ContainsKey(BestQualityResultName) ? ((DoubleValue)Results[BestQualityResultName].Value).Value
140                                                                     : (Maximization ? double.MinValue : double.MaxValue);
141        var targetValue = TargetValueParameter.Value != null ? TargetValueParameter.Value.Value
142                                                             : Maximization ? double.MaxValue : double.MinValue;
143
144        var timeHit = MaximumExecutionTimeParameter.Value != null && executionTime >= MaximumExecutionTimeParameter.Value.Value;
145        var evalHit = MaximumEvaluationsParameter.Value != null && evaluations >= MaximumEvaluationsParameter.Value.Value;
146        var targetHit = Maximization && bestQuality >= targetValue || !Maximization && bestQuality <= targetValue;
147
148        return timeHit || evalHit || targetHit;
149      }
150    }
151
152    [StorableConstructor]
153    private AlgorithmIterator(bool deserializing) : base(deserializing) { }
154    private AlgorithmIterator(AlgorithmIterator original, Cloner cloner)
155      : base(original, cloner) {
156      results = cloner.Clone(original.Results);
157      perClockAnalyzer = cloner.Clone(original.perClockAnalyzer);
158      perEvaluationsAnalyzer = cloner.Clone(original.perEvaluationsAnalyzer);
159
160      RegisterEventHandlers();
161    }
162    public AlgorithmIterator()
163      : base() {
164      results = new ResultCollection();
165      Parameters.Add(new OptionalValueParameter<TimeSpanValue>("MaximumExecutionTime", "The maximum wall-clock time that the algorithm should run."));
166      Parameters.Add(new OptionalValueParameter<IntValue>("MaximumEvaluations", "The maximum number of function evaluations that the algorithm should run.", new IntValue(100000000)));
167      Parameters.Add(new OptionalValueParameter<DoubleValue>("TargetValue", "The target value that the algorithm should run for."));
168      Parameters.Add(new FixedValueParameter<DoubleValue>("MoveCostPerSolution", "The amount of solution evaluation equivalents of a single move. Use 1 for a black-box scenario.", new DoubleValue(1)));
169      Parameters.Add(new FixedValueParameter<BoolValue>("StoreSolutionInRun", "Whether the solution data types should be kept in the run."));
170      Parameters.Add(new ValueParameter<IAlgorithm>("Algorithm", "The algorithm to iterate.") { GetsCollected = false }); // due to storage efficiency, by default we don't want to store the algorithm instance in the run
171
172      perClockAnalyzer = new QualityPerClockAnalyzer();
173      perEvaluationsAnalyzer = new QualityPerEvaluationsAnalyzer();
174
175      RegisterEventHandlers();
176    }
177
178    public override IDeepCloneable Clone(Cloner cloner) {
179      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
180      return new AlgorithmIterator(this, cloner);
181    }
182
183    [StorableHook(HookType.AfterDeserialization)]
184    private void AfterDeserialization() {
185      RegisterEventHandlers();
186    }
187
188    #region Register Event Handlers
189    protected override void RegisterProblemEvents() {
190      var bkParam = Problem.BestKnownQualityParameter as IValueParameter<DoubleValue>;
191      if (bkParam != null) {
192        bkParam.ValueChanged += Problem_BestKnownQualityParameter_ValueChanged;
193      }
194      base.RegisterProblemEvents();
195    }
196    protected override void DeregisterProblemEvents() {
197      base.DeregisterProblemEvents();
198      var bkParam = Problem.BestKnownQualityParameter as IValueParameter<DoubleValue>;
199      if (bkParam != null) {
200        bkParam.ValueChanged -= Problem_BestKnownQualityParameter_ValueChanged;
201      }
202    }
203    private void RegisterAlgorithmEvents() {
204      Algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred;
205      Algorithm.Paused += Algorithm_Paused;
206      Algorithm.Stopped += Algorithm_Stopped;
207      Algorithm.ProblemChanged += Algorithm_ProblemChanged;
208    }
209    private void DeregisterAlgorithmEvents() {
210      Algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred;
211      Algorithm.Paused -= Algorithm_Paused;
212      Algorithm.Stopped -= Algorithm_Stopped;
213      Algorithm.ProblemChanged -= Algorithm_ProblemChanged;
214    }
215    #endregion
216
217    private void RegisterEventHandlers() {
218      if (Algorithm != null) RegisterAlgorithmEvents();
219      if (Problem != null) RegisterProblemEvents();
220      AlgorithmParameter.ValueChanged += AlgorithmParameterOnValueChanged;
221    }
222
223    private void AlgorithmParameterOnValueChanged(object sender, EventArgs eventArgs) {
224      Algorithm = AlgorithmParameter.Value;
225    }
226
227    #region Prepare, Start, Pause, Stop
228    public override void Prepare() {
229      if (Problem == null || Algorithm == null) return;
230
231      Algorithm.Prepare(true);
232
233      results.Clear();
234      OnPrepared();
235    }
236
237    public override void Start() {
238      base.Start();
239      OnStarted();
240      var task = Task.Factory.StartNew(Run, null);
241      task.ContinueWith(t => {
242        try {
243          t.Wait();
244        } catch (AggregateException ex) {
245          try {
246            ex.Flatten().Handle(x => x is OperationCanceledException);
247          } catch (AggregateException remaining) {
248            if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
249            else OnExceptionOccurred(remaining);
250          }
251        }
252        if (Algorithm.ExecutionState == ExecutionState.Paused) OnPaused();
253        else OnStopped();
254      });
255    }
256
257    public override void Pause() {
258      base.Pause();
259      Algorithm.Pause();
260    }
261
262    public override void Stop() {
263      base.Stop();
264      Algorithm.Stop();
265    }
266    #endregion
267
268    private DateTime lastUpdateTime;
269    private void Run(object state) {
270      lastUpdateTime = DateTime.UtcNow;
271      System.Timers.Timer timer = new System.Timers.Timer(250);
272      timer.AutoReset = true;
273      timer.Elapsed += timer_Elapsed;
274      timer.Start();
275      try {
276        Run();
277      } finally {
278        timer.Elapsed -= timer_Elapsed;
279        timer.Stop();
280        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
281      }
282    }
283
284    private readonly AutoResetEvent algorithmWaitHandle = new AutoResetEvent(false);
285    private void Run() {
286      if (!Results.ContainsKey(ExecutionTimeResultName)) Results.Add(new Result(ExecutionTimeResultName, new TimeSpanValue(TimeSpan.Zero)));
287      if (!Results.ContainsKey(EvaluatedSolutionsResultName)) Results.Add(new Result(EvaluatedSolutionsResultName, new DoubleValue(0)));
288      if (!Results.ContainsKey(EvaluatedMovesResultName)) Results.Add(new Result(EvaluatedMovesResultName, new DoubleValue(0)));
289      if (!Results.ContainsKey(EvaluationsResultName)) Results.Add(new Result(EvaluationsResultName, new DoubleValue(0)));
290      if (!Results.ContainsKey(BestQualityResultName)) Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN)));
291
292      do {
293        if (!Results.ContainsKey(RandomRestartsResultName)) Results.Add(new Result(RandomRestartsResultName, new IntValue(0)));
294        else if (Algorithm.ExecutionState == ExecutionState.Prepared) ((IntValue)Results[RandomRestartsResultName].Value).Value++;
295
296        Algorithm.Start();
297        algorithmWaitHandle.WaitOne();
298
299        if (Algorithm.ExecutionState == ExecutionState.Paused) return;
300
301        var execTime = ((TimeSpanValue)Results[ExecutionTimeResultName].Value);
302        var solEvals = ((DoubleValue)Results[EvaluatedSolutionsResultName].Value);
303        var movEvals = ((DoubleValue)Results[EvaluatedMovesResultName].Value);
304        var restarts = ((IntValue)Results[RandomRestartsResultName].Value);
305        var evaluations = ((DoubleValue)Results[EvaluationsResultName].Value);
306        var bestQuality = ((DoubleValue)Results[BestQualityResultName].Value);
307        var improvement = false;
308
309        IResult result;
310        if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName, out result)) {
311          var evals = ((IntValue)result.Value).Value;
312          evaluations.Value += evals;
313          solEvals.Value += evals;
314        }
315        if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName, out result)) {
316          var evals = ((IntValue)result.Value).Value;
317          evaluations.Value += MoveCostPerSolution * evals;
318          movEvals.Value += evals;
319        }
320        if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.BestQualityParameter.ActualName, out result)) {
321          var newBestQuality = ((DoubleValue)result.Value).Value;
322          if (double.IsNaN(bestQuality.Value)
323              || Maximization && newBestQuality > bestQuality.Value
324              || !Maximization && newBestQuality < bestQuality.Value) {
325            bestQuality.Value = newBestQuality;
326            improvement = true;
327          }
328        }
329        if (Algorithm.Results.TryGetValue(perClockAnalyzer.QualityPerClockParameter.ResultName, out result)) {
330          UpdateQualityPerClockResult((IndexedDataTable<double>)result.Value, restarts.Value);
331        }
332        if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.QualityPerEvaluationsParameter.ResultName, out result)) {
333          UpdateQualityPerEvaluationsResult((IndexedDataTable<double>)result.Value, restarts.Value);
334        }
335        if (StoreSolutionInRun) {
336          foreach (var r in Algorithm.Results) {
337            if (r.Name.ToLower().EndsWith("solution") && improvement) {
338              if (!Results.TryGetValue(r.Name, out result))
339                Results.Add(new Result(r.Name, (IItem)r.Value.Clone()));
340              else result.Value = (IItem)r.Value.Clone();
341            }
342          }
343        }
344
345        execTime.Value = ExecutionTime;
346
347        Algorithm.Prepare(true);
348      } while (!IsFinished);
349    }
350
351    private void UpdateQualityPerClockResult(IndexedDataTable<double> perClock, int restarts) {
352      IndexedDataTable<double> dt;
353      if (!Results.ContainsKey(QualityPerClockResultName)) {
354        dt = (IndexedDataTable<double>)perClock.Clone();
355        if (!dt.Rows.ContainsKey("Restarts"))
356          dt.Rows.Add(new IndexedDataRow<double>("Restarts") {
357            VisualProperties = {
358              ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
359              SecondYAxis = true
360            }
361          });
362        foreach (var v in dt.Rows.First().Values)
363          dt.Rows["Restarts"].Values.Add(Tuple.Create(v.Item1, 0.0));
364        Results.Add(new Result(QualityPerClockResultName, dt));
365      } else {
366        dt = (IndexedDataTable<double>)Results[QualityPerClockResultName].Value;
367        var qualityValues = dt.Rows.First().Values;
368        var restartValues = dt.Rows["Restarts"].Values;
369        var best = qualityValues.Last().Item2;
370        var execTime = qualityValues.Last().Item1;
371        var improvement = false;
372        foreach (var tupl in perClock.Rows.First().Values) {
373          if (Maximization && tupl.Item2 > best || !Maximization && tupl.Item2 < best) {
374            if (!improvement) {
375              // the last entry always holds the same value, but with highest execution time
376              qualityValues.RemoveAt(qualityValues.Count - 1);
377              restartValues.RemoveAt(restartValues.Count - 1);
378              improvement = true;
379            }
380            qualityValues.Add(Tuple.Create(execTime + tupl.Item1, tupl.Item2));
381            restartValues.Add(Tuple.Create(execTime + tupl.Item1, (double)restarts));
382            best = tupl.Item2;
383          }
384        }
385        if (improvement) {
386          var totalExecTime = execTime + perClock.Rows.First().Values.Last().Item1;
387          qualityValues.Add(Tuple.Create(totalExecTime, best));
388          restartValues.Add(Tuple.Create(totalExecTime, (double)restarts));
389        }
390      }
391    }
392
393    private void UpdateQualityPerEvaluationsResult(IndexedDataTable<double> perEvaluations, int restarts) {
394      IndexedDataTable<double> dt;
395      if (!Results.ContainsKey(QualityPerEvaluationsResultName)) {
396        dt = (IndexedDataTable<double>)perEvaluations.Clone();
397        if (!dt.Rows.ContainsKey("Restarts"))
398          dt.Rows.Add(new IndexedDataRow<double>("Restarts") {
399            VisualProperties = {
400              ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
401              SecondYAxis = true
402            }
403          });
404        foreach (var v in dt.Rows.First().Values)
405          dt.Rows["Restarts"].Values.Add(Tuple.Create(v.Item1, 0.0));
406        Results.Add(new Result(QualityPerEvaluationsResultName, dt));
407      } else {
408        dt = (IndexedDataTable<double>)Results[QualityPerEvaluationsResultName].Value;
409        var qualityValues = dt.Rows.First().Values;
410        var restartValues = dt.Rows["Restarts"].Values;
411        var best = qualityValues.Last().Item2;
412        var evaluations = qualityValues.Last().Item1;
413        var improvement = false;
414        foreach (var tupl in perEvaluations.Rows.First().Values) {
415          if (Maximization && tupl.Item2 > best || !Maximization && tupl.Item2 < best) {
416            if (!improvement) {
417              // the last entry always holds the same value, but with highest evaluations
418              qualityValues.RemoveAt(qualityValues.Count - 1);
419              restartValues.RemoveAt(restartValues.Count - 1);
420              improvement = true;
421            }
422            qualityValues.Add(Tuple.Create(evaluations + tupl.Item1, tupl.Item2));
423            restartValues.Add(Tuple.Create(evaluations + tupl.Item1, (double)restarts));
424            best = tupl.Item2;
425          }
426        }
427        if (improvement) { // add the best quality again as value with highest evaluations
428          var totalEvaluations = evaluations + perEvaluations.Rows.First().Values.Last().Item1;
429          qualityValues.Add(Tuple.Create(totalEvaluations, best));
430          restartValues.Add(Tuple.Create(totalEvaluations, (double)restarts));
431        }
432      }
433    }
434
435    private void UpdateTargetValueFromBestKnownQuality() {
436      var bkParam = Problem.BestKnownQualityParameter as IValueParameter<DoubleValue>;
437      if (bkParam != null && bkParam.Value != null)
438        TargetValueParameter.Value = new DoubleValue(bkParam.Value.Value);
439      else if (bkParam != null && bkParam.Value == null)
440        TargetValueParameter.Value = null;
441    }
442
443    private void AddAlgorithmAnalyzers() {
444      if (Algorithm == null) return;
445      if (!Algorithm.Parameters.ContainsKey("Analyzer")) return;
446      var analyzerParam = Algorithm.Parameters["Analyzer"] as IValueParameter<MultiAnalyzer>;
447      if (analyzerParam != null) {
448        foreach (var analyzer in analyzerParam.Value.Operators.OfType<QualityPerClockAnalyzer>().ToList())
449          analyzerParam.Value.Operators.Remove(analyzer);
450        analyzerParam.Value.Operators.Add(perClockAnalyzer);
451        foreach (var analyzer in analyzerParam.Value.Operators.OfType<QualityPerEvaluationsAnalyzer>().ToList())
452          analyzerParam.Value.Operators.Remove(analyzer);
453        analyzerParam.Value.Operators.Add(perEvaluationsAnalyzer);
454      } else {
455        var analyzerParam2 = Algorithm.Parameters["Analyzer"] as IValueParameter<IMultiAnalyzer>;
456        if (analyzerParam2 == null) return;
457        foreach (var analyzer in analyzerParam2.Value.Operators.OfType<QualityPerClockAnalyzer>().ToList())
458          analyzerParam2.Value.Operators.Remove(analyzer);
459        analyzerParam2.Value.Operators.Add(perClockAnalyzer);
460        foreach (var analyzer in analyzerParam2.Value.Operators.OfType<QualityPerEvaluationsAnalyzer>().ToList())
461          analyzerParam2.Value.Operators.Remove(analyzer);
462        analyzerParam2.Value.Operators.Add(perEvaluationsAnalyzer);
463      }
464    }
465
466    private void RemoveAlgorithmAnalyzers() {
467      if (Algorithm == null) return;
468      if (!Algorithm.Parameters.ContainsKey("Analyzer")) return;
469      var analyzerParam = Algorithm.Parameters["Analyzer"] as IValueParameter<MultiAnalyzer>;
470      if (analyzerParam != null) {
471        analyzerParam.Value.Operators.Remove(perClockAnalyzer);
472        analyzerParam.Value.Operators.Remove(perEvaluationsAnalyzer);
473      } else {
474        var analyzerParam2 = Algorithm.Parameters["Analyzer"] as IValueParameter<IMultiAnalyzer>;
475        if (analyzerParam2 != null) {
476          analyzerParam2.Value.Operators.Remove(perClockAnalyzer);
477          analyzerParam2.Value.Operators.Remove(perEvaluationsAnalyzer);
478        }
479      }
480    }
481
482    #region Event Handlers
483    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
484      OnExceptionOccurred(e.Value);
485    }
486    private void Algorithm_Paused(object sender, EventArgs e) {
487      algorithmWaitHandle.Set();
488    }
489    private void Algorithm_Stopped(object sender, EventArgs e) {
490      algorithmWaitHandle.Set();
491    }
492
493    private void Algorithm_ProblemChanged(object sender, EventArgs e) {
494      if (Algorithm.Problem != Problem) Problem = (ISingleObjectiveHeuristicOptimizationProblem)Algorithm.Problem;
495      AddAlgorithmAnalyzers();
496    }
497
498    private void Problem_BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
499      var param = sender as IValueParameter<DoubleValue>;
500      if (param != null) {
501        if (param.Value != null) param.Value.ValueChanged += Problem_BestKnownQualityParameter_Value_ValueChanged;
502        UpdateTargetValueFromBestKnownQuality();
503      }
504    }
505
506    private void Problem_BestKnownQualityParameter_Value_ValueChanged(object sender, EventArgs e) {
507      UpdateTargetValueFromBestKnownQuality();
508    }
509
510    protected override void Problem_Reset(object sender, EventArgs eventArgs) {
511      if (Algorithm != null) AddAlgorithmAnalyzers();
512    }
513
514    protected override void Problem_OperatorsChanged(object sender, EventArgs eventArgs) {
515      if (Algorithm != null) AddAlgorithmAnalyzers();
516    }
517
518    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
519      System.Timers.Timer timer = (System.Timers.Timer)sender;
520      timer.Enabled = false;
521      DateTime now = DateTime.UtcNow;
522      ExecutionTime += now - lastUpdateTime;
523      lastUpdateTime = now;
524      timer.Enabled = true;
525    }
526    #endregion
527  }
528}
Note: See TracBrowser for help on using the repository browser.