Free cookie consent management tool by TermsFeed Policy Generator

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

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources/HeuristicLab.Operators/3.3
Files:
3 added
3 deleted
17 edited
3 moved

Legend:

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

    r2757 r2773  
    6868    }
    6969
    70     public override IExecutionContext Apply() {
     70    public override IExecutionSequence Apply() {
    7171      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
    7272      if (operatorGraph.InitialOperator != null)
  • trunk/sources/HeuristicLab.Operators/3.3/Comparator.cs

    r2757 r2773  
    6161    }
    6262
    63     public override IExecutionContext Apply() {
     63    public override IExecutionSequence Apply() {
    6464      IItem left = LeftSideParameter.ActualValue;
    6565      IItem right = RightSideParameter.ActualValue;
  • trunk/sources/HeuristicLab.Operators/3.3/ConditionalBranch.cs

    r2757 r2773  
    6262    }
    6363
    64     public override IExecutionContext Apply() {
     64    public override IExecutionSequence Apply() {
    6565      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
    6666      if (ConditionParameter.ActualValue.Value) {
  • trunk/sources/HeuristicLab.Operators/3.3/DoubleCounter.cs

    r2757 r2773  
    3030namespace HeuristicLab.Operators {
    3131  /// <summary>
    32   /// Operator which increments a double variable.
     32  /// An operator which increments a double variable.
    3333  /// </summary>
    3434  [Item("DoubleCounter", "An operator which increments a double variable.")]
     
    5353    }
    5454
    55     public override IExecutionContext Apply() {
     55    public override IExecutionSequence Apply() {
    5656      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new DoubleData();
    5757      ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value;
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r2757 r2773  
    8989    <Compile Include="ConditionalBranch.cs" />
    9090    <Compile Include="Comparator.cs" />
     91    <Compile Include="Assigner.cs" />
     92    <Compile Include="MultipleCallsOperator.cs" />
     93    <Compile Include="ParallelSubScopesProcessor.cs" />
     94    <Compile Include="Placeholder.cs" />
     95    <Compile Include="SingleCallOperator.cs" />
     96    <Compile Include="IntCounter.cs" />
    9197    <Compile Include="ScopeCleaner.cs" />
     98    <Compile Include="SequentialSubScopesProcessor.cs" />
     99    <Compile Include="StochasticBranch.cs" />
    92100    <Compile Include="SubScopesRemover.cs" />
    93101    <Compile Include="SubScopesSorter.cs" />
    94102    <Compile Include="DoubleCounter.cs" />
    95     <Compile Include="ParallelProcessor.cs" />
    96103    <Compile Include="UniformParallelSubScopesProcessor.cs" />
    97104    <Compile Include="UniformSequentialSubScopesProcessor.cs" />
    98     <Compile Include="ValueCollector.cs" />
    99     <Compile Include="MultipleSuccessorsOperator.cs" />
    100     <Compile Include="Counter.cs" />
    101105    <Compile Include="EmptyOperator.cs">
    102106      <SubType>Code</SubType>
     
    105109    <Compile Include="Operator.cs" />
    106110    <Compile Include="Properties\AssemblyInfo.cs" />
    107     <Compile Include="SequentialProcessor.cs" />
    108111    <Compile Include="SingleSuccessorOperator.cs" />
    109112    <Compile Include="SubScopesCreater.cs" />
     113    <Compile Include="ValuesCollector.cs" />
    110114    <Compile Include="VariableInjector.cs">
    111115      <SubType>Code</SubType>
  • trunk/sources/HeuristicLab.Operators/3.3/IntCounter.cs

    r2772 r2773  
    3030namespace HeuristicLab.Operators {
    3131  /// <summary>
    32   /// Operator which increments an integer variable.
     32  /// An operator which increments an integer variable.
    3333  /// </summary>
    34   [Item("Counter", "An operator which increments an integer variable.")]
     34  [Item("IntCounter", "An operator which increments an integer variable.")]
    3535  [EmptyStorableClass]
    3636  [Creatable("Test")]
    37   public sealed class Counter : SingleSuccessorOperator {
     37  public sealed class IntCounter : SingleSuccessorOperator {
    3838    public LookupParameter<IntData> ValueParameter {
    3939      get { return (LookupParameter<IntData>)Parameters["Value"]; }
     
    4747    }
    4848
    49     public Counter()
     49    public IntCounter()
    5050      : base() {
    5151      Parameters.Add(new LookupParameter<IntData>("Value", "The value which should be incremented."));
     
    5353    }
    5454
    55     public override IExecutionContext Apply() {
     55    public override IExecutionSequence Apply() {
    5656      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntData();
    5757      ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value;
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2757 r2773  
    130130
    131131    /// <inheritdoc/>
    132     public virtual IExecutionContext Execute(ExecutionContext context) {
     132    public virtual IExecutionSequence Execute(ExecutionContext context) {
    133133      try {
    134134        Canceled = false;
     
    136136        foreach (IParameter param in Parameters)
    137137          param.ExecutionContext = context;
    138         IExecutionContext next = Apply();
     138        IExecutionSequence next = Apply();
    139139        OnExecuted();
    140140        return next;
     
    156156    /// <param name="scope">The scope where to execute the operator</param>
    157157    /// <returns><c>null</c>.</returns>
    158     public abstract IExecutionContext Apply();
     158    public abstract IExecutionSequence Apply();
    159159
    160160    protected virtual void OnExecutionContextChanged() { }
  • 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    }
  • trunk/sources/HeuristicLab.Operators/3.3/Placeholder.cs

    r2772 r2773  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Retrieves an operator from a specified scope and returns a successor operation with this operation
    31   /// and scope.
     32  /// An operator which acts as a placeholder for another operator retrieved from the scope or a parent execution context.
    3233  /// </summary>
    33   public class OperatorExtractor : OperatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return @"An operator extractor retrievs an operator from the scope it is applied on and returns a successor operation containing this operator and the current scope. Lookup for the operator is done recursively.
    37 
    38 Operator extractors can be used to get those operators again that have been injected by combined operators."; }
     34  [Item("Placeholder", "An operator which acts as a placeholder for another operator retrieved from the scope or a parent execution context.")]
     35  [Creatable("Test")]
     36  [EmptyStorableClass]
     37  public sealed class Placeholder : SingleSuccessorOperator {
     38    public LookupParameter<IOperator> OperatorParameter {
     39      get { return (LookupParameter<IOperator>)Parameters["Operator"]; }
    3940    }
    4041
    41     /// <summary>
    42     /// Initializes a new instance of <see cref="OperatorExtractor"/> with
    43     /// one variable info (<c>Operator</c>).
    44     /// </summary>
    45     public OperatorExtractor()
     42    public Placeholder()
    4643      : base() {
    47       AddVariableInfo(new VariableInfo("Operator", "Extracted operator", typeof(IOperator), VariableKind.In));
     44      Parameters.Add(new LookupParameter<IOperator>("Operator", "The operator which is retrieved from the scope or a parent execution context and applied on the current scope."));
    4845    }
    4946
    50     /// <summary>
    51     /// Gets an operator from the specified <paramref name="scope"/> and returns an
    52     /// <see cref="AtomicOperation"/> containing this operator and scope.
    53     /// </summary>
    54     /// <param name="scope">The scope where to apply the operator on.</param>
    55     /// <returns>A new <see cref="AtomicOperation"/> containing the operator and the given
    56     /// <paramref name="scope"/>.</returns>
    57     public override IOperation Apply(IScope scope) {
    58       IOperator op = GetVariableValue<IOperator>("Operator", scope, true, true);
    59       return new AtomicOperation(op, scope);
     47    public override IExecutionSequence Apply() {
     48      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
     49      IOperator op = OperatorParameter.ActualValue;
     50      if (op != null)
     51        next.Insert(0, new ExecutionContext(ExecutionContext.Parent, op, ExecutionContext.Scope));
     52      return next;
    6053    }
    6154  }
  • trunk/sources/HeuristicLab.Operators/3.3/ScopeCleaner.cs

    r2757 r2773  
    4747    }
    4848
    49     public override IExecutionContext Apply() {
     49    public override IExecutionSequence Apply() {
    5050      CurrentScope.Variables.Clear();
    5151      CurrentScope.SubScopes.Clear();
  • trunk/sources/HeuristicLab.Operators/3.3/SequentialSubScopesProcessor.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 must be executed sequentially.
     34  /// An operator which contains multiple operators of which each is applied sequentially 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 SequentialSubScopesProcessor : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     36  [Item("SequentialSubScopesProcessor", "An operator which contains multiple operators of which each is applied sequentially 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 SequentialSubScopesProcessor : MultipleCallsOperator {
     39    public SequentialSubScopesProcessor()
     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.</returns>
    44     public override IOperation Apply(IScope scope) {
    45       CompositeOperation next = new CompositeOperation();
    46       for (int i = 0; i < scope.SubScopes.Count; i++)
    47         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        for (int i = 0; (i < ExecutionContext.Scope.SubScopes.Count) && (i < Operators.Count); i++)
     48          inner.Add(new ExecutionContext(ExecutionContext.Parent, Operators[i], ExecutionContext.Scope.SubScopes[i]));
     49        next.Insert(0, inner);
     50      }
    4851      return next;
    4952    }
  • trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs

    r2757 r2773  
    4949    }
    5050
    51     public override IExecutionContext Apply() {
     51    public override IExecutionSequence Apply() {
    5252      if (Successor != null)
    5353        return new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope);
  • trunk/sources/HeuristicLab.Operators/3.3/StochasticBranch.cs

    r1530 r2773  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     28using HeuristicLab.Parameters;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2730
    2831namespace HeuristicLab.Operators {
    2932  /// <summary>
    30   /// Branch of (one or) two operators that have different probabilities to get executed.
     33  /// A branch of two operators which are executed with a specified probability.
    3134  /// </summary>
    32   public class StochasticBranch : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     35  [Item("StochasticBranch", "A branch of two operators which are executed with a specified probability.")]
     36  [Creatable("Test")]
     37  [EmptyStorableClass]
     38  public class StochasticBranch : SingleSuccessorOperator {
     39    public LookupParameter<IRandom> RandomParameter {
     40      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     41    }
     42    public ValueLookupParameter<DoubleData> ProbabilityParameter {
     43      get { return (ValueLookupParameter<DoubleData>)Parameters["Probability"]; }
     44    }
     45    protected OperatorParameter FirstBranchParameter {
     46      get { return (OperatorParameter)Parameters["FirstBranch"]; }
     47    }
     48    protected OperatorParameter SecondBranchParameter {
     49      get { return (OperatorParameter)Parameters["SecondBranch"]; }
     50    }
     51    public IOperator FirstBranch {
     52      get { return FirstBranchParameter.Value; }
     53      set { FirstBranchParameter.Value = value; }
     54    }
     55    public IOperator SecondBranch {
     56      get { return SecondBranchParameter.Value; }
     57      set { SecondBranchParameter.Value = value; }
    3658    }
    3759
    38     /// <summary>
    39     /// Initializes a new instance of <see cref="StochasticBranch"/> with two variable infos
    40     /// (<c>Random</c> and <c>Probability</c>).
    41     /// </summary>
    4260    public StochasticBranch()
    4361      : base() {
    44       AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
    45       AddVariableInfo(new VariableInfo("Probability", "Probability to choose first branch", typeof(DoubleData), VariableKind.In));
     62      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
     63      Parameters.Add(new ValueLookupParameter<DoubleData>("Probability", "The probability to execute the first branch."));
     64      Parameters.Add(new OperatorParameter("FirstBranch", "The operator which is executed with the given probability."));
     65      Parameters.Add(new OperatorParameter("SecondBranch", "The operator which is executed if the first branch is not executed."));
    4666    }
    4767
    48     /// <summary>
    49     /// Applies the operator of branch one with a specific probability on the given
    50     /// <paramref name="scope"/>, or - if existent - with another probability operator of branch two. 
    51     /// </summary>
    52     /// <param name="scope">The scope to apply the operators on.</param>
    53     /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied
    54     /// to the given <paramref name="scope"/> or <c>null</c>.</returns>
    55     public override IOperation Apply(IScope scope) {
    56       IRandom random = GetVariableValue<IRandom>("Random", scope, true);
    57       DoubleData probability = GetVariableValue<DoubleData>("Probability", scope, true);
    58 
    59       bool result = random.NextDouble() < probability.Data;
    60       if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null))
    61         return new AtomicOperation(SubOperators[0], scope);
    62       else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null))
    63         return new AtomicOperation(SubOperators[1], scope);
    64       return null;
     68    public override IExecutionSequence Apply() {
     69      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
     70      if (RandomParameter.ActualValue.NextDouble() < ProbabilityParameter.ActualValue.Value) {
     71        if (FirstBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, FirstBranch, ExecutionContext.Scope));
     72      } else {
     73        if (SecondBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, SecondBranch, ExecutionContext.Scope));
     74      }
     75      return next;
    6576    }
    6677  }
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesCreater.cs

    r2757 r2773  
    5252    }
    5353
    54     public override IExecutionContext Apply() {
     54    public override IExecutionSequence Apply() {
    5555      int n = NumberOfSubScopesParameter.ActualValue.Value;
    5656      for (int i = 0; i < n; i++)
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs

    r2757 r2773  
    5252    }
    5353
    54     public override IExecutionContext Apply() {
     54    public override IExecutionSequence Apply() {
    5555      IntData index = SubScopeIndexParameter.ActualValue;
    5656      if (index != null)
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesSorter.cs

    r2757 r2773  
    5959    }
    6060
    61     public override IExecutionContext Apply() {
     61    public override IExecutionSequence Apply() {
    6262      descending = DescendingParameter.ActualValue.Value;
    6363      actualName = LookupParameter<DoubleData>.TranslateName(ValueParameter.Name, ExecutionContext);
  • trunk/sources/HeuristicLab.Operators/3.3/UniformParallelSubScopesProcessor.cs

    r2757 r2773  
    3535  [Creatable("Test")]
    3636  [EmptyStorableClass]
    37   public sealed class UniformParallelSubScopesProcessor : SingleSuccessorOperator {
    38     private OperatorParameter OperatorParameter {
    39       get { return (OperatorParameter)Parameters["Operator"]; }
    40     }
    41     public IOperator Operator {
    42       get { return OperatorParameter.Value; }
    43       set { OperatorParameter.Value = value; }
    44     }
    45 
     37  public sealed class UniformParallelSubScopesProcessor : SingleCallOperator {
    4638    public UniformParallelSubScopesProcessor()
    4739      : base() {
     40      Parameters.Remove("Operator");
    4841      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied on all sub-scopes of the current scope in parallel."));
    4942    }
    5043
    51     public override IExecutionContext Apply() {
     44    public override IExecutionSequence Apply() {
    5245      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
    5346      if (Operator != null) {
  • trunk/sources/HeuristicLab.Operators/3.3/UniformSequentialSubScopesProcessor.cs

    r2757 r2773  
    3535  [Creatable("Test")]
    3636  [EmptyStorableClass]
    37   public sealed class UniformSequentialSubScopesProcessor : SingleSuccessorOperator {
    38     private OperatorParameter OperatorParameter {
    39       get { return (OperatorParameter)Parameters["Operator"]; }
    40     }
    41     public IOperator Operator {
    42       get { return OperatorParameter.Value; }
    43       set { OperatorParameter.Value = value; }
    44     }
    45 
     37  public sealed class UniformSequentialSubScopesProcessor : SingleCallOperator {
    4638    public UniformSequentialSubScopesProcessor()
    4739      : base() {
     40      Parameters.Remove("Operator");
    4841      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied sequentially on all sub-scopes of the current scope."));
    4942    }
    5043
    51     public override IExecutionContext Apply() {
     44    public override IExecutionSequence Apply() {
    5245      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
    5346      if (Operator != null) {
  • trunk/sources/HeuristicLab.Operators/3.3/ValuesCollector.cs

    r2772 r2773  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Collections;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Parameters;
     
    3233  /// An operator which collects the actual values of parameters.
    3334  /// </summary>
    34   [Item("ValueCollector", "An operator which collects the actual values of parameters.")]
    35   [EmptyStorableClass]
     35  [Item("ValuesCollector", "An operator which collects the actual values of parameters.")]
    3636  [Creatable("Test")]
    37   public abstract class ValueCollector : SingleSuccessorOperator, IOperator {
    38     protected ValueParameter<ParameterCollection> CollectedValuesParameter {
    39       get { return (ValueParameter<ParameterCollection>)Parameters["CollectedValues"]; }
    40     }
     37  public abstract class ValuesCollector : SingleSuccessorOperator, IOperator {
     38    private ParameterCollection collectedValues;
     39    [Storable]
    4140    public ParameterCollection CollectedValues {
    42       get { return CollectedValuesParameter.Value; }
    43       set { CollectedValuesParameter.Value = value; }
     41      get { return collectedValues; }
     42      private set {
     43        collectedValues = value;
     44        collectedValues.ItemsAdded += new CollectionItemsChangedEventHandler<IParameter>(collectedValues_ItemsAdded);
     45        collectedValues.ItemsRemoved += new CollectionItemsChangedEventHandler<IParameter>(collectedValues_ItemsRemoved);
     46        collectedValues.CollectionReset += new CollectionItemsChangedEventHandler<IParameter>(collectedValues_CollectionReset);
     47      }
    4448    }
    4549
    46     public ValueCollector()
     50    public ValuesCollector()
    4751      : base() {
    48       Parameters.Add(new ValueParameter<ParameterCollection>("CollectedValues", "The parameters whose actual values are collected.", new ParameterCollection()));
     52      CollectedValues = new ParameterCollection();
    4953    }
    5054
    51     protected override void OnExecutionContextChanged() {
    52       foreach (IParameter param in CollectedValues)
    53         param.ExecutionContext = ExecutionContext;
     55    public override IDeepCloneable Clone(Cloner cloner) {
     56      ValuesCollector clone = (ValuesCollector)base.Clone(cloner);
     57      clone.CollectedValues = (ParameterCollection)cloner.Clone(collectedValues);
     58      return clone;
     59    }
     60
     61    private void collectedValues_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     62      Parameters.AddRange(e.Items);
     63    }
     64    private void collectedValues_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     65      Parameters.RemoveRange(e.Items);
     66    }
     67    #region NOTE
     68    // NOTE: The ItemsReplaced event has not to be handled here as it is only fired when the name (i.e. key) of a parameter
     69    // changes. As the same parameter is also contained in the Parameters collection of the operator, the Parameters collection
     70    // will react on this name change on its own.
     71    #endregion
     72    private void collectedValues_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     73      Parameters.RemoveRange(e.OldItems);
     74      Parameters.AddRange(e.Items);
    5475    }
    5576  }
  • trunk/sources/HeuristicLab.Operators/3.3/VariableInjector.cs

    r2757 r2773  
    3737  [Creatable("Test")]
    3838  [EmptyStorableClass]
    39   public class VariableInjector : ValueCollector {
     39  public class VariableInjector : ValuesCollector {
    4040    protected ScopeParameter CurrentScopeParameter {
    4141      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     
    5050    }
    5151
    52     public override IExecutionContext Apply() {
     52    public override IExecutionSequence Apply() {
    5353      IVariable var;
    5454      foreach (IParameter param in CollectedValues) {
Note: See TracChangeset for help on using the changeset viewer.