Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/DataTableValuesCollector.cs @ 3623

Last change on this file since 3623 was 3489, checked in by abeham, 15 years ago

updated SASEGASA #839
changed DataTableValuesCollector to plot IEnumerable<DoubleValue>
removed IMigrator from SASEGASAReunificator

File size: 3.1 KB
RevLine 
[2908]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
22using System;
[3489]23using System.Collections.Generic;
[3376]24using HeuristicLab.Common;
[2908]25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Analysis {
32  /// <summary>
33  /// An operator which collects the actual values of parameters and adds them to a table of data values.
34  /// </summary>
35  [Item("DataTableValuesCollector", "An operator which collects the actual values of parameters and adds them to a table of data values.")]
[3017]36  [StorableClass]
[2908]37  public class DataTableValuesCollector : ValuesCollector {
38    public ValueLookupParameter<DataTable> DataTableParameter {
39      get { return (ValueLookupParameter<DataTable>)Parameters["DataTable"]; }
40    }
41
42    public DataTableValuesCollector()
43      : base() {
44      Parameters.Add(new ValueLookupParameter<DataTable>("DataTable", "The table of data values where the collected values should be stored."));
45    }
46
47    public override IOperation Apply() {
48      DataTable table = DataTableParameter.ActualValue;
49      if (table == null) {
50        table = new DataTable(DataTableParameter.ActualName);
51        DataTableParameter.ActualValue = table;
52      }
53
54      foreach (IParameter param in CollectedValues) {
[3479]55        if (param.ActualValue is DoubleValue) {
[3489]56          AddValue(table, (param.ActualValue as DoubleValue).Value, param.Name, param.Description);
57        } else if (param.ActualValue is IEnumerable<DoubleValue>) {
58          int counter = 0;
59          foreach (DoubleValue data in (param.ActualValue as IEnumerable<DoubleValue>)) {
60            AddValue(table, data.Value, param.Name + counter.ToString(), param.Description);
61            counter++;
[3479]62          }
[2908]63        } else {
[3489]64          AddValue(table, double.NaN, param.Name, param.Description);
[2908]65        }
66      }
67      return base.Apply();
68    }
[3489]69
70    private void AddValue(DataTable table, double data, string name, string description) {
71      DataRow row;
72      table.Rows.TryGetValue(name, out row);
73      if (row == null) {
74        row = new DataRow(name, description);
75        row.Values.Add(data);
76        table.Rows.Add(row);
77      } else {
78        row.Values.Add(data);
79      }
80    }
[2908]81  }
82}
Note: See TracBrowser for help on using the repository browser.