Changeset 12308


Ignore:
Timestamp:
04/14/15 12:29:11 (7 years ago)
Author:
pfleck
Message:

#2027 Used an InstrumentedOperator instead of an AlgorithmOperator and added the operators to the BeforeExecutionOperators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/TerminationOperator.cs

    r12307 r12308  
    3232  [Item("TerminationOperator", "An operator which either calls the terminate- or the continue branch.")]
    3333  [StorableClass]
    34   public sealed class TerminationOperator : AlgorithmOperator {
     34  public sealed class TerminationOperator : InstrumentedOperator {
    3535    public ILookupParameter<ITerminationCriterion> TerminationCriteriaParameter {
    3636      get { return (ILookupParameter<ITerminationCriterion>)Parameters["TerminationCriteria"]; }
     
    5757    [StorableConstructor]
    5858    private TerminationOperator(bool deserializing) : base(deserializing) { }
    59 
    6059    private TerminationOperator(TerminationOperator original, Cloner cloner)
    6160      : base(original, cloner) {
    62       Initialize();
    6361    }
    6462    public override IDeepCloneable Clone(Cloner cloner) {
    6563      return new TerminationOperator(this, cloner);
    6664    }
    67     [StorableHook(HookType.AfterDeserialization)]
    68     private void AfterDeserialization() {
    69       Initialize();
    70     }
    71 
    72 
    73     private Assigner Assigner { get { return OperatorGraph.Iterate().OfType<Assigner>().Single(); } }
    74     private Placeholder Placeholder { get { return OperatorGraph.Iterate().OfType<Placeholder>().Single(); } }
    75     private ConditionalBranch Branch { get { return OperatorGraph.Iterate().OfType<ConditionalBranch>().Single(); } }
    7665
    7766    public TerminationOperator()
     
    8372
    8473      var assigner = new Assigner() { Name = "Terminate = false" };
    85       var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" };
    86       var branch = new ConditionalBranch() { Name = "Terminate?" };
    87 
    88       OperatorGraph.InitialOperator = assigner;
    89 
    9074      assigner.LeftSideParameter.ActualName = TerminateParameter.Name;
    9175      assigner.RightSideParameter.Value = new BoolValue(false);
    92       assigner.Successor = placeholder;
    9376
     77      var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" };
    9478      placeholder.OperatorParameter.ActualName = TerminationCriteriaParameter.Name;
    95       placeholder.Successor = branch;
    9679
    97       branch.ConditionParameter.ActualName = TerminateParameter.Name;
    98 
    99       Initialize();
     80      BeforeExecutionOperators.Add(assigner);
     81      BeforeExecutionOperators.Add(placeholder);
    10082    }
    10183
    102     private void Initialize() {
    103       TerminateBranchParameter.ValueChanged += TerminateBranchParameter_ValueChanged;
    104       ContinueBranchParameter.ValueChanged += ContinueBranchParameter_ValueChanged;
    105 
    106       TerminateParameter.ActualNameChanged += TerminateParameter_ActualNameChanged;
    107       TerminationCriteriaParameter.ActualNameChanged += TerminationCriteriaParameter_ActualNameChanged;
     84    public override IOperation InstrumentedApply() {
     85      var next = new OperationCollection(base.InstrumentedApply());
     86      if (TerminateParameter.ActualValue != null && TerminateParameter.ActualValue.Value) {
     87        if (TerminateBranch != null) next.Insert(0, ExecutionContext.CreateOperation(TerminateBranch));
     88      } else {
     89        if (ContinueBranch != null) next.Insert(0, ExecutionContext.CreateOperation(ContinueBranch));
     90      }
     91      return next;
    10892    }
    109 
    110     #region Events
    111     private void TerminateBranchParameter_ValueChanged(object s, EventArgs e) {
    112       Branch.TrueBranch = TerminateBranch;
    113     }
    114     private void ContinueBranchParameter_ValueChanged(object s, EventArgs e) {
    115       Branch.FalseBranch = ContinueBranch;
    116     }
    117     private void TerminateParameter_ActualNameChanged(object s, EventArgs e) {
    118       Assigner.LeftSideParameter.ActualName = TerminateParameter.ActualName;
    119     }
    120     private void TerminationCriteriaParameter_ActualNameChanged(object s, EventArgs e) {
    121       Placeholder.OperatorParameter.ActualName = TerminationCriteriaParameter.ActualName;
    122     }
    123     #endregion
    12493  }
    12594}
Note: See TracChangeset for help on using the changeset viewer.