Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/10/10 03:39:02 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators/3.3/ParallelSubScopesProcessor.cs

    r1530 r2773  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using System.Text;
     26using System.Xml;
     27using HeuristicLab.Collections;
    2528using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     29using HeuristicLab.Parameters;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2731
    2832namespace HeuristicLab.Operators {
    2933  /// <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.
    3135  /// </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() {
    3641    }
    3742
    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      }
    4952      return next;
    5053    }
Note: See TracChangeset for help on using the changeset viewer.