Changeset 2219 for branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/GeneticProgrammingModel.cs
- Timestamp:
- 08/01/09 13:36:13 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.