Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableSingleSuccessorOperator.cs @ 4828

Last change on this file since 4828 was 4828, checked in by epitzer, 13 years ago

Add ProgrammableSingleSuccessorOperator that properly handles a successor if present (#1275)

File size: 1.5 KB
Line 
1
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Parameters;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6namespace HeuristicLab.Operators.Programmable {
7
8  [Item("ProgrammableSingleSuccessorOperator", "An operator that can be programmed for arbitrary needs and handle a single successor.")]
9  [StorableClass]
10  public class ProgrammableSingleSuccessorOperator : ProgrammableOperator {
11
12    [StorableConstructor]
13    protected ProgrammableSingleSuccessorOperator(bool deserializing) : base(deserializing) { }
14    protected ProgrammableSingleSuccessorOperator(ProgrammableSingleSuccessorOperator original, Cloner cloner)
15      : base(original, cloner) {
16    }
17    public ProgrammableSingleSuccessorOperator()
18      : base() {
19      Parameters.Add(new OperatorParameter("Successor", "Operator that is executed next."));
20    }
21
22    public override IDeepCloneable Clone(Cloner cloner) {
23      return new ProgrammableSingleSuccessorOperator(this, cloner);
24    }
25
26    public override IOperation Apply() {
27      IOperation operation = base.Apply();
28      if (operation != null)
29        return operation;
30      IParameter parameter;
31      Parameters.TryGetValue("Successor", out parameter);
32      OperatorParameter successorParameter = parameter as OperatorParameter;
33      if (successorParameter != null && successorParameter.Value != null)
34        return ExecutionContext.CreateOperation(successorParameter.Value);
35      else
36        return null;
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.