Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Operators/3.3/FirstSubScopeProcessor.cs @ 12018

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

#2269

  • merged trunk after 3.3.11 release
  • updated copyright and plugin version in ALPS plugin
  • removed old ALPS samples based on an userdefined alg
File size: 2.4 KB
Line 
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
22using System;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Operators {
30  [Item("FirstSubScopeProsessor", "An operator which applies a specified operator on the first sub-scope.")]
31  [StorableClass]
32  public sealed class FirstSubScopeProcessor : SingleSuccessorOperator {
33    private OperatorParameter OperatorParameter {
34      get { return (OperatorParameter)Parameters["Operator"]; }
35    }
36
37    public IOperator Operator {
38      get { return OperatorParameter.Value; }
39      set { OperatorParameter.Value = value; }
40    }
41
42    [StorableConstructor]
43    private FirstSubScopeProcessor(bool deserializing) : base(deserializing) { }
44    private FirstSubScopeProcessor(FirstSubScopeProcessor original, Cloner cloner)
45      : base(original, cloner) {
46    }
47    public FirstSubScopeProcessor()
48      : base() {
49      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied on all sub-scopes of the current scope."));
50    }
51
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new FirstSubScopeProcessor(this, cloner);
54    }
55
56    public override IOperation Apply() {
57      var scopes = ExecutionContext.Scope.SubScopes;
58      if (scopes.Count < 1)
59        throw new ArgumentException("At least one sub-scope must exist.");
60
61      var next = new OperationCollection(base.Apply());
62      next.Insert(0, ExecutionContext.CreateOperation(Operator, scopes.First()));
63      return next;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.