Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/Algorithm/ParallelOperatorProcessor.cs @ 10090

Last change on this file since 10090 was 10090, checked in by ascheibe, 10 years ago

#1886 added an algorithm that executes analyzers on a solution cache

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis.SolutionCaching {
31  [Item("ParallelOperatorProcessor", "An operator that contains multiple operators of which each is applied on the current scope in parallel.")]
32  [StorableClass]
33  public sealed class ParallelOperatorProcessor : MultiOperator<IOperator> {
34    public ValueLookupParameter<BoolValue> ParallelParameter {
35      get { return (ValueLookupParameter<BoolValue>)Parameters["Parallel"]; }
36    }
37
38    public BoolValue Parallel {
39      get { return ParallelParameter.Value; }
40      set { ParallelParameter.Value = value; }
41    }
42
43    [StorableConstructor]
44    private ParallelOperatorProcessor(bool deserializing) : base(deserializing) { }
45    private ParallelOperatorProcessor(ParallelOperatorProcessor original, Cloner cloner)
46      : base(original, cloner) {
47    }
48    public ParallelOperatorProcessor()
49      : base() {
50      Parameters.Add(new ValueLookupParameter<BoolValue>("Parallel", "True if the operators should be applied in parallel on the sub-scopes, otherwise false.", new BoolValue(false)));
51    }
52
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new ParallelOperatorProcessor(this, cloner);
55    }
56
57    public override IOperation Apply() {
58      OperationCollection next = new OperationCollection(base.Apply());
59      OperationCollection inner = new OperationCollection();
60      inner.Parallel = Parallel != null && Parallel.Value;
61      for (int i = 0; i < Operators.Count(); i++) {
62        inner.Add(ExecutionContext.CreateOperation(Operators[i], ExecutionContext.Scope));
63      }
64      next.Insert(0, inner);
65      return next;
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.