Changes in trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs [2:23]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs
r2 r23 38 38 AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In)); 39 39 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 40 AddVariableInfo(new VariableInfo("Balance Trees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));40 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 41 41 AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In)); 42 42 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); … … 49 49 MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true); 50 50 GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true); 51 bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;51 double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data; 52 52 IntData treeSize = GetVariableValue<IntData>("TreeSize", scope, false); 53 53 IntData treeHeight = GetVariableValue<IntData>("TreeHeight", scope, false); … … 87 87 } else { 88 88 List<IOperator> uninitializedOperators; 89 IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balance Trees, out uninitializedOperators);89 IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balancedTreesRate, out uninitializedOperators); 90 90 91 91 if (parent == null) { … … 139 139 140 140 private IOperator ChangeFunctionType(IOperator parent, IOperator child, int childIndex, TreeGardener gardener, MersenneTwister random, 141 bool balanceTrees, out List<IOperator> uninitializedOperators) {141 double balancedTreesRate, out List<IOperator> uninitializedOperators) { 142 142 // since there are suboperators, we have to check which 143 143 // and how many of the existing suboperators we can reuse … … 197 197 availableSubOperators.Remove(selectedSubOperator); // the operator shouldn't be available for the following slots 198 198 } else { 199 IOperator freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, balanceTrees); 199 IOperator freshOperatorTree; 200 if(random.NextDouble() <= balancedTreesRate) { 201 freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true); 202 } else { 203 freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false); 204 } 200 205 freshSubTrees.AddRange(gardener.GetAllOperators(freshOperatorTree)); 201 206
Note: See TracChangeset
for help on using the changeset viewer.