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