Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13496 was 13496, checked in by bburlacu, 8 years ago

#1772: Update diversification operators (add extra evaluations to the evaluation counter, add the option for strict schema matching, add additional replacement ratio update rules.

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