Changeset 5185 for branches/ParallelEngine/HeuristicLab.SequentialEngine
- Timestamp:
- 12/31/10 04:29:19 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/ParallelEngine/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs ¶
r4722 r5185 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 27 28 namespace HeuristicLab.SequentialEngine { 28 29 /// <summary> 29 /// Represents an engine that executes its steps sequentially, also if they could be executed 30 /// in parallel. 30 /// Engine for sequential execution of algorithms. 31 31 /// </summary> 32 32 [StorableClass] 33 33 [Item("Sequential Engine", "Engine for sequential execution of algorithms.")] 34 34 public class SequentialEngine : Engine { 35 private IOperator currentOperator;36 37 35 [StorableConstructor] 38 36 protected SequentialEngine(bool deserializing) : base(deserializing) { } … … 44 42 } 45 43 46 /// <summary> 47 /// Deals with the next operation, if it is an <see cref="AtomicOperation"/> it is executed, 48 /// if it is a <see cref="CompositeOperation"/> its single operations are pushed on the execution stack. 49 /// </summary> 50 /// <remarks>If an error occurs during the execution the operation is aborted and the operation 51 /// is pushed on the stack again.<br/> 52 /// If the execution was successful <see cref="EngineBase.OnOperationExecuted"/> is called.</remarks> 53 protected override void ProcessNextOperation() { 54 currentOperator = null; 55 IOperation next = ExecutionStack.Pop(); 56 OperationCollection coll = next as OperationCollection; 57 while (coll != null) { 58 for (int i = coll.Count - 1; i >= 0; i--) 59 ExecutionStack.Push(coll[i]); 60 next = ExecutionStack.Count > 0 ? ExecutionStack.Pop() : null; 61 coll = next as OperationCollection; 62 } 63 IAtomicOperation operation = next as IAtomicOperation; 64 if (operation != null) { 65 try { 66 currentOperator = operation.Operator; 67 ExecutionStack.Push(operation.Operator.Execute((IExecutionContext)operation)); 68 } 69 catch (Exception ex) { 70 ExecutionStack.Push(operation); 71 OnExceptionOccurred(new OperatorExecutionException(operation.Operator, ex)); 72 Pause(); 73 } 74 if (operation.Operator.Breakpoint) { 75 Log.LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName)); 76 Pause(); 44 protected override void Run(CancellationToken cancellationToken) { 45 IOperation next; 46 OperationCollection coll; 47 IAtomicOperation operation; 48 49 while (ExecutionStack.Count > 0) { 50 cancellationToken.ThrowIfCancellationRequested(); 51 52 next = ExecutionStack.Pop(); 53 if (next is OperationCollection) { 54 coll = (OperationCollection)next; 55 for (int i = coll.Count - 1; i >= 0; i--) 56 if (coll[i] != null) ExecutionStack.Push(coll[i]); 57 } else if (next is IAtomicOperation) { 58 operation = (IAtomicOperation)next; 59 try { 60 next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken); 61 } 62 catch (Exception ex) { 63 ExecutionStack.Push(operation); 64 throw new OperatorExecutionException(operation.Operator, ex); 65 } 66 if (next != null) ExecutionStack.Push(next); 67 68 if (operation.Operator.Breakpoint) { 69 Log.LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName)); 70 Pause(); 71 } 77 72 } 78 73 } 79 74 } 80 81 public override void Pause() {82 base.Pause();83 if (currentOperator != null) currentOperator.Abort();84 }85 public override void Stop() {86 base.Stop();87 if (currentOperator != null) currentOperator.Abort();88 }89 75 } 90 76 }
Note: See TracChangeset
for help on using the changeset viewer.