Changeset 145 for branches/FunctionsAndStructIdRefactoring
- Timestamp:
- 04/21/08 20:57:45 (17 years ago)
- Location:
- branches/FunctionsAndStructIdRefactoring
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs
r2 r145 91 91 private static bool InSet(IOperator op, ICollection<IOperator> set) { 92 92 foreach(IOperator element in set) { 93 if(((StringData)element.GetVariable("TypeId").Value).Data == 93 if(element==op || 94 ((StringData)element.GetVariable("TypeId").Value).Data == 94 95 ((StringData)op.GetVariable("TypeId").Value).Data) { 95 96 return true; -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs
r142 r145 58 58 59 59 public override IList<IOperator> SubOperators { 60 get { throw new NotSupportedException(); }60 get { return new List<IOperator>(); } 61 61 } 62 62 -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionTree.cs
r142 r145 77 77 public override XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 78 78 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 79 node.AppendChild(PersistenceManager.Persist("Function", function, document, persistedObjects)); 79 80 XmlNode subTreesNode = document.CreateNode(XmlNodeType.Element, "SubTrees", null); 80 81 for(int i = 0; i < subTrees.Count; i++) … … 90 91 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 91 92 base.Populate(node, restoredObjects); 93 function = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects); 92 94 XmlNode subTreesNode = node.SelectSingleNode("SubTrees"); 93 95 for(int i = 0; i < subTreesNode.ChildNodes.Count; i++) … … 106 108 clone.AddVariable((IVariable)variable.Clone(clonedObjects)); 107 109 } 110 clone.function = function; 108 111 return clone; 109 112 } -
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.