[3623] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3623] | 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 a value in the scope tree.
|
---|
[3623] | 35 | /// </summary>
|
---|
[8016] | 36 | [Item("ValueAnalyzer", "An operator which analyzes a value in the scope tree (current scope and children).")]
|
---|
[3623] | 37 | [StorableClass]
|
---|
[3662] | 38 | public sealed class ValueAnalyzer : 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<DataTable> ValuesParameter {
|
---|
| 44 | get { return (ValueLookupParameter<DataTable>)Parameters["Values"]; }
|
---|
| 45 | }
|
---|
| 46 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
| 47 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 48 | }
|
---|
| 49 | #endregion
|
---|
| 50 |
|
---|
[3662] | 51 | #region Properties
|
---|
[7172] | 52 | public bool EnabledByDefault {
|
---|
| 53 | get { return true; }
|
---|
| 54 | }
|
---|
[3662] | 55 | private DataTableValuesCollector DataTableValuesCollector {
|
---|
| 56 | get { return (DataTableValuesCollector)OperatorGraph.InitialOperator; }
|
---|
[3623] | 57 | }
|
---|
[3662] | 58 | private ResultsCollector ResultsCollector {
|
---|
| 59 | get { return (ResultsCollector)DataTableValuesCollector.Successor; }
|
---|
| 60 | }
|
---|
| 61 | #endregion
|
---|
[3623] | 62 |
|
---|
[4722] | 63 | #region Storing & Cloning
|
---|
| 64 | [StorableConstructor]
|
---|
| 65 | private ValueAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 66 | private ValueAnalyzer(ValueAnalyzer original, Cloner cloner)
|
---|
| 67 | : base(original, cloner) {
|
---|
[7172] | 68 | Initialize();
|
---|
[4722] | 69 | }
|
---|
| 70 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 71 | return new ValueAnalyzer(this, cloner);
|
---|
| 72 | }
|
---|
| 73 | #endregion
|
---|
[3662] | 74 | public ValueAnalyzer()
|
---|
| 75 | : base() {
|
---|
[3623] | 76 | #region Create parameters
|
---|
[3662] | 77 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", "The value contained in the scope tree which should be analyzed."));
|
---|
[3623] | 78 | Parameters.Add(new ValueLookupParameter<DataTable>("Values", "The data table to store the values."));
|
---|
| 79 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
| 80 | #endregion
|
---|
| 81 |
|
---|
| 82 | #region Create operators
|
---|
| 83 | DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
|
---|
| 84 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
| 85 |
|
---|
[3662] | 86 | dataTableValuesCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", null, ValueParameter.Name));
|
---|
| 87 | ((ScopeTreeLookupParameter<DoubleValue>)dataTableValuesCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
|
---|
| 88 | dataTableValuesCollector.DataTableParameter.ActualName = ValuesParameter.Name;
|
---|
[3623] | 89 |
|
---|
[3662] | 90 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", null, ValueParameter.Name));
|
---|
| 91 | ((ScopeTreeLookupParameter<DoubleValue>)resultsCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
|
---|
| 92 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(ValuesParameter.Name));
|
---|
| 93 | resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
|
---|
[3623] | 94 | #endregion
|
---|
| 95 |
|
---|
| 96 | #region Create operator graph
|
---|
| 97 | OperatorGraph.InitialOperator = dataTableValuesCollector;
|
---|
| 98 | dataTableValuesCollector.Successor = resultsCollector;
|
---|
| 99 | resultsCollector.Successor = null;
|
---|
| 100 | #endregion
|
---|
[3662] | 101 |
|
---|
| 102 | Initialize();
|
---|
[3623] | 103 | }
|
---|
[3662] | 104 |
|
---|
| 105 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 106 | private void AfterDeserialization() {
|
---|
| 107 | Initialize();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[3662] | 110 | private void Initialize() {
|
---|
| 111 | ValueParameter.DepthChanged += new EventHandler(ValueParameter_DepthChanged);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | private void ValueParameter_DepthChanged(object sender, System.EventArgs e) {
|
---|
| 115 | ((ScopeTreeLookupParameter<DoubleValue>)DataTableValuesCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
|
---|
| 116 | ((ScopeTreeLookupParameter<DoubleValue>)ResultsCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
|
---|
| 117 | }
|
---|
[3623] | 118 | }
|
---|
| 119 | }
|
---|