Changeset 2218 for branches/GP-Refactoring-713/sources/HeuristicLab.GP
- Timestamp:
- 07/31/09 12:31:32 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs
r2216 r2218 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.GP.Interfaces; 27 using System.Xml; 27 28 28 29 namespace HeuristicLab.GP { … … 43 44 this.subTrees = new List<IFunctionTree>(original.SubTrees.Count); 44 45 foreach (IFunctionTree originalSubTree in original.SubTrees) { 45 this.SubTrees.Add( originalSubTree.Clone());46 this.SubTrees.Add((IFunctionTree)originalSubTree.Clone()); 46 47 } 47 48 } … … 93 94 } 94 95 95 public virtual IFunctionTree Clone() { 96 #endregion 97 98 #region IStorable Members 99 100 public Guid Guid { 101 get { throw new NotSupportedException(); } 102 } 103 104 public virtual object Clone() { 96 105 return new FunctionTreeBase(this); 106 } 107 108 public object Clone(IDictionary<Guid, object> clonedObjects) { 109 throw new NotImplementedException(); 110 } 111 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; 123 } 124 125 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 } 97 133 } 98 134 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/GeneticProgrammingModel.cs
r2216 r2218 53 53 public override object Clone(IDictionary<Guid, object> clonedObjects) { 54 54 GeneticProgrammingModel clone = (GeneticProgrammingModel)base.Clone(clonedObjects); 55 clone.FunctionTree = FunctionTree.Clone();55 clone.FunctionTree = (IFunctionTree)FunctionTree.Clone(); 56 56 return clone; 57 57 } … … 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.Value = GeneralTreeSerializer.Export(FunctionTree); 61 node.AppendChild(PersistenceManager.Persist("Function", FunctionTree.Function, document, persistedObjects)); 62 node.AppendChild(FunctionTree.GetXmlNode("FunctionTree", document, persistedObjects)); 62 63 return node; 63 64 } … … 65 66 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 66 67 base.Populate(node, restoredObjects); 67 FunctionTree = GeneralTreeSerializer.Import(node.Value); 68 IFunction rootFunction = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects); 69 IFunctionTree rootNode = rootFunction.GetTreeNode(); 70 rootNode.Populate(node.SelectSingleNode("FunctionTree"), restoredObjects); 68 71 } 69 72 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj
r2216 r2218 89 89 <Compile Include="BaseClasses\Terminal.cs" /> 90 90 <Compile Include="BaseClasses\UnaryFunction.cs" /> 91 <Compile Include="FunctionTreeSerializer.cs" />92 91 <Compile Include="FunctionLibrary.cs" /> 93 92 <Compile Include="FunctionLibraryEditor.cs">
Note: See TracChangeset
for help on using the changeset viewer.