Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/14/15 11:14:16 (10 years ago)
Author:
pfleck
Message:

#2027 Fixed problem that parameter values are not available during operator construction by using value changed events.
Note that the debug view is not working with this because of the runtime operator graph change.

File:
1 edited

Legend:

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

    r12303 r12307  
    2121
    2222using System;
    23 using HeuristicLab.Collections;
     23using System.Linq;
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     
    3030
    3131namespace HeuristicLab.Termination {
    32   [Item("Termination Operator", "An operator which either calls the terminate- or the continue branch.")]
     32  [Item("TerminationOperator", "An operator which either calls the terminate- or the continue branch.")]
    3333  [StorableClass]
    3434  public sealed class TerminationOperator : AlgorithmOperator {
     
    6060    private TerminationOperator(TerminationOperator original, Cloner cloner)
    6161      : base(original, cloner) {
     62      Initialize();
    6263    }
    6364    public override IDeepCloneable Clone(Cloner cloner) {
    6465      return new TerminationOperator(this, cloner);
    6566    }
     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(); } }
    6676
    6777    public TerminationOperator()
     
    7484      var assigner = new Assigner() { Name = "Terminate = false" };
    7585      var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" };
    76       var terminateBranch = new ConditionalBranch() { Name = "Terminate?" };
     86      var branch = new ConditionalBranch() { Name = "Terminate?" };
    7787
    7888      OperatorGraph.InitialOperator = assigner;
     
    8393
    8494      placeholder.OperatorParameter.ActualName = TerminationCriteriaParameter.Name;
    85       placeholder.Successor = terminateBranch;
     95      placeholder.Successor = branch;
     96
     97      branch.ConditionParameter.ActualName = TerminateParameter.Name;
     98
     99      Initialize();
    86100    }
    87101
    88     public override IOperation Apply() {
    89       var next = new OperationCollection(base.Apply());
    90       // ToDo Terminate available after call execution of the operator graph
    91       if (TerminateParameter.ActualValue != null && TerminateParameter.ActualValue.Value) {
    92         if (TerminateBranch != null) next.Insert(0, ExecutionContext.CreateOperation(TerminateBranch));
    93       } else {
    94         if (ContinueBranch != null) next.Insert(0, ExecutionContext.CreateOperation(ContinueBranch));
    95       }
    96       return next;
     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;
    97108    }
     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
    98124  }
    99125}
Note: See TracChangeset for help on using the changeset viewer.