Changeset 12308
- Timestamp:
- 04/14/15 12:29:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TerminationCriteria/HeuristicLab.Termination/3.3/TerminationOperator.cs
r12307 r12308 32 32 [Item("TerminationOperator", "An operator which either calls the terminate- or the continue branch.")] 33 33 [StorableClass] 34 public sealed class TerminationOperator : AlgorithmOperator {34 public sealed class TerminationOperator : InstrumentedOperator { 35 35 public ILookupParameter<ITerminationCriterion> TerminationCriteriaParameter { 36 36 get { return (ILookupParameter<ITerminationCriterion>)Parameters["TerminationCriteria"]; } … … 57 57 [StorableConstructor] 58 58 private TerminationOperator(bool deserializing) : base(deserializing) { } 59 60 59 private TerminationOperator(TerminationOperator original, Cloner cloner) 61 60 : base(original, cloner) { 62 Initialize();63 61 } 64 62 public override IDeepCloneable Clone(Cloner cloner) { 65 63 return new TerminationOperator(this, cloner); 66 64 } 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(); } }76 65 77 66 public TerminationOperator() … … 83 72 84 73 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 90 74 assigner.LeftSideParameter.ActualName = TerminateParameter.Name; 91 75 assigner.RightSideParameter.Value = new BoolValue(false); 92 assigner.Successor = placeholder;93 76 77 var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" }; 94 78 placeholder.OperatorParameter.ActualName = TerminationCriteriaParameter.Name; 95 placeholder.Successor = branch;96 79 97 branch.ConditionParameter.ActualName = TerminateParameter.Name; 98 99 Initialize(); 80 BeforeExecutionOperators.Add(assigner); 81 BeforeExecutionOperators.Add(placeholder); 100 82 } 101 83 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; 108 92 } 109 110 #region Events111 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 #endregion124 93 } 125 94 }
Note: See TracChangeset
for help on using the changeset viewer.