[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] | 22 | using HeuristicLab.Analysis;
|
---|
[12951] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[12988] | 25 | using HeuristicLab.Data;
|
---|
[12951] | 26 | using HeuristicLab.Operators;
|
---|
[12988] | 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
[12951] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[12958] | 31 | namespace 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 |
|
---|
[13527] | 69 | public override void InitializeState() {
|
---|
| 70 | base.InitializeState();
|
---|
| 71 | evaluatedSolutionsTracker = 0;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[13480] | 74 | public override void ClearState() {
|
---|
[13527] | 75 | base.ClearState();
|
---|
[13480] | 76 | evaluatedSolutionsTracker = 0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[12988] | 79 | protected DiversificationStatisticsOperator(DiversificationStatisticsOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 80 |
|
---|
| 81 | public override IDeepCloneable Clone(Cloner cloner) { return new DiversificationStatisticsOperator(this, cloner); }
|
---|
| 82 |
|
---|
[12951] | 83 | [StorableConstructor]
|
---|
[12988] | 84 | protected DiversificationStatisticsOperator(bool deserializing) : base(deserializing) { }
|
---|
[12951] | 85 |
|
---|
| 86 | public override IOperation Apply() {
|
---|
[12988] | 87 | var results = ResultCollectionParameter.ActualValue;
|
---|
| 88 | DataTable table;
|
---|
| 89 | if (!results.ContainsKey("NumberOfChangedTrees")) {
|
---|
| 90 | table = new DataTable();
|
---|
| 91 | results.Add(new Result("NumberOfChangedTrees", table));
|
---|
[13496] | 92 | var row = new DataRow("Changed trees") { VisualProperties = { StartIndexZero = true } };
|
---|
[12988] | 93 | table.Rows.Add(row);
|
---|
[12951] | 94 | }
|
---|
[12988] | 95 | if (!results.ContainsKey("AverageSchemaLength")) {
|
---|
| 96 | table = new DataTable();
|
---|
| 97 | results.Add(new Result("AverageSchemaLength", table));
|
---|
[13496] | 98 | var row = new DataRow("Average schema length") { VisualProperties = { StartIndexZero = true } };
|
---|
[12988] | 99 | table.Rows.Add(row);
|
---|
| 100 | }
|
---|
| 101 | if (!results.ContainsKey("NumberOfSchemas")) {
|
---|
| 102 | table = new DataTable();
|
---|
| 103 | results.Add(new Result("NumberOfSchemas", table));
|
---|
[13496] | 104 | var row = new DataRow("Number of schemas") { VisualProperties = { StartIndexZero = true } };
|
---|
[12988] | 105 | table.Rows.Add(row);
|
---|
| 106 | }
|
---|
[13480] | 107 | if (!results.ContainsKey("EvaluatedSolutionsPerGeneration")) {
|
---|
| 108 | table = new DataTable();
|
---|
| 109 | results.Add(new Result("EvaluatedSolutionsPerGeneration", table));
|
---|
[13496] | 110 | var row = new DataRow("Evaluated solutions") { VisualProperties = { StartIndexZero = true } };
|
---|
[13480] | 111 | table.Rows.Add(row);
|
---|
| 112 | row.Values.Add(0);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[13496] | 115 | lock (locker) {
|
---|
| 116 | // count the extra evaluations performed after diversification
|
---|
| 117 | EvaluatedSolutionsParameter.ActualValue.Value += NumberOfChangedTreesParameter.ActualValue.Value;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value;
|
---|
| 121 | if (evaluatedSolutions > 0)
|
---|
| 122 | evaluatedSolutions -= evaluatedSolutionsTracker;
|
---|
[12988] | 123 | ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value);
|
---|
| 124 | ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value);
|
---|
| 125 | ((DataTable)results["NumberOfSchemas"].Value).Rows["Number of schemas"].Values.Add(NumberOfSchemasParameter.ActualValue.Value);
|
---|
[13480] | 126 | ((DataTable)results["EvaluatedSolutionsPerGeneration"].Value).Rows["Evaluated solutions"].Values.Add(evaluatedSolutions);
|
---|
| 127 | evaluatedSolutionsTracker += evaluatedSolutions;
|
---|
[12988] | 128 |
|
---|
[12951] | 129 | return base.Apply();
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | }
|
---|