- Timestamp:
- 02/21/08 11:45:52 (17 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification/Manipulation
- Files:
-
- 4 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 -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/CutOutNodeManipulation.cs
r2 r23 52 52 AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In)); 53 53 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 54 AddVariableInfo(new VariableInfo("Balance Trees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));54 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 55 55 AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In)); 56 56 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); … … 65 65 int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data; 66 66 int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data; 67 bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;67 double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data; 68 68 69 69 TreeGardener gardener = new TreeGardener(random, library); … … 95 95 } else { 96 96 // create a new random tree 97 IOperator newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, balanceTrees); 97 IOperator newOperator; 98 if(random.NextDouble() <= balancedTreesRate) { 99 newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, true); 100 } else { 101 newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, false); 102 } 98 103 99 104 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newOperator); -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs
r2 r23 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("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));45 44 AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In | VariableKind.Out)); 46 45 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
r2 r23 41 41 AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In)); 42 42 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 43 AddVariableInfo(new VariableInfo("Balance Trees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));43 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 44 44 AddVariableInfo(new VariableInfo("OperatorTree", "The tree to manipulate", typeof(IOperator), VariableKind.In)); 45 45 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); … … 54 54 int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data; 55 55 int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data; 56 bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;56 double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data; 57 57 int treeSize = GetVariableValue<IntData>("TreeSize", scope, true).Data; 58 58 int treeHeight = GetVariableValue<IntData>("TreeHeight", scope, true).Data; … … 66 66 67 67 // create a new random operator tree 68 IOperator newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, balanceTrees); 68 69 IOperator newOperatorTree; 70 if(random.NextDouble() <= balancedTreesRate) { 71 newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, true); 72 } else { 73 newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, false); 74 } 69 75 70 76 if(!gardener.IsValidTree(newOperatorTree)) { … … 100 106 101 107 // get a random operatorTree 102 IOperator newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, balanceTrees); 108 IOperator newOperatorTree; 109 if(random.NextDouble() <= balancedTreesRate) { 110 newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true); 111 } else { 112 newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false); 113 } 103 114 104 115 IOperator oldChild = parent.SubOperators[childIndex];
Note: See TracChangeset
for help on using the changeset viewer.