Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/14 14:56:39 (11 years ago)
Author:
gkronber
Message:

#2093: merged trunk changes to prepare for reintegration

Location:
branches/LogResidualEvaluator
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LogResidualEvaluator

  • branches/LogResidualEvaluator/HeuristicLab.Operators/3.3/InstrumentedOperator.cs

    r10149 r10483  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
     
    2830  [Item("InstrumentedOperator", "A operator that can execute pre- and post actions.")]
    2931  [StorableClass]
    30   public abstract class InstrumentedOperator : SingleSuccessorOperator {
     32  public abstract class InstrumentedOperator : SingleSuccessorOperator, IInstrumentedOperator {
    3133    private const string BeforeExecutionOperatorsParameterName = "BeforeExecutionOperators";
    3234    private const string AfterExecutionOperatorsParameterName = "AfterExecutionOperators";
    3335
    34     private IFixedValueParameter<ItemList<SingleSuccessorOperator>> BeforeExecutionOperatorsParameter {
    35       get { return (IFixedValueParameter<ItemList<SingleSuccessorOperator>>)Parameters[BeforeExecutionOperatorsParameterName]; }
     36    private IFixedValueParameter<OperatorList> BeforeExecutionOperatorsParameter {
     37      get { return (IFixedValueParameter<OperatorList>)Parameters[BeforeExecutionOperatorsParameterName]; }
    3638    }
    37     private IFixedValueParameter<ItemList<SingleSuccessorOperator>> AfterExecutionOperatorsParameter {
    38       get { return (IFixedValueParameter<ItemList<SingleSuccessorOperator>>)Parameters[AfterExecutionOperatorsParameterName]; }
     39    private IFixedValueParameter<OperatorList> AfterExecutionOperatorsParameter {
     40      get { return (IFixedValueParameter<OperatorList>)Parameters[AfterExecutionOperatorsParameterName]; }
    3941    }
    4042
    41     public ItemList<SingleSuccessorOperator> BeforeExecutionOperators {
     43
     44    IEnumerable<IOperator> IInstrumentedOperator.BeforeExecutionOperators { get { return BeforeExecutionOperators; } }
     45    public OperatorList BeforeExecutionOperators {
    4246      get { return BeforeExecutionOperatorsParameter.Value; }
    4347    }
    44     public ItemList<SingleSuccessorOperator> AfterExecutionOperators {
     48    IEnumerable<IOperator> IInstrumentedOperator.AfterExecutionOperators { get { return AfterExecutionOperators; } }
     49    public OperatorList AfterExecutionOperators {
    4550      get { return AfterExecutionOperatorsParameter.Value; }
    4651    }
     
    5358    protected InstrumentedOperator()
    5459      : 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>()));
     60      Parameters.Add(new FixedValueParameter<OperatorList>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new OperatorList()));
     61      Parameters.Add(new FixedValueParameter<OperatorList>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new OperatorList()));
    5762      BeforeExecutionOperatorsParameter.Hidden = true;
    5863      AfterExecutionOperatorsParameter.Hidden = true;
     
    6469      #region Backwards compatible code, remove with 3.4
    6570      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>()));
     71        Parameters.Add(new FixedValueParameter<OperatorList>(BeforeExecutionOperatorsParameterName, "Actions that are executed before the execution of the operator", new OperatorList()));
    6772        BeforeExecutionOperatorsParameter.Hidden = true;
    6873      }
    6974      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>()));
     75        Parameters.Add(new FixedValueParameter<OperatorList>(AfterExecutionOperatorsParameterName, "Actions that are executed after the execution of the operator", new OperatorList()));
    7176        AfterExecutionOperatorsParameter.Hidden = true;
    7277      }
     
    7580
    7681    public sealed override IOperation Apply() {
    77       var opCol = new OperationCollection();
     82      //to speed up the execution call instrumented apply directly if no before operators exists
     83      if (!BeforeExecutionOperators.Any())
     84        return InstrumentedApply();
    7885
    7986      //build before operations
     87      var opCol = new OperationCollection();
    8088      foreach (var beforeAction in BeforeExecutionOperators) {
    81         IOperation beforeActionOperation = ExecutionContext.CreateOperation(beforeAction);
     89        var beforeActionOperation = ExecutionContext.CreateChildOperation(beforeAction);
    8290        opCol.Add(beforeActionOperation);
    8391      }
     
    8896
    8997    public virtual IOperation InstrumentedApply() {
     98      if (!AfterExecutionOperators.Any()) {
     99        if (Successor != null) return ExecutionContext.CreateOperation(Successor);
     100        return null;
     101      }
     102
    90103      var opCol = new OperationCollection();
    91104      foreach (var afterAction in AfterExecutionOperators) {
    92         IOperation afterActionOperation = ExecutionContext.CreateOperation(afterAction);
     105        var afterActionOperation = ExecutionContext.CreateChildOperation(afterAction);
    93106        opCol.Add(afterActionOperation);
    94107      }
     108
    95109      if (Successor != null)
    96110        opCol.Add(ExecutionContext.CreateOperation(Successor));
Note: See TracChangeset for help on using the changeset viewer.