Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/31/09 12:31:32 (15 years ago)
Author:
gkronber
Message:

Worked on persistence of function trees. #713

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs

    r2216 r2218  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.GP.Interfaces;
     27using System.Xml;
    2728
    2829namespace HeuristicLab.GP {
     
    4344      this.subTrees = new List<IFunctionTree>(original.SubTrees.Count);
    4445      foreach (IFunctionTree originalSubTree in original.SubTrees) {
    45         this.SubTrees.Add(originalSubTree.Clone());
     46        this.SubTrees.Add((IFunctionTree)originalSubTree.Clone());
    4647      }
    4748    }
     
    9394    }
    9495
    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() {
    96105      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      }
    97133    }
    98134
Note: See TracChangeset for help on using the changeset viewer.