Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/ResultNamesCollector.cs @ 7210

Last change on this file since 7210 was 7208, checked in by epitzer, 13 years ago

#1696: Add ResultNamesCollector for easier configuration of BoxCharts

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Optimization;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Data;
10
11namespace HeuristicLab.Analysis.FitnessLandscape.BoxChart {
12  [Item("Result Names Collector", "Collects all occuring names of parameters and results in the currenly visible runs")]
13  [StorableClass]
14  public class ResultNamesCollector : ParameterizedNamedItem, IRunCollectionModifier {
15
16    #region Construction & Cloning
17
18    [StorableConstructor]
19    protected ResultNamesCollector(bool deserializing) : base(deserializing) {}
20
21    protected ResultNamesCollector(ResultNamesCollector original, Cloner cloner) : base(original, cloner) {}
22    public ResultNamesCollector() {}
23
24    public override IDeepCloneable Clone(Cloner cloner) {
25      return new ResultNamesCollector(this, cloner);
26    }
27
28    #endregion
29
30    #region IRunCollectionModifier Members
31
32    public void Modify(List<IRun> runs) {
33      var resultNames = new HashSet<string>();
34      var parameterNames = new HashSet<string>();
35      foreach (var run in runs) {
36        foreach (var name in run.Parameters.Select(p => p.Key))
37          parameterNames.Add(name);
38        foreach (var name in run.Results.Select(r => r.Key))
39          resultNames.Add(name);
40      }
41      var newRun = new Run();
42      foreach (var name in resultNames)
43        newRun.Results.Add(name, new StringValue(name));
44      foreach (var name in parameterNames)
45        newRun.Parameters.Add(name, new StringValue(name));
46      runs.Add(newRun);
47    }
48
49    #endregion
50  }
51}
Note: See TracBrowser for help on using the repository browser.