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 | using HEAL.Attic;
|
---|
32 |
|
---|
33 | namespace 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 | } |
---|