Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/MultiObjective/TimelineAnalyzer.cs @ 17225

Last change on this file since 17225 was 17225, checked in by mkommend, 5 years ago

#2521: Integrated changes of #2943 into problem refactoring branch.

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HEAL.Attic;
32
33namespace HeuristicLab.Analysis {
34  [StorableType("48fc7ff7-a8ab-4ef9-8c01-cc6fbbe3da0b")]
35  [Item("TimelineAnalyzer", "Collects the specified double values from the results and displays them as a timeline")]
36  public class TimelineAnalyzer : SingleSuccessorOperator, IAnalyzer, IMultiObjectiveOperator {
37    public bool EnabledByDefault {
38      get { return true; }
39    }
40    public string ResultName {
41      get { return "Timeline"; }
42    }
43
44    public IFixedValueParameter<CheckedItemList<StringValue>> CollectedSuccessMeasuresParameter {
45      get { return (IFixedValueParameter<CheckedItemList<StringValue>>)Parameters["CollectedSuccessMeasures"]; }
46    }
47
48    public ILookupParameter<ResultCollection> ResultsParameter {
49      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
50    }
51
52    public ResultParameter<DataTable> ResultParameter {
53      get { return (ResultParameter<DataTable>)Parameters[ResultName]; }
54    }
55
56    public CheckedItemList<StringValue> CollectedSuccessMeasures {
57      get { return CollectedSuccessMeasuresParameter.Value; }
58    }
59
60    [StorableConstructor]
61    protected TimelineAnalyzer(StorableConstructorFlag _) : base(_) { }
62
63
64    protected TimelineAnalyzer(TimelineAnalyzer original, Cloner cloner) : base(original, cloner) { }
65    public override IDeepCloneable Clone(Cloner cloner) {
66      return new TimelineAnalyzer(this, cloner);
67    }
68
69    public TimelineAnalyzer() {
70      var names = new List<string> {
71        new CrowdingAnalyzer().ResultName,
72        new GenerationalDistanceAnalyzer().ResultName,
73        new InvertedGenerationalDistanceAnalyzer().ResultName,
74        new HypervolumeAnalyzer().ResultName,
75        new SpacingAnalyzer().ResultName
76      };
77      var analyzers = new CheckedItemList<StringValue>(names.Select(n => new StringValue(n)));
78      Parameters.Add(new FixedValueParameter<CheckedItemList<StringValue>>("CollectedSuccessMeasures", analyzers));
79      Parameters.Add(new LookupParameter<ResultCollection>("Results"));
80      Parameters.Add(new ResultParameter<DataTable>("Timeline", "The development of the success measures over the generations", "Results", new DataTable("Timeline", "")));
81    }
82
83    public override IOperation Apply() {
84      if (ResultParameter.ActualValue == null) ResultParameter.ActualValue = new DataTable(ResultName, "");
85      var plot = ResultParameter.ActualValue;
86      var resultCollection = ResultsParameter.ActualValue;
87      foreach (var resultName in CollectedSuccessMeasures.CheckedItems.Select(i => i.Value.Value)) {
88        if (!resultCollection.ContainsKey(resultName)) continue;
89        var res = resultCollection[resultName].Value as DoubleValue;
90        if (res == null) continue;
91        if (!plot.Rows.ContainsKey(resultName)) plot.Rows.Add(new DataRow(resultName));
92        plot.Rows[resultName].Values.Add(res.Value);
93      }
94      return base.Apply();
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.