Changeset 143 for branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation
- Timestamp:
- 04/21/08 15:31:41 (17 years ago)
- Location:
- branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs
r142 r143 84 84 // size and height stays the same when changing a terminal so no need to update the variables 85 85 // schedule an operation to initialize the new terminal 86 return gardener.CreateInitializationOperation(gardener.GetAll Operators(newTerminal), scope);86 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTerminal), scope); 87 87 } else { 88 88 List<IFunctionTree> uninitializedBranches; … … 147 147 IList<IOperator> allowedSubOperators; 148 148 SubOperatorsConstraintAnalyser analyser = new SubOperatorsConstraintAnalyser(); 149 analyser.AllPossibleOperators = gardener.All Operators;149 analyser.AllPossibleOperators = gardener.AllFunctions; 150 150 if (parent == null) { 151 allowedSubOperators = gardener.All Operators;151 allowedSubOperators = gardener.AllFunctions; 152 152 } else { 153 153 allowedSubOperators = analyser.GetAllowedOperators(parent, childIndex); … … 203 203 freshTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false); 204 204 } 205 freshSubTrees.AddRange(gardener.GetAll Operators(freshTree));205 freshSubTrees.AddRange(gardener.GetAllSubTrees(freshTree)); 206 206 207 207 newTree.InsertSubTree(i, freshTree); -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/CutOutNodeManipulation.cs
r23 r143 27 27 using HeuristicLab.Random; 28 28 using System; 29 using HeuristicLab.Functions; 29 30 30 31 namespace HeuristicLab.StructureIdentification { … … 32 33 public override string Description { 33 34 get { 34 return @"Takes a tree, selects a random node of the tree and then tries to replace a random child35 return @"Takes a tree, selects a random node of the tree and then tries to replace a random sub-tree 35 36 of that node with one of the childs of the selected child. 36 37 … … 53 54 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 54 55 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 55 AddVariableInfo(new VariableInfo(" OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));56 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In ));57 AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In ));56 AddVariableInfo(new VariableInfo("FunctionTree", "The tree to mutate", typeof(IFunctionTree), VariableKind.In | VariableKind.Out)); 57 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); 58 AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); 58 59 } 59 60 60 61 61 62 public override IOperation Apply(IScope scope) { 62 I Operator rootOperator = GetVariableValue<IOperator>("OperatorTree", scope, true);63 IFunctionTree root = GetVariableValue<IFunctionTree>("FunctionTree", scope, true); 63 64 MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true); 64 65 GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true); … … 68 69 69 70 TreeGardener gardener = new TreeGardener(random, library); 70 I Operator parent = gardener.GetRandomParentNode(rootOperator);71 IFunctionTree parent = gardener.GetRandomParentNode(root); 71 72 // parent == null means we should cut out the root node 72 // => return a random sub operatorof the root73 // => return a random sub-tree of the root 73 74 if (parent == null) { 74 // when there are sub operators then replace the old operator with a random suboperator75 if (root Operator.SubOperators.Count > 0) {76 root Operator = rootOperator.SubOperators[random.Next(rootOperator.SubOperators.Count)];75 // when there are sub-trees then replace the old tree with a random sub-tree 76 if (root.SubTrees.Count > 0) { 77 root = root.SubTrees[random.Next(root.SubTrees.Count)]; 77 78 78 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root Operator);79 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root Operator);79 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 80 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 80 81 81 // this is not really necessary (we can leave it in until the operatoris stable)82 if (!gardener.IsValidTree(root Operator)) {82 // this is not really necessary (we can leave it in until the tree is stable) 83 if (!gardener.IsValidTree(root)) { 83 84 throw new InvalidProgramException(); 84 85 } 85 86 86 87 // update the variable 87 scope.GetVariable( "OperatorTree").Value = rootOperator;88 if (!gardener.IsValidTree(root Operator)) {88 scope.GetVariable(scope.TranslateName("FunctionTree")).Value = root; 89 if (!gardener.IsValidTree(root)) { 89 90 throw new InvalidProgramException(); 90 91 } 91 92 93 92 // the tree is already initialized so we don't have to schedule initialization operations 94 93 return null; 95 94 } else { 96 95 // create a new random tree 97 I Operator newOperator;96 IFunctionTree newTree; 98 97 if(random.NextDouble() <= balancedTreesRate) { 99 new Operator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, true);98 newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, true); 100 99 } else { 101 new Operator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, false);100 newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, false); 102 101 } 103 102 104 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(new Operator);105 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(new Operator);103 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newTree); 104 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(newTree); 106 105 107 if (!gardener.IsValidTree(newOperator)) { 106 // update the variable 107 scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTree; 108 109 if (!gardener.IsValidTree(newTree)) { 108 110 throw new InvalidProgramException(); 109 111 } 110 112 111 // update the variable 112 scope.GetVariable("OperatorTree").Value = newOperator; 113 114 if (!gardener.IsValidTree(newOperator)) { 115 throw new InvalidProgramException(); 116 } 117 118 // schedule an operation to initialize the whole operator graph 119 return gardener.CreateInitializationOperation(gardener.GetAllOperators(newOperator), scope); 113 // schedule an operation to initialize the whole tree 114 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope); 120 115 } 121 116 } 122 117 123 int childIndex = random.Next(parent.Sub Operators.Count);124 I Operator child = parent.SubOperators[childIndex];118 int childIndex = random.Next(parent.SubTrees.Count); 119 IFunctionTree child = parent.SubTrees[childIndex]; 125 120 126 // match the suboperators of the child with the allowed suboperators of the parent 127 IOperator[] possibleChilds = gardener.GetAllowedSubOperators(parent, childIndex).SelectMany(allowedOp => child.SubOperators 128 .Where(subOp => ((StringData)subOp.GetVariable(GPOperatorLibrary.TYPE_ID).Value).Data == 129 ((StringData)allowedOp.GetVariable(GPOperatorLibrary.TYPE_ID).Value).Data)).ToArray(); 130 121 // match the sub-trees of the child with the allowed sub-trees of the parent 122 IFunction[] possibleChilds = gardener.GetAllowedSubFunctions(parent.Function, childIndex).SelectMany(allowedFun => child.SubTrees 123 .Where(subTree => allowedFun == subTree.Function)).Select(t=>t.Function).ToArray(); // Actually we should probably use OperatorEqualityComparer here (gkronber 21.04.08) 131 124 132 125 if (possibleChilds.Length > 0) { 133 126 // replace child with a random child of the child 134 // make a clone to simplify removing obsolete operators from the operator-graph135 I Operator selectedChild = (IOperator)possibleChilds[random.Next(possibleChilds.Length)].Clone();136 parent.RemoveSub Operator(childIndex);137 parent. AddSubOperator(selectedChild, childIndex);127 // make a clone to simplify removing obsolete branches from the function-tree 128 IFunction selectedChild = possibleChilds[random.Next(possibleChilds.Length)]; 129 parent.RemoveSubTree(childIndex); 130 parent.InsertSubTree(childIndex, new FunctionTree(selectedChild)); 138 131 139 if (!gardener.IsValidTree(root Operator)) {132 if (!gardener.IsValidTree(root)) { 140 133 throw new InvalidProgramException(); 141 134 } 142 135 143 136 // update the size and height of our tree 144 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root Operator);145 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root Operator);137 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 138 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 146 139 // don't need to schedule initialization operations 147 140 return null; 148 141 } else { 149 142 // determine the level of the parent 150 int parentLevel = gardener.Get NodeLevel(rootOperator, parent);143 int parentLevel = gardener.GetBranchLevel(root, parent); 151 144 152 145 // first remove the old child (first step essential!) 153 parent.RemoveSub Operator(childIndex);146 parent.RemoveSubTree(childIndex); 154 147 // then determine the number of nodes left over after the child has been removed! 155 int remainingNodes = gardener.GetTreeSize(root Operator);148 int remainingNodes = gardener.GetTreeSize(root); 156 149 157 IList<I Operator> allowedOperators = gardener.GetAllowedSubOperators(parent, childIndex);158 I Operator newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxTreeSize - remainingNodes, maxTreeHeight - parentLevel, true);150 IList<IFunction> allowedFunctions = gardener.GetAllowedSubFunctions(parent.Function, childIndex); 151 IFunctionTree newFunctionTree = gardener.CreateRandomTree(allowedFunctions, maxTreeSize - remainingNodes, maxTreeHeight - parentLevel, true); 159 152 160 parent. AddSubOperator(newOperatorTree, childIndex);153 parent.InsertSubTree(childIndex, newFunctionTree); 161 154 162 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root Operator);163 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root Operator);155 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 156 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 164 157 165 if (!gardener.IsValidTree(root Operator)) {158 if (!gardener.IsValidTree(root)) { 166 159 throw new InvalidProgramException(); 167 160 } 168 161 169 // schedule an initialization operation for the new operator170 return gardener.CreateInitializationOperation(gardener.GetAll Operators(newOperatorTree), scope);162 // schedule an initialization operation for the new function-tree 163 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newFunctionTree), scope); 171 164 } 172 165 } -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs
r23 r143 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Random; 28 using HeuristicLab.Functions; 28 29 29 30 namespace HeuristicLab.StructureIdentification { … … 42 43 AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In)); 43 44 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 44 AddVariableInfo(new VariableInfo(" OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In | VariableKind.Out));45 AddVariableInfo(new VariableInfo("FunctionTree", "The tree to mutate", typeof(IFunctionTree), VariableKind.In | VariableKind.Out)); 45 46 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); 46 47 AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In | VariableKind.Out)); … … 49 50 50 51 public override IOperation Apply(IScope scope) { 51 I Operator rootOperator = GetVariableValue<IOperator>("OperatorTree", scope, true);52 IFunctionTree root = GetVariableValue<IFunctionTree>("FunctionTree", scope, true); 52 53 MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true); 53 54 GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true); 54 55 55 TreeGardener gardener = new TreeGardener(random, library); 56 57 IOperator parent = gardener.GetRandomParentNode(rootOperator); 56 IFunctionTree parent = gardener.GetRandomParentNode(root); 58 57 59 58 // parent==null means the whole tree should be deleted. 60 59 // => return a new minimal random tree 61 60 if(parent == null) { 62 I OperatornewTree = gardener.CreateRandomTree(1, 1, true);61 IFunctionTree newTree = gardener.CreateRandomTree(1, 1, true); 63 62 64 63 // check if the tree is ok … … 70 69 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newTree); 71 70 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(newTree); 72 scope.GetVariable( "OperatorTree").Value = newTree;71 scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTree; 73 72 74 73 // schedule an operation to initialize the newly created operator 75 return gardener.CreateInitializationOperation(gardener.GetAll Operators(newTree), scope);74 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope); 76 75 } 77 76 78 int childIndex = random.Next(parent.Sub Operators.Count);77 int childIndex = random.Next(parent.SubTrees.Count); 79 78 80 79 int min; 81 80 int max; 82 gardener.GetMinMaxArity(parent , out min, out max);83 if(parent.Sub Operators.Count > min) {84 parent.RemoveSub Operator(childIndex);85 // actually since the next sub operators are shifted in the place of the removed operator86 // it might be possible that these sub operators are not allowed in the place of the old operator81 gardener.GetMinMaxArity(parent.Function, out min, out max); 82 if(parent.SubTrees.Count > min) { 83 parent.RemoveSubTree(childIndex); 84 // actually since the next sub-trees are shifted in the place of the removed branch 85 // it might be possible that these sub-trees are not allowed in the place of the old branch 87 86 // we ignore this problem for now. 88 // when this starts to become a problem a possible solution is to go through the shifted operators from the place of the shifted87 // when this starts to become a problem a possible solution is to go through the shifted branches from the place of the shifted 89 88 // and find the first one that doesn't fit. At this position we insert a new randomly initialized subtree of matching type (gkronber 25.12.07) 90 89 91 if(!gardener.IsValidTree(root Operator)) {90 if(!gardener.IsValidTree(root)) { 92 91 throw new InvalidOperationException(); 93 92 } 94 93 95 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(rootOperator); 96 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(rootOperator); 97 // root hasn't changed so don't need to update 'OperatorTree' variable 98 94 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 95 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 96 // root hasn't changed so don't need to update 'FunctionTree' variable 99 97 return null; 100 98 } else { 101 99 // replace with a minimal random seedling 102 parent.RemoveSub Operator(childIndex);100 parent.RemoveSubTree(childIndex); 103 101 104 IList<I Operator> allowedOperators = gardener.GetAllowedSubOperators(parent, childIndex);105 I Operator newOperatorTree = gardener.CreateRandomTree(allowedOperators, 1, 1, true);102 IList<IFunction> allowedFunctions = gardener.GetAllowedSubFunctions(parent.Function, childIndex); 103 IFunctionTree newFunctionTree = gardener.CreateRandomTree(allowedFunctions, 1, 1, true); 106 104 107 parent. AddSubOperator(newOperatorTree, childIndex);105 parent.InsertSubTree(childIndex, newFunctionTree); 108 106 109 if(!gardener.IsValidTree(root Operator)) {107 if(!gardener.IsValidTree(root)) { 110 108 throw new InvalidProgramException(); 111 109 } 112 110 113 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(rootOperator); 114 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(rootOperator); 115 // again the root hasn't changed so we don't need to update the 'OperatorTree' variable 116 117 return gardener.CreateInitializationOperation(gardener.GetAllOperators(newOperatorTree), scope); 111 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 112 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 113 // again the root hasn't changed so we don't need to update the 'FunctionTree' variable 114 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newFunctionTree), scope); 118 115 } 119 116 } -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/FullTreeShaker.cs
r88 r143 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Selection; 31 using HeuristicLab.Functions; 31 32 32 33 namespace HeuristicLab.StructureIdentification { … … 38 39 public FullTreeShaker() 39 40 : base() { 41 AddVariableInfo(new VariableInfo("Random", "A random generator (uniform)", typeof(MersenneTwister), VariableKind.In)); 40 42 AddVariableInfo(new VariableInfo("OperatorLibrary", "Operator library that defines operator mutations", typeof(GPOperatorLibrary), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("OperatorTree", "The operator tree that should be mutated", typeof(IOperator), VariableKind.In)); 42 AddVariableInfo(new VariableInfo("Random", "A random generator (uniform)", typeof(MersenneTwister), VariableKind.In)); 43 AddVariableInfo(new VariableInfo("ShakingFactor", "Variable that determines the force of the shakeing operation", typeof(DoubleData), VariableKind.In)); 43 AddVariableInfo(new VariableInfo("ShakingFactor", "Variable that determines the force of the shaking operation", typeof(DoubleData), VariableKind.In)); 44 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be mutated", typeof(IFunctionTree), VariableKind.In | VariableKind.Out)); 44 45 } 45 46 46 47 public override IOperation Apply(IScope scope) { 47 48 GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true); 48 I Operator op = GetVariableValue<IOperator>("OperatorTree", scope, false);49 IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, false); 49 50 MersenneTwister mt = GetVariableValue<MersenneTwister>("Random", scope, true); 50 51 … … 56 57 57 58 TreeGardener gardener = new TreeGardener(mt, library); 58 var parametric Nodes = gardener.GetAllOperators(op).Where(o => o.GetVariable(GPOperatorLibrary.MANIPULATION) != null);59 foreach(I Operator subOperator in parametricNodes) {60 IOperator mutation =(IOperator)sub Operator.GetVariable(GPOperatorLibrary.MANIPULATION).Value;59 var parametricBranches = gardener.GetAllSubTrees(tree).Where(branch => branch.Function.GetVariable(GPOperatorLibrary.MANIPULATION) != null); 60 foreach(IFunctionTree subTree in parametricBranches) { 61 IOperator mutation =(IOperator)subTree.Function.GetVariable(GPOperatorLibrary.MANIPULATION).Value; 61 62 62 63 // store all local variables into a temporary scope 63 64 Scope mutationScope = new Scope(); 64 foreach(IVariableInfo info in subOperator.VariableInfos) { 65 if(info.Local) { 66 mutationScope.AddVariable(subOperator.GetVariable(info.FormalName)); 67 } 65 foreach(IVariable variable in subTree.LocalVariables) { 66 mutationScope.AddVariable(variable); 68 67 } 69 68 -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/OnePointShaker.cs
r88 r143 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Selection; 31 using HeuristicLab.Functions; 31 32 32 33 namespace HeuristicLab.StructureIdentification { … … 39 40 : base() { 40 41 AddVariableInfo(new VariableInfo("OperatorLibrary", "Operator library that defines mutation operations for operators", typeof(GPOperatorLibrary), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("OperatorTree", "The operator tree that should be mutated", typeof(IOperator), VariableKind.In));42 42 AddVariableInfo(new VariableInfo("Random", "A random generator (uniform)", typeof(MersenneTwister), VariableKind.In)); 43 43 AddVariableInfo(new VariableInfo("ShakingFactor", "Factor that determines the force of the shaking operation", typeof(DoubleData), VariableKind.In)); 44 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be mutated", typeof(IFunctionTree), VariableKind.In | VariableKind.Out)); 44 45 } 45 46 46 47 public override IOperation Apply(IScope scope) { 47 48 GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true); 48 I Operator op = GetVariableValue<IOperator>("OperatorTree", scope, false);49 IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, false); 49 50 MersenneTwister mt = GetVariableValue<MersenneTwister>("Random", scope, true); 50 51 TreeGardener gardener = new TreeGardener(mt, library); 51 52 52 53 // get all nodes for which a manipulation is defined 53 var parametricNodes = gardener.GetAllOperators(op).Where(o => o.GetVariable(GPOperatorLibrary.MANIPULATION) != null); 54 IOperator selectedOp = parametricNodes.ElementAt(mt.Next(parametricNodes.Count())); 55 56 IOperator mutation = (IOperator)selectedOp.GetVariable(GPOperatorLibrary.MANIPULATION).Value; 57 54 var parametricBranches = gardener.GetAllSubTrees(tree).Where(branch => branch.Function.GetVariable(GPOperatorLibrary.MANIPULATION) != null); 55 IFunctionTree selectedBranch = parametricBranches.ElementAt(mt.Next(parametricBranches.Count())); 56 IOperator mutation = (IOperator)selectedBranch.Function.GetVariable(GPOperatorLibrary.MANIPULATION).Value; 58 57 CompositeOperation next = new CompositeOperation(); 59 58 60 59 // store all local variables into a temporary scope 61 60 Scope tempScope = new Scope("Temp. manipulation scope"); 62 // add aliases 63 foreach(IVariableInfo variableInfo in VariableInfos) 64 tempScope.AddAlias(variableInfo.FormalName, variableInfo.ActualName); 65 66 foreach(IVariableInfo info in selectedOp.VariableInfos) { 67 if(info.Local) { 68 tempScope.AddVariable(selectedOp.GetVariable(info.FormalName)); 69 } 61 foreach(IVariable variable in selectedBranch.LocalVariables) { 62 tempScope.AddVariable(variable); 70 63 } 71 64 -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
r23 r143 69 69 IOperator newOperatorTree; 70 70 if(random.NextDouble() <= balancedTreesRate) { 71 newOperatorTree = gardener.CreateRandomTree(gardener.All Operators, maxTreeSize, maxTreeHeight, true);71 newOperatorTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, true); 72 72 } else { 73 newOperatorTree = gardener.CreateRandomTree(gardener.All Operators, maxTreeSize, maxTreeHeight, false);73 newOperatorTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight, false); 74 74 } 75 75 … … 84 84 85 85 // return a CompositeOperation that randomly initializes the new operator 86 return gardener.CreateInitializationOperation(gardener.GetAll Operators(newOperatorTree), scope);86 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newOperatorTree), scope); 87 87 } else { 88 88 // determine a random child of the parent to be replaced … … 90 90 91 91 // get the list of allowed suboperators as the new child 92 IList<IOperator> allowedOperators = gardener.GetAllowedSub Operators(parent, childIndex);92 IList<IOperator> allowedOperators = gardener.GetAllowedSubFunctions(parent, childIndex); 93 93 94 94 if(allowedOperators.Count == 0) { … … 100 100 // calculate the maximum size and height of the new sub-tree based on the location where 101 101 // it will be inserted 102 int parentLevel = gardener.Get NodeLevel(rootOperator, parent);102 int parentLevel = gardener.GetBranchLevel(rootOperator, parent); 103 103 104 104 int maxSubTreeHeight = maxTreeHeight - parentLevel; … … 127 127 128 128 // return a CompositeOperation that randomly initializes all nodes of the new subtree 129 return gardener.CreateInitializationOperation(gardener.GetAll Operators(newOperatorTree), scope);129 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newOperatorTree), scope); 130 130 } 131 131 }
Note: See TracChangeset
for help on using the changeset viewer.