Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs @ 13495

Last change on this file since 13495 was 13480, checked in by bburlacu, 9 years ago

#1772: Schema diversification strategy: implement adaptive replacement ratio and added number of evaluated solutions per generation to the diversification statistics operator

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Analysis;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [Item("SchemaCleanupOperator", "Operator which removes the schemas from the global scope after they have been evaluated.")]
33  [StorableClass]
34  public class DiversificationStatisticsOperator : SingleSuccessorOperator {
35    private const string NumberOfChangedTreesParameterName = "NumberOfChangedTrees";
36    private const string NumberOfSchemasParameterName = "NumberOfSchemas";
37    private const string AverageSchemaLengthParameterName = "AverageSchemaLength";
38    private const string ResultCollectionParameterName = "Results";
39    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
40
41    public ILookupParameter<IntValue> NumberOfChangedTreesParameter {
42      get { return (ILookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; }
43    }
44    public ILookupParameter<IntValue> NumberOfSchemasParameter {
45      get { return (ILookupParameter<IntValue>)Parameters[NumberOfSchemasParameterName]; }
46    }
47    public ILookupParameter<DoubleValue> AverageSchemaLengthParameter {
48      get { return (ILookupParameter<DoubleValue>)Parameters[AverageSchemaLengthParameterName]; }
49    }
50    public ILookupParameter<ResultCollection> ResultCollectionParameter {
51      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
52    }
53    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
54      get { return (ILookupParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
55    }
56
57    private int evaluatedSolutionsTracker;
58
59    public DiversificationStatisticsOperator() {
60      Parameters.Add(new LookupParameter<IntValue>(NumberOfChangedTreesParameterName));
61      Parameters.Add(new LookupParameter<IntValue>(NumberOfSchemasParameterName));
62      Parameters.Add(new LookupParameter<DoubleValue>(AverageSchemaLengthParameterName));
63      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));
64      Parameters.Add(new LookupParameter<IntValue>(EvaluatedSolutionsParameterName));
65    }
66
67    public override void ClearState() {
68      evaluatedSolutionsTracker = 0;
69      base.ClearState();
70    }
71
72    protected DiversificationStatisticsOperator(DiversificationStatisticsOperator original, Cloner cloner) : base(original, cloner) { }
73
74    public override IDeepCloneable Clone(Cloner cloner) { return new DiversificationStatisticsOperator(this, cloner); }
75
76    [StorableConstructor]
77    protected DiversificationStatisticsOperator(bool deserializing) : base(deserializing) { }
78
79    public override IOperation Apply() {
80      var results = ResultCollectionParameter.ActualValue;
81      DataTable table;
82      if (!results.ContainsKey("NumberOfChangedTrees")) {
83        table = new DataTable();
84        results.Add(new Result("NumberOfChangedTrees", table));
85        var row = new DataRow("Changed trees");
86        table.Rows.Add(row);
87      }
88      if (!results.ContainsKey("AverageSchemaLength")) {
89        table = new DataTable();
90        results.Add(new Result("AverageSchemaLength", table));
91        var row = new DataRow("Average schema length");
92        table.Rows.Add(row);
93      }
94      if (!results.ContainsKey("NumberOfSchemas")) {
95        table = new DataTable();
96        results.Add(new Result("NumberOfSchemas", table));
97        var row = new DataRow("Number of schemas");
98        table.Rows.Add(row);
99      }
100      if (!results.ContainsKey("EvaluatedSolutionsPerGeneration")) {
101        table = new DataTable();
102        results.Add(new Result("EvaluatedSolutionsPerGeneration", table));
103        var row = new DataRow("Evaluated solutions");
104        table.Rows.Add(row);
105        row.Values.Add(0);
106      }
107
108      var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value - evaluatedSolutionsTracker;
109      ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value);
110      ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value);
111      ((DataTable)results["NumberOfSchemas"].Value).Rows["Number of schemas"].Values.Add(NumberOfSchemasParameter.ActualValue.Value);
112      ((DataTable)results["EvaluatedSolutionsPerGeneration"].Value).Rows["Evaluated solutions"].Values.Add(evaluatedSolutions);
113      evaluatedSolutionsTracker += evaluatedSolutions;
114
115      return base.Apply();
116    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.