Changeset 525 for trunk/sources/HeuristicLab.StructureIdentification
- Timestamp:
- 08/20/08 10:48:40 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs ¶
r452 r525 166 166 int d = (int)nextExtension[2]; 167 167 parent.RemoveSubTree(a); 168 parent.InsertSubTree(a, 168 parent.InsertSubTree(a, 169 169 CreateRandomTree(GetAllowedSubFunctions(parent.Function, a), 1, 1)); // append a tree with minimal possible height 170 170 } … … 282 282 283 283 internal bool IsValidTree(IFunctionTree tree) { 284 SubOperatorsConstraintAnalyser analyzer = new SubOperatorsConstraintAnalyser();285 analyzer.AllPossibleOperators = AllFunctions.Cast<IOperator>().ToArray<IOperator>();286 284 for(int i = 0; i < tree.SubTrees.Count; i++) { 287 if(!analyzer.GetAllowedOperators(tree.Function, i).Contains(tree.SubTrees[i].Function)) return false; 288 } 289 290 foreach(IConstraint constraint in tree.Function.Constraints) { 291 if(constraint is NumberOfSubOperatorsConstraint) { 292 int max = ((NumberOfSubOperatorsConstraint)constraint).MaxOperators.Data; 293 int min = ((NumberOfSubOperatorsConstraint)constraint).MinOperators.Data; 294 if(tree.SubTrees.Count < min || tree.SubTrees.Count > max) 295 return false; 296 } 297 } 285 if(!tree.Function.AllowedSubFunctions(i).Contains(tree.SubTrees[i].Function)) return false; 286 } 287 288 if(tree.SubTrees.Count < tree.Function.MinArity || tree.SubTrees.Count > tree.Function.MaxArity) 289 return false; 298 290 foreach(IFunctionTree subTree in tree.SubTrees) { 299 291 if(!IsValidTree(subTree)) return false; … … 335 327 int nSlots = Math.Max(minArity, children.Count); 336 328 337 SubOperatorsConstraintAnalyser analyzer = new SubOperatorsConstraintAnalyser();338 analyzer.AllPossibleOperators = children.Cast<IOperator>().ToArray<IOperator>();339 340 329 List<HashSet<IFunction>> slotSets = new List<HashSet<IFunction>>(); 341 330 … … 344 333 // we only count those slots that can hold at least one of the children that we should combine 345 334 for(int slot = 0; slot < nSlots; slot++) { 346 HashSet<IFunction> functionSet = new HashSet<IFunction>( analyzer.GetAllowedOperators(f, slot).Cast<IFunction>());335 HashSet<IFunction> functionSet = new HashSet<IFunction>(f.AllowedSubFunctions(slot)); 347 336 if(functionSet.Count() > 0) { 348 337 slotSets.Add(functionSet); … … 400 389 return allFunctions; 401 390 } else { 402 SubOperatorsConstraintAnalyser analyzer = new SubOperatorsConstraintAnalyser(); 403 analyzer.AllPossibleOperators = AllFunctions.Cast<IOperator>().ToArray<IOperator>(); 404 List<IFunction> result = new List<IFunction>(); 405 foreach(IFunction function in analyzer.GetAllowedOperators(f, index)) { 406 result.Add(function); 407 } 408 return result; 391 return f.AllowedSubFunctions(index); 409 392 } 410 393 } 411 394 internal void GetMinMaxArity(IFunction f, out int minArity, out int maxArity) { 412 foreach(IConstraint constraint in f.Constraints) { 413 NumberOfSubOperatorsConstraint theConstraint = constraint as NumberOfSubOperatorsConstraint; 414 if(theConstraint != null) { 415 minArity = theConstraint.MinOperators.Data; 416 maxArity = theConstraint.MaxOperators.Data; 417 return; 418 } 419 } 420 // the default arity is 2 421 minArity = 2; 422 maxArity = 2; 395 minArity = f.MinArity; 396 maxArity = f.MaxArity; 423 397 } 424 398 #endregion
Note: See TracChangeset
for help on using the changeset viewer.