Changeset 10483 for branches/LogResidualEvaluator/HeuristicLab.Operators/3.3/InstrumentedOperator.cs
- Timestamp:
- 02/20/14 14:56:39 (11 years ago)
- Location:
- branches/LogResidualEvaluator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LogResidualEvaluator
- Property svn:mergeinfo changed
-
branches/LogResidualEvaluator/HeuristicLab.Operators/3.3/InstrumentedOperator.cs
r10149 r10483 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 28 30 [Item("InstrumentedOperator", "A operator that can execute pre- and post actions.")] 29 31 [StorableClass] 30 public abstract class InstrumentedOperator : SingleSuccessorOperator {32 public abstract class InstrumentedOperator : SingleSuccessorOperator, IInstrumentedOperator { 31 33 private const string BeforeExecutionOperatorsParameterName = "BeforeExecutionOperators"; 32 34 private const string AfterExecutionOperatorsParameterName = "AfterExecutionOperators"; 33 35 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]; } 36 38 } 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]; } 39 41 } 40 42 41 public ItemList<SingleSuccessorOperator> BeforeExecutionOperators { 43 44 IEnumerable<IOperator> IInstrumentedOperator.BeforeExecutionOperators { get { return BeforeExecutionOperators; } } 45 public OperatorList BeforeExecutionOperators { 42 46 get { return BeforeExecutionOperatorsParameter.Value; } 43 47 } 44 public ItemList<SingleSuccessorOperator> AfterExecutionOperators { 48 IEnumerable<IOperator> IInstrumentedOperator.AfterExecutionOperators { get { return AfterExecutionOperators; } } 49 public OperatorList AfterExecutionOperators { 45 50 get { return AfterExecutionOperatorsParameter.Value; } 46 51 } … … 53 58 protected InstrumentedOperator() 54 59 : 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())); 57 62 BeforeExecutionOperatorsParameter.Hidden = true; 58 63 AfterExecutionOperatorsParameter.Hidden = true; … … 64 69 #region Backwards compatible code, remove with 3.4 65 70 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())); 67 72 BeforeExecutionOperatorsParameter.Hidden = true; 68 73 } 69 74 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())); 71 76 AfterExecutionOperatorsParameter.Hidden = true; 72 77 } … … 75 80 76 81 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(); 78 85 79 86 //build before operations 87 var opCol = new OperationCollection(); 80 88 foreach (var beforeAction in BeforeExecutionOperators) { 81 IOperation beforeActionOperation = ExecutionContext.CreateOperation(beforeAction);89 var beforeActionOperation = ExecutionContext.CreateChildOperation(beforeAction); 82 90 opCol.Add(beforeActionOperation); 83 91 } … … 88 96 89 97 public virtual IOperation InstrumentedApply() { 98 if (!AfterExecutionOperators.Any()) { 99 if (Successor != null) return ExecutionContext.CreateOperation(Successor); 100 return null; 101 } 102 90 103 var opCol = new OperationCollection(); 91 104 foreach (var afterAction in AfterExecutionOperators) { 92 IOperation afterActionOperation = ExecutionContext.CreateOperation(afterAction);105 var afterActionOperation = ExecutionContext.CreateChildOperation(afterAction); 93 106 opCol.Add(afterActionOperation); 94 107 } 108 95 109 if (Successor != null) 96 110 opCol.Add(ExecutionContext.CreateOperation(Successor));
Note: See TracChangeset
for help on using the changeset viewer.