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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 |
|
---|
32 | namespace 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 | }
|
---|