- Timestamp:
- 02/10/10 03:39:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators/3.3/ParallelSubScopesProcessor.cs
r1530 r2773 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Text; 26 using System.Xml; 27 using HeuristicLab.Collections; 25 28 using HeuristicLab.Core; 26 using HeuristicLab.Data; 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 31 28 32 namespace HeuristicLab.Operators { 29 33 /// <summary> 30 /// Performs <c>n</c> operators on <c>n</c> subscopes, operations can be executed in parallel.34 /// An operator which contains multiple operators of which each is applied in parallel on one sub-scope of the current scope. The first operator is applied on the first sub-scope, the second on the second, and so on. 31 35 /// </summary> 32 public class ParallelSubScopesProcessor : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 36 [Item("ParallelSubScopesProcessor", "An operator which contains multiple operators of which each is applied in parallel on one sub-scope of the current scope. The first operator is applied on the first sub-scope, the second on the second, and so on.")] 37 [Creatable("Test")] 38 public sealed class ParallelSubScopesProcessor : MultipleCallsOperator { 39 public ParallelSubScopesProcessor() 40 : base() { 36 41 } 37 42 38 /// <summary> 39 /// Applies <c>n</c> operators on all the <c>n</c> sub scopes of the given <paramref name="scope"/>. 40 /// </summary> 41 /// <param name="scope">The scope on whose sub scopes the operators are applied.</param> 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied 43 /// on the <c>i</c>th sub scope, the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 44 public override IOperation Apply(IScope scope) { 45 CompositeOperation next = new CompositeOperation(); 46 next.ExecuteInParallel = true; 47 for (int i = 0; i < scope.SubScopes.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i])); 43 public override IExecutionSequence Apply() { 44 ExecutionContextCollection next = new ExecutionContextCollection(base.Apply()); 45 if (Operators.Count > 0) { 46 ExecutionContextCollection inner = new ExecutionContextCollection(); 47 inner.Parallel = true; 48 for (int i = 0; (i < ExecutionContext.Scope.SubScopes.Count) && (i < Operators.Count); i++) 49 inner.Add(new ExecutionContext(ExecutionContext.Parent, Operators[i], ExecutionContext.Scope.SubScopes[i])); 50 next.Insert(0, inner); 51 } 49 52 return next; 50 53 }
Note: See TracChangeset
for help on using the changeset viewer.