Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Operators/3.3/CheckedMultiOperator.cs @ 12440

Last change on this file since 12440 was 9934, checked in by abeham, 11 years ago

#1833:

  • Changed behavior to output results only of those operators that have been checked
  • Removed additional "Checked" result
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Operators {
30  /// <summary>
31  /// A base class for operators which apply arbitrary many other operators of a specific type that can be checked or unchecked.
32  /// </summary>
33  [Item("CheckedMultiOperator", "A base class for operators which apply arbitrary many other operators of a specific type that can be checked or unchecked.")]
34  [StorableClass]
35  public abstract class CheckedMultiOperator<T> : MultiOperator<T>, ICheckedMultiOperator<T> where T : class, IOperator {
36    /// <summary>
37    /// Gets the operators of the checked multi operator
38    /// </summary>
39    public new ICheckedItemList<T> Operators {
40      get { return (ICheckedItemList<T>)base.Operators; }
41      protected set { base.Operators = value; }
42    }
43
44    [StorableConstructor]
45    protected CheckedMultiOperator(bool deserializing) : base(deserializing) { }
46    protected CheckedMultiOperator(CheckedMultiOperator<T> original, Cloner cloner)
47      : base(original, cloner) {
48    }
49    /// <summary>
50    /// Creates a new instance of CheckedMultiOperator
51    /// </summary>
52    public CheckedMultiOperator()
53      : base() {
54      Operators = new CheckedItemList<T>();
55    }
56
57    public override void CollectParameterValues(IDictionary<string, IItem> values) {
58      foreach (var param in Parameters.OfType<IValueParameter>().Except(OperatorParameters)) {
59        var children = GetCollectedValues(param);
60        foreach (var c in children) {
61          if (String.IsNullOrEmpty(c.Key))
62            values.Add(param.Name, c.Value);
63          else values.Add(param.Name + "." + c.Key, c.Value);
64        }
65      }
66      foreach (var opParam in OperatorParameters) {
67        var op = opParam.Value;
68        var @checked = Operators.ItemChecked(op);
69        if (!@checked) continue;
70        var children = GetCollectedValues(opParam);
71        foreach (var c in children) {
72          if (String.IsNullOrEmpty(c.Key))
73            values.Add(opParam.Name, c.Value);
74          else values.Add(opParam.Name + "." + c.Key, c.Value);
75        }
76      }
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.