[8924] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8924] | 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 |
|
---|
[7228] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
[16565] | 28 | using HEAL.Attic;
|
---|
[18055] | 29 | using HeuristicLab.Collections;
|
---|
[7228] | 30 |
|
---|
| 31 | namespace HeuristicLab.Optimization {
|
---|
| 32 |
|
---|
| 33 | [Item("RunCollection Value Remover", "Modifies a RunCollection by removing results or parameters.")]
|
---|
[16565] | 34 | [StorableType("300726A9-3E81-4F8E-A11F-4A5B3CDCA796")]
|
---|
[7228] | 35 | public class RunCollectionValueRemover : ParameterizedNamedItem, IRunCollectionModifier {
|
---|
| 36 |
|
---|
| 37 | public ValueParameter<CheckedItemCollection<StringValue>> ValuesParameter {
|
---|
| 38 | get { return (ValueParameter<CheckedItemCollection<StringValue>>)Parameters["Values"]; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[18055] | 41 | public IFixedValueParameter<BoolValue> InvertParameter {
|
---|
| 42 | get { return (IFixedValueParameter<BoolValue>)Parameters["Invert"]; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[7228] | 45 | public IEnumerable<string> Values {
|
---|
| 46 | get { return ValuesParameter.Value.CheckedItems.Select(v => v.Value); }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[18055] | 49 | public bool Invert => InvertParameter.Value.Value;
|
---|
| 50 |
|
---|
[7228] | 51 | #region Construction & Cloning
|
---|
| 52 | [StorableConstructor]
|
---|
[16565] | 53 | protected RunCollectionValueRemover(StorableConstructorFlag _) : base(_) { }
|
---|
[7228] | 54 | protected RunCollectionValueRemover(RunCollectionValueRemover original, Cloner cloner)
|
---|
| 55 | : base(original, cloner) {
|
---|
| 56 | }
|
---|
| 57 | public RunCollectionValueRemover() {
|
---|
[18055] | 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: Blackbox <-> Whitebox (Default: Blackbox)", new BoolValue(false)));
|
---|
[7228] | 60 | }
|
---|
| 61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 62 | return new RunCollectionValueRemover(this, cloner);
|
---|
| 63 | }
|
---|
| 64 | #endregion
|
---|
| 65 |
|
---|
[18055] | 66 | public void Modify(List<IRun> runs) {
|
---|
[7228] | 67 | foreach (var run in runs) {
|
---|
[18055] | 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 | }
|
---|
[7228] | 84 | }
|
---|
| 85 |
|
---|
| 86 | }
|
---|
| 87 | }
|
---|