- Timestamp:
- 04/28/08 21:35:23 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs ¶
r189 r202 156 156 int maxArity; 157 157 // create a new tree-node for a randomly selected function 158 IFunction Tree newTree = allowedFunctions[random.Next(allowedFunctions.Count)].GetTreeNode();159 gardener.GetMinMaxArity( newTree.Function, out minArity, out maxArity);158 IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)]; 159 gardener.GetMinMaxArity(selectedFunction, out minArity, out maxArity); 160 160 // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible 161 161 if (actualArity > maxArity) … … 165 165 // create a list that holds old sub-trees that we can reuse in the new tree 166 166 List<IFunctionTree> availableSubTrees = new List<IFunctionTree>(child.SubTrees); 167 List<IFunctionTree> freshSubTrees = new List<IFunctionTree>() { newTree }; 167 List<IFunctionTree> freshSubTrees = new List<IFunctionTree>(); 168 IFunctionTree newTree = selectedFunction.GetTreeNode(); 168 169 // randomly select the sub-trees that we keep 169 170 for (int i = 0; i < actualArity; i++) { … … 172 173 // then use a random existing sub-tree. When there are no existing sub-trees 173 174 // that fit in the given slot then create a new random tree and use it for the slot 174 ICollection<IFunction> allowedSubFunctions = gardener.GetAllowedSubFunctions( newTree.Function, i);175 ICollection<IFunction> allowedSubFunctions = gardener.GetAllowedSubFunctions(selectedFunction, i); 175 176 var matchingSubTrees = availableSubTrees.Where(subTree => allowedSubFunctions.Contains(subTree.Function)); 176 177 if (matchingSubTrees.Count() > 0) { … … 186 187 } 187 188 } 189 freshSubTrees.Add(newTree); 188 190 uninitializedBranches = freshSubTrees; 189 191 return newTree;
Note: See TracChangeset
for help on using the changeset viewer.