Changeset 2219
- Timestamp:
- 08/01/09 13:36:13 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/VariableFunctionTree.cs
r2218 r2219 64 64 65 65 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 66 XmlNode node = base.GetXmlNode(name, document, persistedObjects);66 XmlNode node = document.CreateElement(name); 67 67 XmlAttribute varAttr = document.CreateAttribute("Variable"); 68 68 varAttr.Value = VariableName; -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/ConstantFunctionTree.cs
r2218 r2219 62 62 63 63 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 64 XmlNode node = base.GetXmlNode(name, document, persistedObjects);64 XmlNode node = document.CreateElement(name); 65 65 XmlAttribute valueAttr = document.CreateAttribute("Value"); 66 66 valueAttr.Value = XmlConvert.ToString(Value); -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/VariableFunctionTree.cs
r2218 r2219 72 72 73 73 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 74 XmlNode node = base.GetXmlNode(name, document, persistedObjects);74 XmlNode node = document.CreateElement(name); 75 75 XmlAttribute weightAttr = document.CreateAttribute("Weight"); 76 76 weightAttr.Value = XmlConvert.ToString(Weight); -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs
r2216 r2219 156 156 157 157 public override object Clone(IDictionary<Guid, object> clonedObjects) { 158 throw new NotSupportedException(); 158 FunctionBase clone = (FunctionBase)base.Clone(clonedObjects); 159 clone.initializer = (IOperator)Auxiliary.Clone(initializer, clonedObjects); 160 clone.manipulator = (IOperator)Auxiliary.Clone(manipulator, clonedObjects); 161 clone.maxArity = maxArity; 162 clone.minArity = minArity; 163 clone.minTreeHeight = minTreeHeight; 164 clone.minTreeSize = minTreeSize; 165 clone.tickets = tickets; 166 for (int i = 0; i < MaxSubTrees; i++) { 167 var allowedSubFunctionsForSlot = new List<IFunction>(); 168 foreach (IFunction f in GetAllowedSubFunctions(i)) { 169 allowedSubFunctionsForSlot.Add((IFunction)Auxiliary.Clone(f, clonedObjects)); 170 } 171 clone.allowedSubFunctions.Add(allowedSubFunctionsForSlot); 172 } 173 return clone; 159 174 } 160 175 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs
r2218 r2219 111 111 112 112 public virtual XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 113 XmlNode node = document.CreateElement(name); 114 //XmlAttribute typeAttr = document.CreateAttribute("Type"); 115 //typeAttr.Value = PersistenceManager.BuildTypeString(GetType()); 116 //node.Attributes.Append(typeAttr); 117 foreach (IFunctionTree subTree in SubTrees) { 118 XmlNode funNode = PersistenceManager.Persist(Function, document, persistedObjects); 119 node.AppendChild(funNode); 120 funNode.AppendChild(subTree.GetXmlNode("Tree", document, persistedObjects)); 121 } 122 return node; 113 return null; 123 114 } 124 115 125 116 public virtual void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 126 for (int i = 0; i < node.ChildNodes.Count; i++) {127 XmlNode childNode = node.ChildNodes[i];128 IFunction function = (IFunction)PersistenceManager.Restore(childNode, restoredObjects);129 IFunctionTree tree = function.GetTreeNode();130 tree.Populate(childNode.SelectSingleNode("Tree"), restoredObjects);131 AddSubTree(tree);132 }133 117 } 134 118 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/GeneticProgrammingModel.cs
r2218 r2219 59 59 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 60 60 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 61 node.AppendChild(PersistenceManager.Persist("Function", FunctionTree.Function, document, persistedObjects)); 62 node.AppendChild(FunctionTree.GetXmlNode("FunctionTree", document, persistedObjects)); 61 PersistTree(node, document, persistedObjects, FunctionTree); 63 62 return node; 63 } 64 65 private void PersistTree(XmlNode node, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects, IFunctionTree tree) { 66 XmlNode fNode = PersistenceManager.Persist(tree.Function, document, persistedObjects); 67 XmlAttribute subTreesAttr = document.CreateAttribute("Args"); 68 subTreesAttr.Value = XmlConvert.ToString(tree.SubTrees.Count); 69 fNode.Attributes.Append(subTreesAttr); 70 node.AppendChild(fNode); 71 XmlNode treeNode = tree.GetXmlNode("Data", document, persistedObjects); 72 if (treeNode != null) fNode.AppendChild(treeNode); 73 foreach (IFunctionTree subTree in tree.SubTrees) { 74 PersistTree(node, document, persistedObjects, subTree); 75 } 64 76 } 65 77 66 78 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 67 79 base.Populate(node, restoredObjects); 68 IFunction rootFunction = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects); 69 IFunctionTree rootNode = rootFunction.GetTreeNode(); 70 rootNode.Populate(node.SelectSingleNode("FunctionTree"), restoredObjects); 80 int nodeIndex = 0; 81 FunctionTree = RestoreTree(node, ref nodeIndex, restoredObjects); 82 } 83 84 private IFunctionTree RestoreTree(XmlNode node, ref int nodeIndex, IDictionary<Guid, IStorable> restoredObjects) { 85 XmlNode fNode = node.ChildNodes[nodeIndex]; 86 int subTrees = XmlConvert.ToInt32(fNode.Attributes["Args"].Value); 87 IFunction f = (IFunction)PersistenceManager.Restore(fNode, restoredObjects); 88 IFunctionTree tree = f.GetTreeNode(); 89 if(fNode.ChildNodes.Count>0) tree.Populate(fNode.ChildNodes[0], restoredObjects); 90 nodeIndex++; 91 for (int i = 0; i < subTrees; i++) { 92 tree.AddSubTree(RestoreTree(node, ref nodeIndex, restoredObjects)); 93 } 94 return tree; 71 95 } 72 96
Note: See TracChangeset
for help on using the changeset viewer.