Changeset 224
- Timestamp:
- 05/07/08 01:13:58 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ExperimentalFunctionsBaking/BakedFunctionTree.cs
r223 r224 27 27 using HeuristicLab.DataAnalysis; 28 28 using HeuristicLab.Data; 29 using System.Xml; 29 30 30 31 namespace HeuristicLab.Functions { … … 33 34 private List<double> data; 34 35 35 internalBakedFunctionTree() {36 public BakedFunctionTree() { 36 37 code = new List<int>(); 37 38 data = new List<double>(); … … 226 227 227 228 228 public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 229 throw new NotImplementedException(); 230 } 231 232 public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 233 throw new NotImplementedException(); 229 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 230 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 231 node.AppendChild(PersistenceManager.Persist("Function", Function, document, persistedObjects)); 232 XmlNode subTreesNode = document.CreateNode(XmlNodeType.Element, "SubTrees", null); 233 for(int i = 0; i < SubTrees.Count; i++) 234 subTreesNode.AppendChild(PersistenceManager.Persist(SubTrees[i], document, persistedObjects)); 235 node.AppendChild(subTreesNode); 236 XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null); 237 foreach(IVariable variable in LocalVariables) 238 variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects)); 239 node.AppendChild(variablesNode); 240 return node; 241 } 242 243 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 244 base.Populate(node, restoredObjects); 245 IFunction function = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects); 246 code.Add(0); 247 code.Add(BakedTreeEvaluator.MapFunction(function)); 248 code.Add(0); 249 treesExpanded = true; 250 subTrees = new List<IFunctionTree>(); 251 variables = new List<IVariable>(); 252 variablesExpanded = true; 253 XmlNode subTreesNode = node.SelectSingleNode("SubTrees"); 254 for(int i = 0; i < subTreesNode.ChildNodes.Count; i++) 255 subTrees.Add((IFunctionTree)PersistenceManager.Restore(subTreesNode.ChildNodes[i], restoredObjects)); 256 XmlNode variablesNode = node.SelectSingleNode("Variables"); 257 foreach(XmlNode variableNode in variablesNode.ChildNodes) 258 variables.Add((IVariable)PersistenceManager.Restore(variableNode, restoredObjects)); 234 259 } 235 260 236 261 public override object Clone(IDictionary<Guid, object> clonedObjects) { 237 262 BakedFunctionTree clone = new BakedFunctionTree(); 238 if(treesExpanded || variablesExpanded) throw new InvalidOperationException(); // sanity check 263 // in case the user (de)serialized the tree between evaluation and selection we have to flatten the tree again. 264 if(treesExpanded) FlattenTrees(); 265 if(variablesExpanded) FlattenVariables(); 239 266 clone.code.AddRange(code); 240 267 clone.data.AddRange(data);
Note: See TracChangeset
for help on using the changeset viewer.