Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LastSubScopeCloner.cs @ 11676

Last change on this file since 11676 was 11609, checked in by pfleck, 9 years ago

#2269

  • Fixed Bugs with Per-Layer-Results.
  • Fixed Bugs in EldersSelector.
  • Added LayerCreator instead of LastSubScopeCloner for avoiding operators for some temporary hacks.
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.ALPS {
32  [Item("LastSubScopeCloner", "An operator which clones the last sub-scope of the current scope.")]
33  [StorableClass]
34  public sealed class LastSubScopeCloner : SingleSuccessorOperator {
35    [StorableConstructor]
36    private LastSubScopeCloner(bool deserializing) : base(deserializing) { }
37
38    private LastSubScopeCloner(LastSubScopeCloner original, Cloner cloner)
39      : base(original, cloner) {
40    }
41    public LastSubScopeCloner()
42      : base() {
43      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes should be cloned."));
44      Parameters.Add(new ValueParameter<IntValue>("NumberOfCopies", "The number of copies that should be created.", new IntValue(1)));
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new LastSubScopeCloner(this, cloner);
49    }
50
51    public override IOperation Apply() {
52      var scopes = ExecutionContext.Scope.SubScopes;
53      if (scopes.Count < 1)
54        throw new ArgumentException("At least one sub-scope must exist.");
55
56      var lastSubScope = scopes.Last();
57      var clone = (IScope)lastSubScope.Clone(new Cloner());
58
59      int number;
60      if (int.TryParse(clone.Name, out number))
61        clone.Name = (number + 1).ToString();
62
63      scopes.Add(clone);
64
65      return base.Apply();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.