[5735] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5735] | 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 HeuristicLab.Core;
|
---|
[16565] | 23 | using HEAL.Attic;
|
---|
[5735] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Parameters;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 |
|
---|
| 28 | namespace 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.")]
|
---|
[16565] | 33 | [StorableType("1F299CDC-13E0-4F12-9E2D-7D3CAC8C651C")]
|
---|
[5735] | 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]
|
---|
[16565] | 52 | protected SubScopesCloner(StorableConstructorFlag _) : base(_) { }
|
---|
[5769] | 53 | protected SubScopesCloner(SubScopesCloner original, Cloner cloner)
|
---|
[5735] | 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 | }
|
---|