Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Operators/3.3/CheckedMultiOperator.cs @ 17842

Last change on this file since 17842 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.1 KB
RevLine 
[2773]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2773]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
[9942]22using System;
23using System.Collections.Generic;
24using System.Linq;
[4722]25using HeuristicLab.Common;
[2773]26using HeuristicLab.Core;
[17097]27using HEAL.Attic;
[2773]28
29namespace HeuristicLab.Operators {
30  /// <summary>
[3616]31  /// A base class for operators which apply arbitrary many other operators of a specific type that can be checked or unchecked.
[2773]32  /// </summary>
[3822]33  [Item("CheckedMultiOperator", "A base class for operators which apply arbitrary many other operators of a specific type that can be checked or unchecked.")]
[17097]34  [StorableType("7C166074-0171-4574-8689-8CDB75A9BB1A")]
[9159]35  public abstract class CheckedMultiOperator<T> : MultiOperator<T>, ICheckedMultiOperator<T> where T : class, IOperator {
[3591]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; }
[2773]42    }
[4722]43
44    [StorableConstructor]
[17097]45    protected CheckedMultiOperator(StorableConstructorFlag _) : base(_) { }
[4722]46    protected CheckedMultiOperator(CheckedMultiOperator<T> original, Cloner cloner)
47      : base(original, cloner) {
48    }
[3591]49    /// <summary>
50    /// Creates a new instance of CheckedMultiOperator
51    /// </summary>
52    public CheckedMultiOperator()
[2773]53      : base() {
[3591]54      Operators = new CheckedItemList<T>();
[2773]55    }
[9942]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    }
[2773]78  }
79}
Note: See TracBrowser for help on using the repository browser.