Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerUniformSubScopesProcessor.cs @ 12080

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

#2269

  • LayerUniformSubScopesProcessor does not longer derives from UniformSubScopesProcessor.
  • Reverted changes of UniformSubScopesProcessor.
File size: 4.7 KB
RevLine 
[12035]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
[12039]22using System;
[12035]23using System.Collections;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Algorithms.ALPS {
34  [Item("LayerUniformSubScopesProcessor", "")]
35  [StorableClass]
[12080]36  public class LayerUniformSubScopesProcessor : SingleSuccessorOperator {
37    private OperatorParameter OperatorParameter {
38      get { return (OperatorParameter)Parameters["Operator"]; }
39    }
40    public ValueLookupParameter<BoolValue> ParallelParameter {
41      get { return (ValueLookupParameter<BoolValue>)Parameters["Parallel"]; }
42    }
[12035]43
44    private ILookupParameter<IntArray> PopulationSizeParameter {
45      get { return (ILookupParameter<IntArray>)Parameters["PopulationSize"]; }
46    }
47
[12080]48    public IOperator Operator {
49      get { return OperatorParameter.Value; }
50      set { OperatorParameter.Value = value; }
51    }
52    public BoolValue Parallel {
53      get { return ParallelParameter.Value; }
54      set { ParallelParameter.Value = value; }
55    }
56
[12035]57    [StorableConstructor]
58    private LayerUniformSubScopesProcessor(bool deserializing) : base(deserializing) { }
59    private LayerUniformSubScopesProcessor(LayerUniformSubScopesProcessor original, Cloner cloner)
60      : base(original, cloner) {
61    }
62    public LayerUniformSubScopesProcessor()
63      : base() {
[12080]64      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied on all sub-scopes of the current scope."));
65      Parameters.Add(new ValueLookupParameter<BoolValue>("Parallel", "True if the operator should be applied in parallel on all sub-scopes, otherwise false.", new BoolValue(false)));
66
[12035]67      Parameters.Add(new LookupParameter<IntArray>("PopulationSize"));
68    }
69
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new LayerUniformSubScopesProcessor(this, cloner);
72    }
73
74    public override IOperation Apply() {
[12080]75      var next = new OperationCollection(Successor != null ? ExecutionContext.CreateOperation(Successor) : null);
[12035]76      if (Operator != null) {
[12080]77        var scopes = ExecutionContext.Scope.SubScopes;
78        var inner = new OperationCollection() {
79          Parallel = Parallel == null ? false : Parallel.Value
80        };
[12035]81        for (int i = 0; i < scopes.Count; i++) {
82          var layerParameters = new LayerIntermediateParameter {
[12039]83            new ValueParameter<IntValue>(PopulationSizeParameter.ActualName, new IntValue(PopulationSizeParameter.ActualValue[Math.Min(i, PopulationSizeParameter.ActualValue.Length - 1)]))
[12035]84          };
85          var immediateContext = new ExecutionContext(ExecutionContext.Parent, layerParameters, scopes[i]);
86          inner.Add(immediateContext.CreateChildOperation(Operator, scopes[i]));
87        }
88        next.Insert(0, inner);
89      }
90      return next;
91    }
92  }
93
94  [Item("LayerIntermediateParameter", "")]
95  [StorableClass]
96  public class LayerIntermediateParameter : ParameterizedNamedItem, IEnumerable<IParameter> {
97    [StorableConstructor]
98    private LayerIntermediateParameter(bool deserializing) : base(deserializing) { }
99    private LayerIntermediateParameter(LayerIntermediateParameter original, Cloner cloner)
100      : base(original, cloner) {
101    }
102    public LayerIntermediateParameter()
103      : base("LayerIntermediateParameter") {
104    }
105    public override IDeepCloneable Clone(Cloner cloner) {
106      return new LayerIntermediateParameter(this, cloner);
107    }
108
109    public void Add(IParameter parameter) {
110      Parameters.Add(parameter);
111    }
112
113    public IEnumerator<IParameter> GetEnumerator() {
114      return Parameters.GetEnumerator();
115    }
116    IEnumerator IEnumerable.GetEnumerator() {
117      return GetEnumerator();
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.