Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/QualityTrailMultiAnalyzer.cs @ 14614

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

#2457:

  • Added stripped-down version of FLA branch
  • Added appropriate calculators
  • Fixed detecting maximization in RLD view
File size: 5.2 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.PluginInfrastructure;
30using System.Linq;
31
32namespace HeuristicLab.Analysis.FitnessLandscape {
33  [Item("QualityTrailAnalyzer", "An analyzer that creates a quality trail which can be further analyzed by several analyzers.")]
34  [StorableClass]
35  public class QualityTrailMultiAnalyzer : CheckedMultiOperator<IQualityTrailAnalyzer>, IAnalyzer {
36    public bool EnabledByDefault {
37      get { return false; }
38    }
39
40    public override bool CanChangeName {
41      get { return false; }
42    }
43
44    public IValueLookupParameter<IntValue> UpdateIntervalParameter {
45      get { return (IValueLookupParameter<IntValue>)Parameters["QualityTrailUpdateInterval"]; }
46    }
47    public ILookupParameter<IntValue> UpdateCounterParameter {
48      get { return (ILookupParameter<IntValue>)Parameters["QualityTrailUpdateCounter"]; }
49    }
50    public ILookupParameter<DataTable> QualityTrailParameter {
51      get { return (ILookupParameter<DataTable>)Parameters["Quality Trail"]; }
52    }
53    public ILookupParameter<ResultCollection> ResultsParameter {
54      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
55    }
56    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
57      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
58    }
59    public ILookupParameter<BoolValue> MaximizationParameter {
60      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
61    }
62
63    public IntValue UpdateInterval {
64      get { return UpdateIntervalParameter.Value; }
65      set { UpdateIntervalParameter.Value = value; }
66    }
67
68    [StorableConstructor]
69    protected QualityTrailMultiAnalyzer(bool deserializing) : base(deserializing) { }
70    protected QualityTrailMultiAnalyzer(QualityTrailMultiAnalyzer original, Cloner cloner) : base(original, cloner) { }
71    public QualityTrailMultiAnalyzer()
72      : base() {
73      Parameters.Add(new ValueLookupParameter<IntValue>("QualityTrailUpdateInterval", "The interval at which the contained analyzers should be applied.", new IntValue(1)));
74      Parameters.Add(new LookupParameter<IntValue>("QualityTrailUpdateCounter", "The number of times the Analyzer was called since the last update."));
75      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "All historical quality values throughout the algorithm run"));
76      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "Quality values of the whole population", 1));
77      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collected results"));
78      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem"));
79
80      foreach (var analyzer in ApplicationManager.Manager.GetInstances<IQualityTrailAnalyzer>()) {
81        Operators.Add(analyzer, !(analyzer is FitnessCloudAnalyzer));
82      }
83    }
84
85    public override IDeepCloneable Clone(Cloner cloner) {
86      return new QualityTrailMultiAnalyzer(this, cloner);
87    }
88
89    public override IOperation InstrumentedApply() {
90      var maximization = MaximizationParameter.ActualValue.Value;
91      var qualityTrail = QualityTrailParameter.ActualValue;
92      if (qualityTrail == null) {
93        qualityTrail = new DataTable("Quality Trail");
94        qualityTrail.Rows.Add(new DataRow("Qualities"));
95        QualityTrailParameter.ActualValue = qualityTrail;
96      }
97      var qualities = QualityParameter.ActualValue.Select(x => x.Value);
98      qualityTrail.Rows["Qualities"].Values.Add(maximization ? qualities.Max() : qualities.Min());
99
100      var interval = UpdateIntervalParameter.ActualValue.Value;
101      var counter = UpdateCounterParameter.ActualValue;
102      if (counter == null) {
103        counter = new IntValue(0);
104        UpdateCounterParameter.ActualValue = counter;
105      }
106      counter.Value++;
107
108      var next = new OperationCollection();
109      if (counter.Value % interval == 0) {
110        counter.Value = 0;
111        foreach (var item in Operators.CheckedItems) next.Add(ExecutionContext.CreateOperation(item.Value));
112      }
113      next.Add(base.InstrumentedApply());
114      return next;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.