Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/03/10 04:43:06 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources/HeuristicLab.Operators/3.3
Files:
1 added
6 edited
1 moved

Legend:

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

    r2727 r2740  
    3636  [Item("CombinedOperator", "An operator which contains an operator graph.")]
    3737  [Creatable("Test")]
    38   public sealed class CombinedOperator : StandardOperator, IOperator {
     38  public sealed class CombinedOperator : SingleSuccessorOperator, IOperator {
    3939    public override Image ItemImage {
    4040      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Module; }
     
    6868    }
    6969
    70     public override ExecutionContextCollection Apply(ExecutionContext context) {
    71       ExecutionContextCollection next = base.Apply(context);
     70    public override ExecutionContextCollection Apply() {
     71      ExecutionContextCollection next = base.Apply();
    7272      if (operatorGraph.InitialOperator != null)
    73         next.Insert(0, new ExecutionContext(context, operatorGraph.InitialOperator, context.Scope));
     73        next.Insert(0, new ExecutionContext(ExecutionContext, operatorGraph.InitialOperator, ExecutionContext.Scope));
    7474      return next;
    7575    }
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2715 r2740  
    3535  [EmptyStorableClass]
    3636  [Creatable("Test")]
    37   public sealed class Counter : StandardOperator {
     37  public sealed class Counter : SingleSuccessorOperator {
    3838    public ItemParameter<IntData> Value {
    3939      get { return (ItemParameter<IntData>)Parameters["Value"]; }
     
    4949    }
    5050
    51     public override ExecutionContextCollection Apply(ExecutionContext context) {
    52       IntData value = (IntData)Value.GetValue(context);
    53       IntData increment = (IntData)Increment.GetValue(context);
     51    public override ExecutionContextCollection Apply() {
     52      IntData value = (IntData)Value.Value;
     53      IntData increment = (IntData)Increment.Value;
    5454      value.Value += increment.Value;
    55       return base.Apply(context);
     55      return base.Apply();
    5656    }
    5757  }
  • trunk/sources/HeuristicLab.Operators/3.3/EmptyOperator.cs

    r2684 r2740  
    3434  [Creatable("Test")]
    3535  [EmptyStorableClass]
    36   public sealed class EmptyOperator : StandardOperator {
     36  public sealed class EmptyOperator : SingleSuccessorOperator {
    3737    public EmptyOperator()
    3838      : base() {
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r2714 r2740  
    8686  <ItemGroup>
    8787    <Compile Include="CombinedOperator.cs" />
     88    <Compile Include="MultipleSuccessorsOperator.cs" />
    8889    <Compile Include="Counter.cs" />
    8990    <Compile Include="EmptyOperator.cs">
     
    9495    <Compile Include="Properties\AssemblyInfo.cs" />
    9596    <Compile Include="SequentialProcessor.cs" />
    96     <Compile Include="StandardOperator.cs" />
     97    <Compile Include="SingleSuccessorOperator.cs" />
    9798  </ItemGroup>
    9899  <ItemGroup>
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2684 r2740  
    8484    }
    8585
     86    [Storable]
     87    private ExecutionContext executionContext;
     88    protected ExecutionContext ExecutionContext {
     89      get { return executionContext; }
     90    }
     91
    8692    /// <summary>
    8793    /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and
     
    107113      clone.canceled = canceled;
    108114      clone.breakpoint = breakpoint;
     115      clone.executionContext = (ExecutionContext)cloner.Clone(executionContext);
    109116      return clone;
    110117    }
     
    112119    /// <inheritdoc/>
    113120    public virtual ExecutionContextCollection Execute(ExecutionContext context) {
    114       canceled = false;
    115       ExecutionContextCollection next = Apply(context);
    116       OnExecuted();
    117       return next;
     121      try {
     122        canceled = false;
     123        executionContext = context;
     124        foreach (IParameter param in Parameters)
     125          param.ExecutionContext = context;
     126        ExecutionContextCollection next = Apply();
     127        OnExecuted();
     128        return next;
     129      }
     130      finally {
     131        foreach (IParameter param in Parameters)
     132          param.ExecutionContext = null;
     133        context = null;
     134      }
    118135    }
    119136    /// <inheritdoc/>
     
    127144    /// <param name="scope">The scope where to execute the operator</param>
    128145    /// <returns><c>null</c>.</returns>
    129     public virtual ExecutionContextCollection Apply(ExecutionContext context) {
     146    public virtual ExecutionContextCollection Apply() {
    130147      return new ExecutionContextCollection();
    131148    }
  • trunk/sources/HeuristicLab.Operators/3.3/SequentialProcessor.cs

    r2684 r2740  
    3636  [Creatable("Test")]
    3737  [EmptyStorableClass]
    38   public sealed class SequentialProcessor : Operator, IOperator {
    39     public new ParameterCollection Parameters {
    40       get {
    41         return base.Parameters;
    42       }
    43     }
    44     IObservableKeyedCollection<string, IParameter> IOperator.Parameters {
    45       get { return Parameters; }
    46     }
    47 
     38  public sealed class SequentialProcessor : MultipleSuccessorsOperator {
    4839    public SequentialProcessor()
    4940      : base() {
    5041    }
    5142
    52     public override ExecutionContextCollection Apply(ExecutionContext context) {
     43    public override ExecutionContextCollection Apply() {
    5344      ExecutionContextCollection next = new ExecutionContextCollection();
    54       foreach (IParameter param in Parameters) {
    55         IOperatorParameter opParam = param as IOperatorParameter;
    56         if (opParam != null) {
    57           IOperator op = (IOperator)opParam.GetValue(context);
    58           if (op != null) next.Add(new ExecutionContext(context.Parent, op, context.Scope));
    59         }
    60       }
     45      for (int i = 0; i < Successors.Count; i++)
     46        next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope));
    6147      return next;
    6248    }
  • trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs

    r2739 r2740  
    3232  /// A base class for operators which have only one successor.
    3333  /// </summary>
    34   [Item("StandardOperator", "A base class for operators which have only one successor.")]
     34  [Item("SingleSuccessorOperator", "A base class for operators which have only one successor.")]
    3535  [Creatable("Test")]
    3636  [EmptyStorableClass]
    37   public abstract class StandardOperator : Operator {
    38     public OperatorParameter Successor {
     37  public abstract class SingleSuccessorOperator : Operator {
     38    protected OperatorParameter SuccessorParameter {
    3939      get { return (OperatorParameter)Parameters["Successor"]; }
    4040    }
    41 
    42     public StandardOperator()
    43       : base() {
    44       Parameters.Add(new OperatorParameter("Successor", "Operator which is executed next"));
     41    public IOperator Successor {
     42      get { return SuccessorParameter.Value; }
     43      set { SuccessorParameter.Value = value; }
    4544    }
    4645
    47     public override ExecutionContextCollection Apply(ExecutionContext context) {
    48       IOperator successor = (IOperator)Successor.GetValue(context);
    49       if (successor != null)
    50         return new ExecutionContextCollection(new ExecutionContext(context.Parent, successor, context.Scope));
     46    public SingleSuccessorOperator()
     47      : base() {
     48      Parameters.Add(new OperatorParameter("Successor", "Operator which is executed next."));
     49    }
     50
     51    public override ExecutionContextCollection Apply() {
     52      if (Successor != null)
     53        return new ExecutionContextCollection(new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope));
    5154      else
    5255        return new ExecutionContextCollection();
Note: See TracChangeset for help on using the changeset viewer.