Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/ValueAnalyzer.cs @ 3662

Last change on this file since 3662 was 3662, checked in by swagner, 15 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • adapted analyzers
File size: 4.7 KB
RevLine 
[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]22using System;
23using HeuristicLab.Common;
[3623]24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Analysis {
33  /// <summary>
[3662]34  /// An operator which analyzes a value in the scope tree.
[3623]35  /// </summary>
[3662]36  [Item("ValueAnalyzer", "An operator which analyzes a value in the scope tree.")]
[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
52    private DataTableValuesCollector DataTableValuesCollector {
53      get { return (DataTableValuesCollector)OperatorGraph.InitialOperator; }
[3623]54    }
[3662]55    private ResultsCollector ResultsCollector {
56      get { return (ResultsCollector)DataTableValuesCollector.Successor; }
57    }
58    #endregion
[3623]59
[3662]60    public ValueAnalyzer()
61      : base() {
[3623]62      #region Create parameters
[3662]63      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", "The value contained in the scope tree which should be analyzed."));
[3623]64      Parameters.Add(new ValueLookupParameter<DataTable>("Values", "The data table to store the values."));
65      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
66      #endregion
67
68      #region Create operators
69      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
70      ResultsCollector resultsCollector = new ResultsCollector();
71
[3662]72      dataTableValuesCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", null, ValueParameter.Name));
73      ((ScopeTreeLookupParameter<DoubleValue>)dataTableValuesCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
74      dataTableValuesCollector.DataTableParameter.ActualName = ValuesParameter.Name;
[3623]75
[3662]76      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Value", null, ValueParameter.Name));
77      ((ScopeTreeLookupParameter<DoubleValue>)resultsCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
78      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(ValuesParameter.Name));
79      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
[3623]80      #endregion
81
82      #region Create operator graph
83      OperatorGraph.InitialOperator = dataTableValuesCollector;
84      dataTableValuesCollector.Successor = resultsCollector;
85      resultsCollector.Successor = null;
86      #endregion
[3662]87
88      Initialize();
[3623]89    }
[3662]90    [StorableConstructor]
91    private ValueAnalyzer(bool deserializing) : base() { }
92
93    [StorableHook(HookType.AfterDeserialization)]
94    private void Initialize() {
95      ValueParameter.DepthChanged += new EventHandler(ValueParameter_DepthChanged);
96    }
97
98    public override IDeepCloneable Clone(Cloner cloner) {
99      ValueAnalyzer clone = (ValueAnalyzer)base.Clone(cloner);
100      clone.Initialize();
101      return clone;
102    }
103
104    private void ValueParameter_DepthChanged(object sender, System.EventArgs e) {
105      ((ScopeTreeLookupParameter<DoubleValue>)DataTableValuesCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
106      ((ScopeTreeLookupParameter<DoubleValue>)ResultsCollector.CollectedValues["Value"]).Depth = ValueParameter.Depth;
107    }
[3623]108  }
109}
Note: See TracBrowser for help on using the repository browser.