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 |
|
---|
22 | using HeuristicLab.Analysis;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Optimization.Operators;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Algorithms.RAPGA {
|
---|
33 | /// <summary>
|
---|
34 | /// An operator which analyzes the size of the population in a scope tree.
|
---|
35 | /// </summary>
|
---|
36 | [Item("PopulationSizeAnalyzer", "An operator which analyzes the size of the population in a scope tree.")]
|
---|
37 | [StorableClass]
|
---|
38 | public sealed class PopulationSizeAnalyzer : AlgorithmOperator, IAnalyzer {
|
---|
39 | #region Parameter properties
|
---|
40 | public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
|
---|
41 | get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; }
|
---|
42 | }
|
---|
43 | public ILookupParameter<IntValue> MaximumPopulationSizeParameter {
|
---|
44 | get { return (ILookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
|
---|
45 | }
|
---|
46 | public ILookupParameter<IntValue> MinimumPopulationSizeParameter {
|
---|
47 | get { return (ILookupParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
|
---|
48 | }
|
---|
49 | public IValueLookupParameter<DataTable> PopulationSizesParameter {
|
---|
50 | get { return (IValueLookupParameter<DataTable>)Parameters["PopulationSizes"]; }
|
---|
51 | }
|
---|
52 | public IValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
53 | get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
54 | }
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region Properties
|
---|
58 | public bool EnabledByDefault {
|
---|
59 | get { return true; }
|
---|
60 | }
|
---|
61 | private DataTableValuesCollector DataTableValuesCollector {
|
---|
62 | get { return (DataTableValuesCollector)OperatorGraph.InitialOperator; }
|
---|
63 | }
|
---|
64 | private ResultsCollector ResultsCollector {
|
---|
65 | get { return (ResultsCollector)DataTableValuesCollector.Successor; }
|
---|
66 | }
|
---|
67 | #endregion
|
---|
68 |
|
---|
69 | #region Storing & Cloning
|
---|
70 | [StorableConstructor]
|
---|
71 | private PopulationSizeAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
72 | private PopulationSizeAnalyzer(PopulationSizeAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
73 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
74 | return new PopulationSizeAnalyzer(this, cloner);
|
---|
75 | }
|
---|
76 | #endregion
|
---|
77 | public PopulationSizeAnalyzer()
|
---|
78 | : base() {
|
---|
79 | #region Create parameters
|
---|
80 | Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population in the scope tree which should be analyzed."));
|
---|
81 | Parameters.Add(new LookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population in the scope tree which should be analyzed."));
|
---|
82 | Parameters.Add(new LookupParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population in the scope tree which should be analyzed."));
|
---|
83 | Parameters.Add(new ValueLookupParameter<DataTable>("PopulationSizes", "The data table to store the values."));
|
---|
84 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
85 | #endregion
|
---|
86 |
|
---|
87 | #region Create operators
|
---|
88 | DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
|
---|
89 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
90 |
|
---|
91 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize", null, CurrentPopulationSizeParameter.Name));
|
---|
92 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("MaximumPopulationSize", null, MaximumPopulationSizeParameter.Name));
|
---|
93 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("MinimumPopulationSize", null, MinimumPopulationSizeParameter.Name));
|
---|
94 | dataTableValuesCollector.DataTableParameter.ActualName = PopulationSizesParameter.Name;
|
---|
95 |
|
---|
96 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(PopulationSizesParameter.Name));
|
---|
97 | resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
|
---|
98 | #endregion
|
---|
99 |
|
---|
100 | #region Create operator graph
|
---|
101 | OperatorGraph.InitialOperator = dataTableValuesCollector;
|
---|
102 | dataTableValuesCollector.Successor = resultsCollector;
|
---|
103 | resultsCollector.Successor = null;
|
---|
104 | #endregion
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|