Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14808 was 7211, checked in by epitzer, 13 years ago

#1696: Make ResultNamesCollector return a CheckedItemCollection instead of individual results

File size: 1.8 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      newRun.Results.Add("Result Names",
43        new CheckedItemCollection<StringValue>(resultNames.Select(r => new StringValue(r))));
44      newRun.Parameters.Add("Parameter Names",
45        new CheckedItemCollection<StringValue>(parameterNames.Select(p => new StringValue(p))));
46      runs.Add(newRun);
47    }
48
49    #endregion
50  }
51}
Note: See TracBrowser for help on using the repository browser.