- Timestamp:
- 01/14/22 09:49:45 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
r18194 r18195 64 64 tree = value; 65 65 66 var newFunctions = GetSubFunctions();66 var newFunctions = CreateSubFunctions(tree); 67 67 var oldFunctions = subFunctions?.Intersect(newFunctions) 68 68 ?? Enumerable.Empty<SubFunction>(); 69 69 // adds new functions and keeps the old ones (if they match) 70 subFunctions = newFunctions.Except(oldFunctions).Concat(oldFunctions).ToList(); 70 var functionsToAdd = newFunctions.Except(oldFunctions); 71 subFunctions = functionsToAdd.Concat(oldFunctions).ToList(); 72 RegisterSubFunctionEventHandlers(functionsToAdd); 71 73 } 72 74 } … … 124 126 this.applyLinearScaling = original.ApplyLinearScaling; 125 127 this.subFunctions = original.subFunctions.Select(cloner.Clone).ToList(); 126 Register EventHandlers();128 RegisterSubFunctionEventHandlers(SubFunctions); 127 129 } 128 130 … … 136 138 } 137 139 138 Register EventHandlers();140 RegisterSubFunctionEventHandlers(SubFunctions); 139 141 } 140 142 #endregion … … 151 153 } 152 154 153 private IList<SubFunction> GetSubFunctions() {155 private static IList<SubFunction> CreateSubFunctions(ISymbolicExpressionTree tree) { 154 156 var subFunctions = new List<SubFunction>(); 155 foreach (var node in Tree.IterateNodesPrefix())157 foreach (var node in tree.IterateNodesPrefix()) 156 158 if (node is SubFunctionTreeNode subFunctionTreeNode) { 157 159 if (!subFunctionTreeNode.Arguments.Any()) … … 171 173 Arguments = subFunctionTreeNode.Arguments 172 174 }; 173 subFunction.Changed += OnSubFunctionChanged;174 175 subFunctions.Add(subFunction); 175 176 } … … 178 179 } 179 180 180 private void Register EventHandlers() {181 foreach (var sf in SubFunctions) {182 sf.Changed += OnSubFunctionChanged;181 private void RegisterSubFunctionEventHandlers(IEnumerable<SubFunction> subFunctions) { 182 foreach (var sf in subFunctions) { 183 sf.Changed += (o, e) => OnChanged(); 183 184 } 184 } 185 private void OnSubFunctionChanged(object sender, EventArgs e) => OnChanged(); 185 } 186 186 } 187 187 }
Note: See TracChangeset
for help on using the changeset viewer.