Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Analysis/3.3/MultiObjective/TimelineAnalyzer.cs @ 16310

Last change on this file since 16310 was 16310, checked in by bwerth, 5 years ago

#2943 worked on MOBasicProblem and MOAnalyzers

File size: 3.8 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;
31
32namespace HeuristicLab.Analysis {
33  [StorableClass]
34  [Item("TimelineAnalyzer", "Collects the specified double values from the results and displays them as a timeline")]
35  public class TimelineAnalyzer : SingleSuccessorOperator, IAnalyzer, IMultiObjectiveOperator {
36    public bool EnabledByDefault => true;
37    public string ResultName => "Timeline";
38
39    public IFixedValueParameter<CheckedItemList<StringValue>> CollectedSuccessMeasuresParameter =>
40      (IFixedValueParameter<CheckedItemList<StringValue>>)Parameters["CollectedSuccessMeasures"];
41
42    public ILookupParameter<ResultCollection> ResultsParameter => (ILookupParameter<ResultCollection>)Parameters["Results"];
43
44    public ResultParameter<DataTable> ResultParameter => (ResultParameter<DataTable>)Parameters[ResultName];
45
46    public CheckedItemList<StringValue> CollectedSuccessMeasures => CollectedSuccessMeasuresParameter.Value;
47
48    [StorableConstructor]
49    protected TimelineAnalyzer(bool deserializing) : base(deserializing) { }
50
51
52    protected TimelineAnalyzer(TimelineAnalyzer original, Cloner cloner) : base(original, cloner) { }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new TimelineAnalyzer(this, cloner);
55    }
56
57    public TimelineAnalyzer() {
58      var names = new List<string> {
59        new CrowdingAnalyzer().ResultName,
60        new GenerationalDistanceAnalyzer().ResultName,
61        new InvertedGenerationalDistanceAnalyzer().ResultName,
62        new HypervolumeAnalyzer().ResultName,
63        new SpacingAnalyzer().ResultName
64      };
65      var analyzers = new CheckedItemList<StringValue> (names.Select(n=> new StringValue(n)));
66      Parameters.Add(new FixedValueParameter<CheckedItemList<StringValue>>("CollectedSuccessMeasures",analyzers));
67      Parameters.Add(new LookupParameter<ResultCollection>("Results"));
68      Parameters.Add(new ResultParameter<DataTable>("Timeline", "The development of the success measures over the generations","Results", new DataTable("Timeline","")));
69    }
70
71    public override IOperation Apply() {
72      if (ResultParameter.ActualValue == null) ResultParameter.ActualValue = new DataTable(ResultName,"");
73      var plot = ResultParameter.ActualValue;
74      var resultCollection = ResultsParameter.ActualValue;
75      foreach (var resultName in CollectedSuccessMeasures.CheckedItems.Select(i=>i.Value.Value)) {
76        if(!resultCollection.ContainsKey(resultName)) continue;
77        if(!(resultCollection[resultName].Value is DoubleValue res)) continue;
78        if(!plot.Rows.ContainsKey(resultName)) plot.Rows.Add(new DataRow(resultName));
79        plot.Rows[resultName].Values.Add(res.Value);
80      }
81      return base.Apply();
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.