Changeset 163 for trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
- Timestamp:
- 04/22/08 20:28:26 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
r155 r163 42 42 AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In)); 43 43 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 44 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));45 44 AddVariableInfo(new VariableInfo("FunctionTree", "The tree to manipulate", typeof(IFunctionTree), VariableKind.In | VariableKind.Out)); 46 45 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); … … 54 53 int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data; 55 54 int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data; 56 double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;57 55 int treeSize = GetVariableValue<IntData>("TreeSize", scope, true).Data; 58 56 int treeHeight = GetVariableValue<IntData>("TreeHeight", scope, true).Data; 59 60 57 TreeGardener gardener = new TreeGardener(random, library); 61 62 58 IFunctionTree parent = gardener.GetRandomParentNode(root); 63 59 if(parent == null) { 64 60 // parent == null means we should subsitute the whole tree 65 61 // => create a new random tree 66 67 // create a new random function tree 68 IFunctionTree newTree; 69 if(random.NextDouble() <= balancedTreesRate) { 70 newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, true); 71 } else { 72 newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, false); 73 } 74 62 IFunctionTree newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight); 75 63 if(!gardener.IsValidTree(newTree)) { 76 64 throw new InvalidProgramException(); … … 98 86 // it will be inserted 99 87 int parentLevel = gardener.GetBranchLevel(root, parent); 100 101 88 int maxSubTreeHeight = maxTreeHeight - parentLevel; 102 89 int maxSubTreeSize = maxTreeSize - (treeSize - gardener.GetTreeSize(parent.SubTrees[childIndex])); 103 90 104 91 // create a random function tree 105 IFunctionTree newTree; 106 if(random.NextDouble() <= balancedTreesRate) { 107 newTree = gardener.CreateRandomTree(allowedFunctions, maxSubTreeSize, maxSubTreeHeight, true); 108 } else { 109 newTree = gardener.CreateRandomTree(allowedFunctions, maxSubTreeSize, maxSubTreeHeight, false); 110 } 111 92 IFunctionTree newTree = gardener.CreateRandomTree(allowedFunctions, maxSubTreeSize, maxSubTreeHeight); 112 93 parent.RemoveSubTree(childIndex); 113 94 parent.InsertSubTree(childIndex, newTree);
Note: See TracChangeset
for help on using the changeset viewer.