Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10231


Ignore:
Timestamp:
12/17/13 10:34:51 (11 years ago)
Author:
mkommend
Message:

#2119: Improvements to the InstrumentedOperator class:

  • skipped generation of operations if no instrumentation is performed
  • changed type of operators parameters to OperatorList
File:
1 edited

Legend:

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

    r10149 r10231  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3233    private const string AfterExecutionOperatorsParameterName = "AfterExecutionOperators";
    3334
    34     private IFixedValueParameter<ItemList<SingleSuccessorOperator>> BeforeExecutionOperatorsParameter {
    35       get { return (IFixedValueParameter<ItemList<SingleSuccessorOperator>>)Parameters[BeforeExecutionOperatorsParameterName]; }
     35    private IFixedValueParameter<OperatorList> BeforeExecutionOperatorsParameter {
     36      get { return (IFixedValueParameter<OperatorList>)Parameters[BeforeExecutionOperatorsParameterName]; }
    3637    }
    37     private IFixedValueParameter<ItemList<SingleSuccessorOperator>> AfterExecutionOperatorsParameter {
    38       get { return (IFixedValueParameter<ItemList<SingleSuccessorOperator>>)Parameters[AfterExecutionOperatorsParameterName]; }
     38    private IFixedValueParameter<OperatorList> AfterExecutionOperatorsParameter {
     39      get { return (IFixedValueParameter<OperatorList>)Parameters[AfterExecutionOperatorsParameterName]; }
    3940    }
    4041
    41     public ItemList<SingleSuccessorOperator> BeforeExecutionOperators {
     42    public OperatorList BeforeExecutionOperators {
    4243      get { return BeforeExecutionOperatorsParameter.Value; }
    4344    }
    44     public ItemList<SingleSuccessorOperator> AfterExecutionOperators {
     45    public OperatorList AfterExecutionOperators {
    4546      get { return AfterExecutionOperatorsParameter.Value; }
    4647    }
     
    5354    protected InstrumentedOperator()
    5455      : base() {
    55       Parameters.Add(new FixedValueParameter<ItemList<SingleSuccessorOperator>>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new ItemList<SingleSuccessorOperator>()));
    56       Parameters.Add(new FixedValueParameter<ItemList<SingleSuccessorOperator>>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new ItemList<SingleSuccessorOperator>()));
     56      Parameters.Add(new FixedValueParameter<OperatorList>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new OperatorList()));
     57      Parameters.Add(new FixedValueParameter<OperatorList>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new OperatorList()));
    5758      BeforeExecutionOperatorsParameter.Hidden = true;
    5859      AfterExecutionOperatorsParameter.Hidden = true;
     
    6465      #region Backwards compatible code, remove with 3.4
    6566      if (!Parameters.ContainsKey(BeforeExecutionOperatorsParameterName)) {
    66         Parameters.Add(new FixedValueParameter<ItemList<SingleSuccessorOperator>>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new ItemList<SingleSuccessorOperator>()));
     67        Parameters.Add(new FixedValueParameter<OperatorList>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new OperatorList()));
    6768        BeforeExecutionOperatorsParameter.Hidden = true;
    6869      }
    6970      if (!Parameters.ContainsKey(AfterExecutionOperatorsParameterName)) {
    70         Parameters.Add(new FixedValueParameter<ItemList<SingleSuccessorOperator>>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new ItemList<SingleSuccessorOperator>()));
     71        Parameters.Add(new FixedValueParameter<OperatorList>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new OperatorList()));
    7172        AfterExecutionOperatorsParameter.Hidden = true;
    7273      }
     
    7576
    7677    public sealed override IOperation Apply() {
    77       var opCol = new OperationCollection();
     78      //to speed up the execution call instrumented apply directly if no before operators exists
     79      if (!BeforeExecutionOperators.Any())
     80        return InstrumentedApply();
    7881
    7982      //build before operations
     83      var opCol = new OperationCollection();
    8084      foreach (var beforeAction in BeforeExecutionOperators) {
    81         IOperation beforeActionOperation = ExecutionContext.CreateOperation(beforeAction);
     85        var beforeActionOperation = ExecutionContext.CreateOperation(beforeAction);
    8286        opCol.Add(beforeActionOperation);
    8387      }
     
    8892
    8993    public virtual IOperation InstrumentedApply() {
     94      if (!AfterExecutionOperators.Any()) {
     95        if (Successor != null) return ExecutionContext.CreateOperation(Successor);
     96        return null;
     97      }
     98
    9099      var opCol = new OperationCollection();
    91100      foreach (var afterAction in AfterExecutionOperators) {
    92         IOperation afterActionOperation = ExecutionContext.CreateOperation(afterAction);
     101        var afterActionOperation = ExecutionContext.CreateOperation(afterAction);
    93102        opCol.Add(afterActionOperation);
    94103      }
     104
    95105      if (Successor != null)
    96106        opCol.Add(ExecutionContext.CreateOperation(Successor));
Note: See TracChangeset for help on using the changeset viewer.