Changeset 5177 for branches/ParallelEngine/HeuristicLab.Operators
- Timestamp:
- 12/26/10 03:51:30 (14 years ago)
- Location:
- branches/ParallelEngine/HeuristicLab.Operators/3.3
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ParallelEngine/HeuristicLab.Operators/3.3/AlgorithmOperator.cs
r4722 r5177 55 55 } 56 56 57 public override IOperation Apply( ) {58 OperationCollection next = new OperationCollection(base.Apply( ));57 public override IOperation Apply(IExecutionContext context) { 58 OperationCollection next = new OperationCollection(base.Apply(context)); 59 59 if (operatorGraph.InitialOperator != null) 60 next.Insert(0, ExecutionContext.CreateChildOperation(operatorGraph.InitialOperator));60 next.Insert(0, context.CreateChildOperation(operatorGraph.InitialOperator)); 61 61 return next; 62 62 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/Assigner.cs
r4722 r5177 54 54 } 55 55 56 public override IOperation Apply( ) {56 public override IOperation Apply(IExecutionContext context) { 57 57 LeftSideParameter.ActualValue = (IItem)RightSideParameter.ActualValue.Clone(); 58 return base.Apply( );58 return base.Apply(context); 59 59 } 60 60 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/Comparator.cs
r4722 r5177 68 68 } 69 69 70 public override IOperation Apply( ) {70 public override IOperation Apply(IExecutionContext context) { 71 71 IItem left = LeftSideParameter.ActualValue; 72 72 IItem right = RightSideParameter.ActualValue; … … 91 91 } 92 92 ResultParameter.ActualValue = new BoolValue(b); 93 return base.Apply( );93 return base.Apply(context); 94 94 } 95 95 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/ConditionalBranch.cs
r4722 r5177 67 67 } 68 68 69 public override IOperation Apply( ) {70 OperationCollection next = new OperationCollection(base.Apply( ));69 public override IOperation Apply(IExecutionContext context) { 70 OperationCollection next = new OperationCollection(base.Apply(context)); 71 71 if (ConditionParameter.ActualValue != null && ConditionParameter.ActualValue.Value) { 72 if (TrueBranch != null) next.Insert(0, ExecutionContext.CreateOperation(TrueBranch));72 if (TrueBranch != null) next.Insert(0, context.CreateOperation(TrueBranch)); 73 73 } else { 74 if (FalseBranch != null) next.Insert(0, ExecutionContext.CreateOperation(FalseBranch));74 if (FalseBranch != null) next.Insert(0, context.CreateOperation(FalseBranch)); 75 75 } 76 76 return next; -
branches/ParallelEngine/HeuristicLab.Operators/3.3/DoubleCounter.cs
r4722 r5177 59 59 } 60 60 61 public override IOperation Apply( ) {61 public override IOperation Apply(IExecutionContext context) { 62 62 if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new DoubleValue(); 63 63 ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value; 64 return base.Apply( );64 return base.Apply(context); 65 65 } 66 66 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/IntCounter.cs
r4722 r5177 59 59 } 60 60 61 public override IOperation Apply( ) {61 public override IOperation Apply(IExecutionContext context) { 62 62 if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntValue(); 63 63 ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value; 64 return base.Apply( );64 return base.Apply(context); 65 65 } 66 66 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/Operator.cs
r4722 r5177 28 28 namespace HeuristicLab.Operators { 29 29 /// <summary> 30 /// The base class for alloperators.30 /// Base class for operators. 31 31 /// </summary> 32 32 [Item("Operator", "Base class for operators.")] … … 43 43 } 44 44 45 [Storable]46 private IExecutionContext executionContext;47 protected IExecutionContext ExecutionContext {48 get { return executionContext; }49 private set {50 if (value != executionContext) {51 executionContext = value;52 OnExecutionContextChanged();53 }54 }55 }56 57 /// <summary>58 /// Flag whether the current instance has been canceled.59 /// </summary>60 45 private bool canceled; 61 /// <inheritdoc/>62 46 protected bool Canceled { 63 47 get { return canceled; } … … 72 56 [Storable] 73 57 private bool breakpoint; 74 /// <inheritdoc/>75 /// <remarks>Calls <see cref="OnBreakpointChanged"/> in the setter.</remarks>76 58 public bool Breakpoint { 77 59 get { return breakpoint; } … … 91 73 this.canceled = original.canceled; 92 74 this.breakpoint = original.breakpoint; 93 this.executionContext = cloner.Clone<IExecutionContext>(original.executionContext);94 75 } 95 /// <summary>96 /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and97 /// the canceled flag to <c>false</c> and the name of the operator to the type name.98 /// </summary>99 76 protected Operator() 100 77 : base() { … … 123 100 } 124 101 125 /// <inheritdoc/>126 102 public virtual IOperation Execute(IExecutionContext context) { 127 103 try { 128 104 Canceled = false; 129 ExecutionContext = context;130 105 foreach (IParameter param in Parameters) 131 106 param.ExecutionContext = context; 132 IOperation next = Apply( );107 IOperation next = Apply(context); 133 108 OnExecuted(); 134 109 return next; … … 137 112 foreach (IParameter param in Parameters) 138 113 param.ExecutionContext = null; 139 ExecutionContext = null;140 114 } 141 115 } 142 /// <inheritdoc/>143 /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks>144 116 public void Abort() { 145 117 Canceled = true; 146 118 } 147 /// <summary> 148 /// Performs the current operator on the specified <paramref name="scope"/>. 149 /// </summary> 150 /// <param name="scope">The scope where to execute the operator</param> 151 /// <returns><c>null</c>.</returns> 152 public abstract IOperation Apply(); 119 public abstract IOperation Apply(IExecutionContext context); 153 120 154 protected virtual void OnExecutionContextChanged() { }155 121 protected virtual void OnCanceledChanged() { } 156 /// <inheritdoc/>157 122 public event EventHandler BreakpointChanged; 158 /// <summary>159 /// Fires a new <c>BreakpointChanged</c> event.160 /// </summary>161 123 protected virtual void OnBreakpointChanged() { 162 124 if (BreakpointChanged != null) { … … 164 126 } 165 127 } 166 /// <inheritdoc/>167 128 public event EventHandler Executed; 168 /// <summary>169 /// Fires a new <c>Executed</c> event.170 /// </summary>171 129 protected virtual void OnExecuted() { 172 130 if (Executed != null) { -
branches/ParallelEngine/HeuristicLab.Operators/3.3/Placeholder.cs
r4722 r5177 50 50 } 51 51 52 public override IOperation Apply( ) {53 OperationCollection next = new OperationCollection(base.Apply( ));52 public override IOperation Apply(IExecutionContext context) { 53 OperationCollection next = new OperationCollection(base.Apply(context)); 54 54 IOperator op = OperatorParameter.ActualValue; 55 55 if (op != null) 56 next.Insert(0, ExecutionContext.CreateOperation(op));56 next.Insert(0, context.CreateOperation(op)); 57 57 return next; 58 58 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/ScopeCleaner.cs
r4722 r5177 53 53 } 54 54 55 public override IOperation Apply( ) {55 public override IOperation Apply(IExecutionContext context) { 56 56 CurrentScope.Variables.Clear(); 57 57 CurrentScope.SubScopes.Clear(); 58 return base.Apply( );58 return base.Apply(context); 59 59 } 60 60 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs
r4722 r5177 50 50 } 51 51 52 public override IOperation Apply( ) {52 public override IOperation Apply(IExecutionContext context) { 53 53 if (Successor != null) 54 return ExecutionContext.CreateOperation(Successor);54 return context.CreateOperation(Successor); 55 55 else 56 56 return null; -
branches/ParallelEngine/HeuristicLab.Operators/3.3/StochasticBranch.cs
r4722 r5177 71 71 } 72 72 73 public override IOperation Apply( ) {74 OperationCollection next = new OperationCollection(base.Apply( ));73 public override IOperation Apply(IExecutionContext context) { 74 OperationCollection next = new OperationCollection(base.Apply(context)); 75 75 if (RandomParameter.ActualValue.NextDouble() < ProbabilityParameter.ActualValue.Value) { 76 if (FirstBranch != null) next.Insert(0, ExecutionContext.CreateOperation(FirstBranch));76 if (FirstBranch != null) next.Insert(0, context.CreateOperation(FirstBranch)); 77 77 } else { 78 if (SecondBranch != null) next.Insert(0, ExecutionContext.CreateOperation(SecondBranch));78 if (SecondBranch != null) next.Insert(0, context.CreateOperation(SecondBranch)); 79 79 } 80 80 return next; -
branches/ParallelEngine/HeuristicLab.Operators/3.3/StochasticMultiBranch.cs
r4722 r5177 109 109 /// or all selected operators have zero probabitlity.</exception> 110 110 /// <returns>A new operation with the operator that was selected followed by the current operator's successor.</returns> 111 public override IOperation Apply( ) {111 public override IOperation Apply(IExecutionContext context) { 112 112 IRandom random = RandomParameter.ActualValue; 113 113 DoubleArray probabilities = ProbabilitiesParameter.ActualValue; … … 131 131 } 132 132 } 133 OperationCollection next = new OperationCollection(base.Apply( ));133 OperationCollection next = new OperationCollection(base.Apply(context)); 134 134 if (successor != null) { 135 135 if (CreateChildOperation) 136 next.Insert(0, ExecutionContext.CreateChildOperation(successor));137 else next.Insert(0, ExecutionContext.CreateOperation(successor));136 next.Insert(0, context.CreateChildOperation(successor)); 137 else next.Insert(0, context.CreateOperation(successor)); 138 138 } 139 139 return next; -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SubScopesCreator.cs
r4722 r5177 58 58 } 59 59 60 public override IOperation Apply( ) {60 public override IOperation Apply(IExecutionContext context) { 61 61 int n = NumberOfSubScopesParameter.ActualValue.Value; 62 62 for (int i = 0; i < n; i++) 63 63 CurrentScope.SubScopes.Add(new Scope(i.ToString())); 64 return base.Apply( );64 return base.Apply(context); 65 65 } 66 66 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SubScopesMixer.cs
r4722 r5177 77 77 /// <param name="scope">The scope whose sub scopes should be mixed.</param> 78 78 /// <returns><c>null</c>.</returns> 79 public override IOperation Apply( ) {79 public override IOperation Apply(IExecutionContext context) { 80 80 int partitions = Partitions.Value; 81 IScope scope = ExecutionContext.Scope;81 IScope scope = context.Scope; 82 82 int count = scope.SubScopes.Count; 83 83 if ((count % partitions) != 0) … … 96 96 scope.SubScopes.AddRange(reorderedSubScopes); 97 97 98 return base.Apply( );98 return base.Apply(context); 99 99 } 100 100 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SubScopesProcessor.cs
r4722 r5177 67 67 } 68 68 69 public override IOperation Apply( ) {70 List<IScope> scopes = GetScopesOnLevel( ExecutionContext.Scope, Depth.Value).ToList();71 OperationCollection next = new OperationCollection(base.Apply( ));69 public override IOperation Apply(IExecutionContext context) { 70 List<IScope> scopes = GetScopesOnLevel(context.Scope, Depth.Value).ToList(); 71 OperationCollection next = new OperationCollection(base.Apply(context)); 72 72 if (scopes.Count != Operators.Count) 73 73 throw new ArgumentException("The number of operators doesn't match the number of sub-scopes at depth " + Depth.Value); … … 75 75 inner.Parallel = Parallel == null ? false : Parallel.Value; 76 76 for (int i = 0; i < scopes.Count(); i++) { 77 inner.Add( ExecutionContext.CreateOperation(Operators[i], scopes[i]));77 inner.Add(context.CreateOperation(Operators[i], scopes[i])); 78 78 } 79 79 next.Insert(0, inner); -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SubScopesRemover.cs
r4722 r5177 67 67 } 68 68 69 public override IOperation Apply( ) {69 public override IOperation Apply(IExecutionContext context) { 70 70 if (RemoveAllSubScopes) 71 71 CurrentScope.SubScopes.Clear(); … … 73 73 CurrentScope.SubScopes.RemoveAt(SubScopeIndexParameter.ActualValue.Value); 74 74 } 75 return base.Apply( );75 return base.Apply(context); 76 76 } 77 77 } -
branches/ParallelEngine/HeuristicLab.Operators/3.3/SubScopesSorter.cs
r4722 r5177 65 65 } 66 66 67 public override IOperation Apply( ) {67 public override IOperation Apply(IExecutionContext context) { 68 68 descending = DescendingParameter.ActualValue.Value; 69 69 actualName = ValueParameter.TranslatedName; 70 70 CurrentScope.SubScopes.Sort(SortScopes); 71 return base.Apply( );71 return base.Apply(context); 72 72 } 73 73 -
branches/ParallelEngine/HeuristicLab.Operators/3.3/UniformSubScopesProcessor.cs
r4722 r5177 74 74 } 75 75 76 public override IOperation Apply( ) {77 OperationCollection next = new OperationCollection(base.Apply( ));76 public override IOperation Apply(IExecutionContext context) { 77 OperationCollection next = new OperationCollection(base.Apply(context)); 78 78 if (Operator != null) { 79 List<IScope> scopes = GetScopesOnLevel( ExecutionContext.Scope, Depth.Value).ToList();79 List<IScope> scopes = GetScopesOnLevel(context.Scope, Depth.Value).ToList(); 80 80 OperationCollection inner = new OperationCollection(); 81 81 inner.Parallel = Parallel == null ? false : Parallel.Value; 82 82 for (int i = 0; i < scopes.Count; i++) { 83 inner.Add( ExecutionContext.CreateOperation(Operator, scopes[i]));83 inner.Add(context.CreateOperation(Operator, scopes[i])); 84 84 } 85 85 next.Insert(0, inner); -
branches/ParallelEngine/HeuristicLab.Operators/3.3/VariableCreator.cs
r4722 r5177 53 53 } 54 54 55 public override IOperation Apply( ) {55 public override IOperation Apply(IExecutionContext context) { 56 56 IVariable var; 57 57 foreach (IParameter param in CollectedValues) { … … 66 66 CurrentScope.Variables.Add(new Variable(name, param.Description, value == null ? null : (IItem)value.Clone())); 67 67 } 68 return base.Apply( );68 return base.Apply(context); 69 69 } 70 70 }
Note: See TracChangeset
for help on using the changeset viewer.