1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace 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("390272F8-3B06-4121-B7F6-2FC713A45613")]
|
---|
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 | }
|
---|