1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.FixedOperators {
|
---|
30 | class FixedBase : CombinedOperator {
|
---|
31 |
|
---|
32 | protected virtual void Execute(IOperator op, IScope scope){
|
---|
33 | IOperation operation;
|
---|
34 | IOperator currentOperator;
|
---|
35 | Stack<IOperation> executionStack = new Stack<IOperation>();
|
---|
36 | executionStack.Push(op.Execute(scope));
|
---|
37 |
|
---|
38 | while (executionStack.Count > 0) {
|
---|
39 | operation = executionStack.Pop();
|
---|
40 | if (operation is AtomicOperation) {
|
---|
41 | AtomicOperation atomicOperation = (AtomicOperation)operation;
|
---|
42 | IOperation next = null;
|
---|
43 | try {
|
---|
44 | currentOperator = atomicOperation.Operator;
|
---|
45 | next = atomicOperation.Operator.Execute(atomicOperation.Scope);
|
---|
46 | }
|
---|
47 | catch (Exception) {
|
---|
48 | // push operation on stack again
|
---|
49 | executionStack.Push(atomicOperation);
|
---|
50 | //Abort();
|
---|
51 | //ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
|
---|
52 | throw new InvalidOperationException("Invalid Operation occured in FixedBase.Execute");
|
---|
53 | }
|
---|
54 | if (next != null)
|
---|
55 | executionStack.Push(next);
|
---|
56 | //OnOperationExecuted(atomicOperation);
|
---|
57 | //if (atomicOperation.Operator.Breakpoint) Abort();
|
---|
58 | } else if (operation is CompositeOperation) {
|
---|
59 | CompositeOperation compositeOperation = (CompositeOperation)operation;
|
---|
60 | for (int i = compositeOperation.Operations.Count - 1; i >= 0; i--)
|
---|
61 | executionStack.Push(compositeOperation.Operations[i]);
|
---|
62 | } // else if
|
---|
63 | } // while
|
---|
64 | } // Execute
|
---|
65 |
|
---|
66 | } // class FixedBase
|
---|
67 | } // namespace HeuristicLab.FixedOperators
|
---|