Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Operators/3.3/SubScopesCloner.cs @ 17107

Last change on this file since 17107 was 16565, checked in by gkronber, 6 years ago

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

File size: 2.8 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 HeuristicLab.Core;
23using HEAL.Attic;
24using HeuristicLab.Common;
25using HeuristicLab.Parameters;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.Operators {
29  /// <summary>
30  /// An operator which creates multiple copies of the subscopes of the current scope.
31  /// </summary>
32  [Item("SubScopesCloner", "An operator which creates multiple copies of the subscopes of the current scope.")]
33  [StorableType("1F299CDC-13E0-4F12-9E2D-7D3CAC8C651C")]
34  public class SubScopesCloner : SingleSuccessorOperator {
35    private ScopeParameter CurrentScopeParameter {
36      get { return (ScopeParameter)Parameters["CurrentScope"]; }
37    }
38    private ValueParameter<IntValue> NumberOfCopiesParameter {
39      get { return (ValueParameter<IntValue>)Parameters["NumberOfCopies"]; }
40    }
41
42    public IScope CurrentScope {
43      get { return CurrentScopeParameter.ActualValue; }
44    }
45    public IntValue NumberOfCopies {
46      get { return NumberOfCopiesParameter.Value; }
47      set { NumberOfCopiesParameter.Value = value;  }
48    }
49
50
51    [StorableConstructor]
52    protected SubScopesCloner(StorableConstructorFlag _) : base(_) { }
53    protected SubScopesCloner(SubScopesCloner original, Cloner cloner)
54      : base(original, cloner) {
55    }
56    public SubScopesCloner()
57      : base() {
58      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes should be cloned."));
59      Parameters.Add(new ValueParameter<IntValue>("NumberOfCopies", "The number of copies that should be created.", new IntValue(1)));
60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new SubScopesCloner(this, cloner);
64    }
65
66    public override IOperation Apply() {
67      ScopeList subScopes = new ScopeList(CurrentScope.SubScopes);
68
69      for (int i = 0; i < NumberOfCopies.Value; i++) {
70        foreach (Scope scope in subScopes) {
71          CurrentScope.SubScopes.Add(scope.Clone() as IScope);
72        }
73      }
74
75       return base.Apply();
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.