Changeset 12307 for branches/TerminationCriteria
- Timestamp:
- 04/14/15 11:14:16 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TerminationCriteria/HeuristicLab.Termination/3.3/TerminationOperator.cs
r12303 r12307 21 21 22 22 using System; 23 using HeuristicLab.Collections;23 using System.Linq; 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; … … 30 30 31 31 namespace HeuristicLab.Termination { 32 [Item("Termination 32 [Item("TerminationOperator", "An operator which either calls the terminate- or the continue branch.")] 33 33 [StorableClass] 34 34 public sealed class TerminationOperator : AlgorithmOperator { … … 60 60 private TerminationOperator(TerminationOperator original, Cloner cloner) 61 61 : base(original, cloner) { 62 Initialize(); 62 63 } 63 64 public override IDeepCloneable Clone(Cloner cloner) { 64 65 return new TerminationOperator(this, cloner); 65 66 } 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(); } } 66 76 67 77 public TerminationOperator() … … 74 84 var assigner = new Assigner() { Name = "Terminate = false" }; 75 85 var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" }; 76 var terminateBranch = new ConditionalBranch() { Name = "Terminate?" };86 var branch = new ConditionalBranch() { Name = "Terminate?" }; 77 87 78 88 OperatorGraph.InitialOperator = assigner; … … 83 93 84 94 placeholder.OperatorParameter.ActualName = TerminationCriteriaParameter.Name; 85 placeholder.Successor = terminateBranch; 95 placeholder.Successor = branch; 96 97 branch.ConditionParameter.ActualName = TerminateParameter.Name; 98 99 Initialize(); 86 100 } 87 101 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; 97 108 } 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 98 124 } 99 125 }
Note: See TracChangeset
for help on using the changeset viewer.