source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Optimization/3.3/RunCollectionModification/RunCollectionValueRemover.cs @ 18056

Last change on this file since 18056 was 18056, checked in by dpiringe, 3 months ago

#3026

  • fixed a wrong description for the invert parameter in RunCollectionValueRemover
  • fixed the usage of a wrong formatter in RunCollectionSRSolutionGraphVizFormatter
  • fixed a bug in ListJsonItem where an empty guid field can cause an exception
  • started to rework the RegressionProblemDataConverter -> it causes a bug with the symbol Variable of the TypeCorherentGrammar (maybe more grammars)
    • the reasons for the rework: this converter was already the source of some problems in the past; it uses a lot of reflection and dynamic objects -> it is very complicated to read/understand
  • added an official description property Description in the metadata part of a template + entry in Constants.cs
File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HEAL.Attic;
29using HeuristicLab.Collections;
30
31namespace HeuristicLab.Optimization {
32
33  [Item("RunCollection Value Remover", "Modifies a RunCollection by removing results or parameters.")]
34  [StorableType("300726A9-3E81-4F8E-A11F-4A5B3CDCA796")]
35  public class RunCollectionValueRemover : ParameterizedNamedItem, IRunCollectionModifier {
36   
37    public ValueParameter<CheckedItemCollection<StringValue>> ValuesParameter {
38      get { return (ValueParameter<CheckedItemCollection<StringValue>>)Parameters["Values"]; }
39    }
40
41    public IFixedValueParameter<BoolValue> InvertParameter {
42      get { return (IFixedValueParameter<BoolValue>)Parameters["Invert"]; }
43    }
44
45    public IEnumerable<string> Values {
46      get { return ValuesParameter.Value.CheckedItems.Select(v => v.Value); }
47    }
48
49    public bool Invert => InvertParameter.Value.Value;
50
51    #region Construction & Cloning   
52    [StorableConstructor]
53    protected RunCollectionValueRemover(StorableConstructorFlag _) : base(_) { }
54    protected RunCollectionValueRemover(RunCollectionValueRemover original, Cloner cloner)
55      : base(original, cloner) {
56    }
57    public RunCollectionValueRemover() {
58      Parameters.Add(new ValueParameter<CheckedItemCollection<StringValue>>("Values", "The result or parameter values to be removed from each run."));
59      Parameters.Add(new FixedValueParameter<BoolValue>("Invert", "Inverts the filter strategy: Blacklist <-> Whitelist (Default: Blacklist)", new BoolValue(false)));
60    }
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new RunCollectionValueRemover(this, cloner);
63    }   
64    #endregion   
65
66    public void Modify(List<IRun> runs) {
67      foreach (var run in runs) {
68        if (Invert) { //Whitebox
69          var parametersCopy = new ObservableDictionary<string, IItem>(run.Parameters);
70          var resultsCopy = new ObservableDictionary<string, IItem>(run.Results);
71          foreach(var param in parametersCopy)
72            if (!Values.Any(x => x == param.Key))
73              run.Parameters.Remove(param.Key);
74          foreach (var result in resultsCopy)
75            if (!Values.Any(x => x == result.Key))
76              run.Results.Remove(result.Key);
77        } else { //Blackbox
78          foreach (var value in Values) {
79            run.Parameters.Remove(value);
80            run.Results.Remove(value);
81          }
82        }
83      }   
84    }
85   
86  }
87}
Note: See TracBrowser for help on using the repository browser.