- Timestamp:
- 04/20/10 15:49:22 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3376 r3442 56 56 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 57 57 var rootNode = grammar.StartSymbol.CreateTreeNode(); 58 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random); 58 59 rootNode.Grammar = grammar; 59 60 tree.Root = PTC2(random, rootNode, maxTreeSize, maxTreeHeight, maxFunctionDefinitions, maxFunctionArguments); … … 111 112 var dummy = new SymbolicExpressionTreeNode(); 112 113 root.AddSubTree(dummy); 113 // dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();114 114 extensionPoints.Add(new TreeExtensionPoint { Parent = root, ChildIndex = i, ExtensionPointDepth = 2 }); 115 115 } … … 132 132 Symbol selectedSymbol = SelectRandomSymbol(random, allowedSymbols); 133 133 SymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode(); 134 if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random); 134 135 parent.RemoveSubTree(argumentIndex); 135 136 parent.InsertSubTree(argumentIndex, newTree); … … 145 146 var dummy = new SymbolicExpressionTreeNode(); 146 147 newTree.AddSubTree(dummy); 147 //if (IsTopLevelBranch(root, dummy))148 // dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();149 148 extensionPoints.Add(new TreeExtensionPoint { Parent = newTree, ChildIndex = i, ExtensionPointDepth = extensionDepth + 1 }); 150 149 } … … 172 171 var selectedSymbol = SelectRandomSymbol(random, possibleSymbols); 173 172 var tree = selectedSymbol.CreateTreeNode(); 173 if (tree.HasLocalParameters) tree.ResetLocalParameters(random); 174 174 parent.RemoveSubTree(argumentIndex); 175 175 parent.InsertSubTree(argumentIndex, tree); … … 179 179 var dummy = new SymbolicExpressionTreeNode(); 180 180 tree.AddSubTree(dummy); 181 // dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();182 181 // replace the just inserted dummy by recursive application 183 182 ReplaceWithMinimalTree(random, root, tree, i, maxFunctionDefinitions, maxFunctionArguments); … … 229 228 230 229 private static bool IsTopLevelBranch(SymbolicExpressionTreeNode root, SymbolicExpressionTreeNode branch) { 231 //return root.SubTrees.IndexOf(branch) > -1;232 230 return branch is SymbolicExpressionTreeTopLevelNode; 233 231 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs
r3431 r3442 65 65 public SymbolicExpressionTree(SymbolicExpressionTreeNode root) 66 66 : base() { 67 this.Root = root; 67 68 } 68 69 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCompiler.cs
r3409 r3442 46 46 entryPoint.Clear(); 47 47 // compile main body 48 code.AddRange(Compile(tree.Root.SubTrees[0] ));48 code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0])); 49 49 // compile branches 50 50 var functionBranches = from node in tree.IterateNodesPrefix() … … 53 53 foreach (DefunTreeNode branch in functionBranches) { 54 54 entryPoint[branch.FunctionName] = (short)code.Count; 55 code.AddRange(Compile(branch ));55 code.AddRange(Compile(branch.SubTrees[0])); 56 56 } 57 // address of all functions is fixed now 58 // iterate through code again and fill in the jump locations 59 for (int i = 0; i < code.Count; i++) { 60 Instruction instr = code[i]; 61 if (instr.symbol == CodeSymbol.Call) { 62 var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode; 63 instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName]; 64 instr.dynamicNode = null; 65 code[i] = instr; 66 } 67 } 68 57 69 return code.ToArray(); 58 70 } … … 65 77 if (codeSymbol.ContainsKey(node.Symbol.GetType())) { 66 78 instr.symbol = codeSymbol[node.Symbol.GetType()]; 67 if (instr.symbol == CodeSymbol.Call) { 68 var invokeNode = (InvokeFunctionTreeNode)node; 69 instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName]; 70 } else if (instr.symbol == CodeSymbol.Arg) { 79 if (instr.symbol == CodeSymbol.Arg) { 71 80 var argNode = (ArgumentTreeNode)node; 72 81 instr.iArg0 = (short)argNode.Symbol.ArgumentIndex; 82 } else if (instr.symbol == CodeSymbol.Call) { 83 instr.dynamicNode = node; // save node for fixup of jump addresses in second iteration 73 84 } 74 85 } else { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs
r3376 r3442 65 65 SymbolicExpressionTreeParameter.ActualValue = Create(Random, SymbolicExpressionGrammar, 66 66 MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments); 67 68 foreach (var node in SymbolicExpressionTreeParameter.ActualValue.IterateNodesPostfix()) {69 node.ResetLocalParameters(RandomParameter.ActualValue);70 }71 67 return null; 72 68 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r3376 r3442 145 145 #endregion 146 146 147 147 public override string ToString() { 148 return Symbol.Name; 149 } 148 150 149 151 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs
r3376 r3442 53 53 return new DefunTreeNode(this); 54 54 } 55 56 public override string ToString() { 57 return FunctionName; 58 } 55 59 } 56 60 }
Note: See TracChangeset
for help on using the changeset viewer.