- Timestamp:
- 04/21/08 20:57:45 (17 years ago)
- Location:
- branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/RandomTreeCreator.cs
r143 r145 41 41 AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In)); 42 42 AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In)); 43 AddVariableInfo(new VariableInfo(" OperatorTree", "The tree to mutate", typeof(IFunctionTree), VariableKind.In));44 AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind. In));45 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)); 46 46 } 47 47 … … 67 67 int actualTreeHeight = gardener.GetTreeHeight(root); 68 68 69 scope.AddVariable(new HeuristicLab.Core.Variable( "OperatorTree", root));70 scope.AddVariable(new HeuristicLab.Core.Variable( "TreeSize", new IntData(actualTreeSize)));71 scope.AddVariable(new HeuristicLab.Core.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))); 72 72 73 73 if(!gardener.IsValidTree(root)) { throw new InvalidProgramException(); } -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/TreeGardener.cs
r143 r145 325 325 326 326 internal bool IsValidTree(IFunctionTree tree) { 327 if (!tree.Function.IsValid()) 328 return false; 329 foreach (IFunctionTree subTree in tree.SubTrees) { 330 if (!subTree.Function.IsValid()) 331 return false; 332 } 333 327 foreach(IConstraint constraint in tree.Function.Constraints) { 328 if(constraint is NumberOfSubOperatorsConstraint) { 329 int max = ((NumberOfSubOperatorsConstraint)constraint).MaxOperators.Data; 330 int min = ((NumberOfSubOperatorsConstraint)constraint).MinOperators.Data; 331 if(tree.SubTrees.Count < min || tree.SubTrees.Count > max) return false; 332 } 333 } 334 foreach(IFunctionTree subTree in tree.SubTrees) { 335 if(!IsValidTree(subTree)) return false; 336 } 334 337 return true; 335 338 }
Note: See TracChangeset
for help on using the changeset viewer.