- Timestamp:
- 04/22/08 18:05:14 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/RandomTreeCreator.cs
r23 r155 26 26 using System; 27 27 using HeuristicLab.Random; 28 using HeuristicLab.Functions; 28 29 29 30 namespace HeuristicLab.StructureIdentification { … … 40 41 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 41 42 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 42 AddVariableInfo(new VariableInfo(" OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));43 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind. In));44 AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind. In));43 AddVariableInfo(new VariableInfo("FunctionTree", "The created tree", typeof(IFunctionTree), VariableKind.New | VariableKind.Out)); 44 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.New | VariableKind.Out)); 45 AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.New | VariableKind.Out)); 45 46 } 46 47 … … 56 57 int treeHeight = random.Next(1, maxTreeHeight + 1); 57 58 int treeSize = random.Next(1, maxTreeSize + 1); 58 I Operator rootOperator;59 IFunctionTree root; 59 60 if(random.NextDouble() <= balancedTreesRate) { 60 root Operator= gardener.CreateRandomTree(treeSize, treeHeight, true);61 root = gardener.CreateRandomTree(treeSize, treeHeight, true); 61 62 } else { 62 root Operator= gardener.CreateRandomTree(treeSize, treeHeight, false);63 root = gardener.CreateRandomTree(treeSize, treeHeight, false); 63 64 } 64 65 65 int actualTreeSize = gardener.GetTreeSize(root Operator);66 int actualTreeHeight = gardener.GetTreeHeight(root Operator);66 int actualTreeSize = gardener.GetTreeSize(root); 67 int actualTreeHeight = gardener.GetTreeHeight(root); 67 68 68 scope.AddVariable(new Variable("OperatorTree", rootOperator));69 scope.AddVariable(new Variable("TreeSize", new IntData(actualTreeSize)));70 scope.AddVariable(new Variable("TreeHeight", new IntData(actualTreeHeight)));69 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), root)); 70 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeSize"), new IntData(actualTreeSize))); 71 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(actualTreeHeight))); 71 72 72 if(!gardener.IsValidTree(root Operator)) { throw new InvalidProgramException(); }73 if(!gardener.IsValidTree(root)) { throw new InvalidProgramException(); } 73 74 74 75 if(actualTreeSize > maxTreeSize || … … 77 78 } 78 79 79 return gardener.CreateInitializationOperation(gardener.GetAll Operators(rootOperator), scope);80 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(root), scope); 80 81 } 81 82 }
Note: See TracChangeset
for help on using the changeset viewer.