[3623] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
[3662] | 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
[3623] | 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.Analysis {
|
---|
| 33 | /// <summary>
|
---|
[3662] | 34 | /// An operator which analyzes the minimum, average and maximum of a value in the scope tree.
|
---|
[3623] | 35 | /// </summary>
|
---|
[3662] | 36 | [Item("MinAverageMaxValueAnalyzer", "An operator which analyzes the minimum, average and maximum of a value in the scope tree.")]
|
---|
[3623] | 37 | [StorableClass]
|
---|
[3662] | 38 | public sealed class MinAverageMaxValueAnalyzer : AlgorithmOperator, IAnalyzer {
|
---|
[3623] | 39 | #region Parameter properties
|
---|
[3659] | 40 | public ScopeTreeLookupParameter<DoubleValue> ValueParameter {
|
---|
| 41 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Value"]; }
|
---|
[3623] | 42 | }
|
---|
| 43 | public ValueLookupParameter<DoubleValue> MinValueParameter {
|
---|
| 44 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MinValue"]; }
|
---|
| 45 | }
|
---|
| 46 | public ValueLookupParameter<DoubleValue> AverageValueParameter {
|
---|
| 47 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageValue"]; }
|
---|
| 48 | }
|
---|
| 49 | public ValueLookupParameter<DoubleValue> MaxValueParameter {
|
---|
| 50 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MaxValue"]; }
|
---|
| 51 | }
|
---|
| 52 | public ValueLookupParameter<DataTable> ValuesParameter {
|
---|
| 53 | get { return (ValueLookupParameter<DataTable>)Parameters["Values"]; }
|
---|
| 54 | }
|
---|
| 55 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
| 56 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 57 | }
|
---|
[3710] | 58 | public ValueParameter<BoolValue> CollectMinValueInResultsParameter {
|
---|
| 59 | get { return (ValueParameter<BoolValue>)Parameters["CollectMinValueInResults"]; }
|
---|
| 60 | }
|
---|
| 61 | public ValueParameter<BoolValue> CollectMaxValueInResultsParameter {
|
---|
| 62 | get { return (ValueParameter<BoolValue>)Parameters["CollectMaxValueInResults"]; }
|
---|
| 63 | }
|
---|
| 64 | public ValueParameter<BoolValue> CollectAverageValueInResultsParameter {
|
---|
| 65 | get { return (ValueParameter<BoolValue>)Parameters["CollectAverageValueInResults"]; }
|
---|
| 66 | }
|
---|
[3623] | 67 | #endregion
|
---|
| 68 |
|
---|
[3662] | 69 | #region Properties
|
---|
| 70 | private MinAverageMaxValueCalculator MinAverageMaxValueCalculator {
|
---|
| 71 | get { return (MinAverageMaxValueCalculator)OperatorGraph.InitialOperator; }
|
---|
[3623] | 72 | }
|
---|
[3710] | 73 | private BoolValue CollectMinValueInResults {
|
---|
| 74 | get { return CollectMinValueInResultsParameter.Value; }
|
---|
| 75 | }
|
---|
| 76 | private BoolValue CollectMaxValueInResults {
|
---|
| 77 | get { return CollectMaxValueInResultsParameter.Value; }
|
---|
| 78 | }
|
---|
| 79 | private BoolValue CollectAverageValueInResults {
|
---|
| 80 | get { return CollectAverageValueInResultsParameter.Value; }
|
---|
| 81 | }
|
---|
[3662] | 82 | #endregion
|
---|
[3710] | 83 | [Storable]
|
---|
| 84 | private ResultsCollector resultsCollector;
|
---|
[3662] | 85 | public MinAverageMaxValueAnalyzer()
|
---|
| 86 | : base() {
|
---|
[3623] | 87 | #region Create parameters
|
---|
[3662] | 88 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", "The value contained in the scope tree which should be analyzed."));
|
---|
[3623] | 89 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MinValue", "The minimum of the value."));
|
---|
[3710] | 90 | Parameters.Add(new ValueParameter<BoolValue>("CollectMinValueInResults", "Determines if the minimum of the value should also be stored in the results.", new BoolValue(true)));
|
---|
[3623] | 91 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageValue", "The average of the value."));
|
---|
[3710] | 92 | Parameters.Add(new ValueParameter<BoolValue>("CollectAverageValueInResults", "Determines if the average of the value should also be stored in the results.", new BoolValue(true)));
|
---|
[3623] | 93 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxValue", "The maximum of the value."));
|
---|
[3710] | 94 | Parameters.Add(new ValueParameter<BoolValue>("CollectMaxValueInResults", "Determines if the maximum of the value should also be stored in the results.", new BoolValue(true)));
|
---|
[3623] | 95 | Parameters.Add(new ValueLookupParameter<DataTable>("Values", "The data table to store the minimum, average and maximum of the value."));
|
---|
| 96 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
| 97 | #endregion
|
---|
| 98 |
|
---|
| 99 | #region Create operators
|
---|
| 100 | MinAverageMaxValueCalculator minAverageMaxValueCalculator = new MinAverageMaxValueCalculator();
|
---|
| 101 | DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
|
---|
[3710] | 102 | resultsCollector = new ResultsCollector();
|
---|
[3623] | 103 |
|
---|
[3662] | 104 | minAverageMaxValueCalculator.AverageValueParameter.ActualName = AverageValueParameter.Name;
|
---|
| 105 | minAverageMaxValueCalculator.MaxValueParameter.ActualName = MaxValueParameter.Name;
|
---|
| 106 | minAverageMaxValueCalculator.MinValueParameter.ActualName = MinValueParameter.Name;
|
---|
| 107 | minAverageMaxValueCalculator.ValueParameter.ActualName = ValueParameter.Name;
|
---|
| 108 | minAverageMaxValueCalculator.ValueParameter.Depth = ValueParameter.Depth;
|
---|
[3623] | 109 |
|
---|
[3662] | 110 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MinValue", null, MinValueParameter.Name));
|
---|
| 111 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("AverageValue", null, AverageValueParameter.Name));
|
---|
| 112 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MaxValue", null, MaxValueParameter.Name));
|
---|
| 113 | dataTableValuesCollector.DataTableParameter.ActualName = ValuesParameter.Name;
|
---|
[3623] | 114 |
|
---|
[3710] | 115 | if (CollectMinValueInResults.Value)
|
---|
| 116 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MinValue", null, MinValueParameter.Name));
|
---|
| 117 | if (CollectAverageValueInResults.Value)
|
---|
| 118 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("AverageValue", null, AverageValueParameter.Name));
|
---|
| 119 | if (CollectMaxValueInResults.Value)
|
---|
| 120 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MaxValue", null, MaxValueParameter.Name));
|
---|
[3662] | 121 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(ValuesParameter.Name));
|
---|
| 122 | resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
|
---|
[3623] | 123 | #endregion
|
---|
| 124 |
|
---|
| 125 | #region Create operator graph
|
---|
| 126 | OperatorGraph.InitialOperator = minAverageMaxValueCalculator;
|
---|
| 127 | minAverageMaxValueCalculator.Successor = dataTableValuesCollector;
|
---|
| 128 | dataTableValuesCollector.Successor = resultsCollector;
|
---|
| 129 | resultsCollector.Successor = null;
|
---|
| 130 | #endregion
|
---|
[3662] | 131 |
|
---|
| 132 | Initialize();
|
---|
[3623] | 133 | }
|
---|
[3662] | 134 | [StorableConstructor]
|
---|
| 135 | private MinAverageMaxValueAnalyzer(bool deserializing) : base() { }
|
---|
| 136 |
|
---|
| 137 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 138 | private void Initialize() {
|
---|
| 139 | ValueParameter.DepthChanged += new EventHandler(ValueParameter_DepthChanged);
|
---|
[3710] | 140 | CollectMinValueInResultsParameter.ValueChanged += new EventHandler(CollectMinValueInResultsParameter_ValueChanged);
|
---|
| 141 | CollectMinValueInResultsParameter.Value.ValueChanged += new EventHandler(CollectMinValueInResultsParameter_ValueChanged);
|
---|
| 142 | CollectMaxValueInResultsParameter.ValueChanged += new EventHandler(CollectMaxValueInResultsParameter_ValueChanged);
|
---|
| 143 | CollectMaxValueInResultsParameter.Value.ValueChanged += new EventHandler(CollectMaxValueInResultsParameter_ValueChanged);
|
---|
| 144 | CollectAverageValueInResultsParameter.ValueChanged += new EventHandler(CollectAverageValueInResultsParameter_ValueChanged);
|
---|
| 145 | CollectAverageValueInResultsParameter.Value.ValueChanged += new EventHandler(CollectAverageValueInResultsParameter_ValueChanged);
|
---|
[3662] | 146 | }
|
---|
| 147 |
|
---|
[3710] | 148 | private void CollectAverageValueInResultsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 149 | if (CollectAverageValueInResults.Value)
|
---|
| 150 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("AverageValue", null, AverageValueParameter.Name));
|
---|
| 151 | else {
|
---|
| 152 | IParameter avgValueParameter;
|
---|
| 153 | resultsCollector.CollectedValues.TryGetValue("AverageValue", out avgValueParameter);
|
---|
| 154 | resultsCollector.CollectedValues.Remove(avgValueParameter);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | private void CollectMaxValueInResultsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 159 | if (CollectMaxValueInResults.Value)
|
---|
| 160 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MaxValue", null, MaxValueParameter.Name));
|
---|
| 161 | else {
|
---|
| 162 | IParameter maxValueParameter;
|
---|
| 163 | resultsCollector.CollectedValues.TryGetValue("MaxValue", out maxValueParameter);
|
---|
| 164 | resultsCollector.CollectedValues.Remove(maxValueParameter);
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | private void CollectMinValueInResultsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 169 | if (CollectMinValueInResults.Value)
|
---|
| 170 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("MinValue", null, MinValueParameter.Name));
|
---|
| 171 | else {
|
---|
| 172 | IParameter minValueParameter;
|
---|
| 173 | resultsCollector.CollectedValues.TryGetValue("MinValue", out minValueParameter);
|
---|
| 174 | resultsCollector.CollectedValues.Remove(minValueParameter);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[3662] | 178 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 179 | MinAverageMaxValueAnalyzer clone = (MinAverageMaxValueAnalyzer)base.Clone(cloner);
|
---|
| 180 | clone.Initialize();
|
---|
| 181 | return clone;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | private void ValueParameter_DepthChanged(object sender, System.EventArgs e) {
|
---|
| 185 | MinAverageMaxValueCalculator.ValueParameter.Depth = ValueParameter.Depth;
|
---|
| 186 | }
|
---|
[3623] | 187 | }
|
---|
| 188 | }
|
---|