Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Optimization/3.3/RunCollectionModification/RunCollectionValueRemover.cs

Last change on this file was 16956, checked in by abeham, 5 years ago

#2457: merged trunk into branch

File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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;
29
30namespace HeuristicLab.Optimization {
31
32  [Item("RunCollection Value Remover", "Modifies a RunCollection by removing results or parameters.")]
33  [StorableType("300726A9-3E81-4F8E-A11F-4A5B3CDCA796")]
34  public class RunCollectionValueRemover : ParameterizedNamedItem, IRunCollectionModifier {
35   
36    public ValueParameter<CheckedItemCollection<StringValue>> ValuesParameter {
37      get { return (ValueParameter<CheckedItemCollection<StringValue>>)Parameters["Values"]; }
38    }
39
40    public IEnumerable<string> Values {
41      get { return ValuesParameter.Value.CheckedItems.Select(v => v.Value); }
42    }
43
44    #region Construction & Cloning   
45    [StorableConstructor]
46    protected RunCollectionValueRemover(StorableConstructorFlag _) : base(_) { }
47    protected RunCollectionValueRemover(RunCollectionValueRemover original, Cloner cloner)
48      : base(original, cloner) {
49    }
50    public RunCollectionValueRemover() {
51      Parameters.Add(new ValueParameter<CheckedItemCollection<StringValue>>("Values", "The result or parameter values to be removed from each run."));     
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new RunCollectionValueRemover(this, cloner);
55    }   
56    #endregion   
57
58    public void Modify(List<IRun> runs) {     
59      foreach (var run in runs) {
60        foreach (var value in Values) {
61          run.Parameters.Remove(value);
62          run.Results.Remove(value);
63        }       
64      }     
65    }
66   
67  }
68}
Note: See TracBrowser for help on using the repository browser.