Changeset 2218
- Timestamp:
- 07/31/09 12:31:32 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/VariableFunctionTree.cs
r2216 r2218 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.GP.Interfaces; 26 using System.Xml; 26 27 27 28 namespace HeuristicLab.GP.Boolean { … … 58 59 } 59 60 60 public override IFunctionTreeClone() {61 public override object Clone() { 61 62 return new VariableFunctionTree(this); 63 } 64 65 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 66 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 67 XmlAttribute varAttr = document.CreateAttribute("Variable"); 68 varAttr.Value = VariableName; 69 node.Attributes.Append(varAttr); 70 return node; 71 } 72 73 public override void Populate(XmlNode node, IDictionary<System.Guid, IStorable> restoredObjects) { 74 base.Populate(node, restoredObjects); 75 VariableName = node.Attributes["Variable"].Value; 62 76 } 63 77 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/HeuristicLab.GP.Interfaces-3.3.csproj
r2216 r2218 83 83 <SubType>Code</SubType> 84 84 </Compile> 85 <Compile Include="IFunctionTreeSerializer.cs" /> 85 <Compile Include="IFunctionTreeSerializer.cs"> 86 <SubType>Code</SubType> 87 </Compile> 86 88 <Compile Include="IGeneticProgrammingModel.cs" /> 87 89 <Compile Include="HeuristicLabGPInterfacesPlugin.cs" /> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/IFunctionTree.cs
r2210 r2218 26 26 27 27 namespace HeuristicLab.GP.Interfaces { 28 public interface IFunctionTree {28 public interface IFunctionTree : IStorable { 29 29 bool HasLocalParameters { get; } 30 30 IList<IFunctionTree> SubTrees { get; } … … 37 37 void InsertSubTree(int index, IFunctionTree tree); 38 38 void RemoveSubTree(int index); 39 IFunctionTree Clone();40 39 } 41 40 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/IFunctionTreeSerializer.cs
r2216 r2218 30 30 string Export(IFunctionTree tree); 31 31 bool TryExport(IFunctionTree tree, out string exported); 32 IFunctionTree Import(string tree);33 bool TryImport(string tree, out IFunctionTree importedTree);32 //IFunctionTree Import(string tree); 33 //bool TryImport(string tree, out IFunctionTree importedTree); 34 34 } 35 35 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Operators/3.3/HeuristicLab.GP.Operators-3.3.csproj
r2212 r2218 10 10 <AppDesignerFolder>Properties</AppDesignerFolder> 11 11 <RootNamespace>HeuristicLab.GP.Operators</RootNamespace> 12 <AssemblyName>HeuristicLab.GP.Operators </AssemblyName>12 <AssemblyName>HeuristicLab.GP.Operators-3.3</AssemblyName> 13 13 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
r2216 r2218 54 54 } 55 55 56 public IFunctionTree Import(string tree) { 57 Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t')); 58 return ParseTree(tokens); 59 } 60 61 private IFunctionTree ParseTree(Queue<string> tokens) { 62 Expect("(", tokens); 63 string funSymb = tokens.Peek(); 64 double constValue; 65 if (double.TryParse(funSymb, out constValue)) { 66 throw new UnknownFunctionException(funSymb); 67 } 68 switch (funSymb) { 69 case "variable": return ParseVariable(tokens); 70 case "differential": return ParseDifferential(tokens); 71 default: 72 IFunctionTree fNode = ParseFunction(tokens); 73 Expect(")", tokens); 74 return fNode; 75 } 76 77 } 78 79 private IFunctionTree ParseFunction(Queue<string> tokens) { 80 throw new UnknownFunctionException(tokens.Dequeue()); 81 } 82 83 private IFunctionTree ParseDifferential(Queue<string> tokens) { 84 throw new UnknownFunctionException(tokens.Dequeue()); 85 } 86 87 private IFunctionTree ParseVariable(Queue<string> tokens) { 88 throw new UnknownFunctionException(tokens.Dequeue()); 89 } 90 91 private void Expect(string p, Queue<string> tokens) { 92 throw new NotImplementedException(); 93 } 94 95 public bool TryImport(string tree, out IFunctionTree importedTree) { 96 try { 97 importedTree = Import(tree); 98 return true; 99 } 100 catch (UnknownFunctionException) { 101 importedTree = null; 102 return false; 103 } 104 } 56 //public IFunctionTree Import(string tree) { 57 // Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t')); 58 // return ParseTree(tokens); 59 //} 60 61 //private IFunctionTree ParseTree(Queue<string> tokens) { 62 // Expect("(", tokens); 63 // string funSymb = tokens.Peek(); 64 // double constValue; 65 // if (double.TryParse(funSymb, out constValue)) { 66 // throw new UnknownFunctionException(funSymb); 67 // } 68 // switch (funSymb) { 69 // case "variable": return ParseVariable(tokens); 70 // case "differential": return ParseDifferential(tokens); 71 // default: 72 // IFunctionTree fNode = ParseFunction(tokens); 73 // Expect(")", tokens); 74 // return fNode; 75 // } 76 77 //} 78 79 //private IFunctionTree ParseFunction(Queue<string> tokens) { 80 // string symb = tokens.Dequeue(); 81 // IFunctionTree funTree; 82 // switch (symb) { 83 // case "+": funTree = new Addition().GetTreeNode(); break; 84 // case "-": funTree = new Subtraction().GetTreeNode(); break; 85 // case "*": funTree = new Multiplication().GetTreeNode(); break; 86 // } 87 88 // while (tokens.Peek() == "(") { 89 // funTree.AddSubTree(ParseTree(tokens)); 90 // } 91 // return funTree; 92 //} 93 94 //private IFunctionTree ParseDifferential(Queue<string> tokens) { 95 // string symb = tokens.Dequeue(); 96 // double weight = double.Parse(tokens.Dequeue()); 97 // string name = tokens.Dequeue(); 98 // int sampleOffset = int.Parse(tokens.Dequeue()); 99 // VariableFunctionTree varFunTree = new Differential().GetTreeNode(); 100 // varFunTree.Weight = weight; 101 // varFunTree.SampleOffset = sampleOffset; 102 // varFunTree.VariableName = name; 103 // return varFunTree; 104 //} 105 106 //private IFunctionTree ParseVariable(Queue<string> tokens) { 107 // string symb = tokens.Dequeue(); 108 // double weight = double.Parse(tokens.Dequeue()); 109 // string name = tokens.Dequeue(); 110 // int sampleOffset = int.Parse(tokens.Dequeue()); 111 // VariableFunctionTree varFunTree = new Variable().GetTreeNode(); 112 // varFunTree.Weight = weight; 113 // varFunTree.SampleOffset = sampleOffset; 114 // varFunTree.VariableName = name; 115 // return varFunTree; 116 //} 117 118 //private void Expect(string p, Queue<string> tokens) { 119 // var next = tokens.Dequeue(); 120 // if (p != next) throw new FormatException("Expected symbol: " + p + ", found symbol: " + next); 121 //} 122 123 //public bool TryImport(string tree, out IFunctionTree importedTree) { 124 // try { 125 // importedTree = Import(tree); 126 // return true; 127 // } 128 // catch (UnknownFunctionException) { 129 // importedTree = null; 130 // return false; 131 // } 132 //} 105 133 106 134 private void BuildExportString(IFunctionTree tree) { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/ConstantFunctionTree.cs
r2216 r2218 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.GP.Interfaces; 26 using System.Xml; 26 27 27 28 namespace HeuristicLab.GP.StructureIdentification { … … 56 57 } 57 58 58 public override IFunctionTreeClone() {59 public override object Clone() { 59 60 return new ConstantFunctionTree(this); 61 } 62 63 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 64 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 65 XmlAttribute valueAttr = document.CreateAttribute("Value"); 66 valueAttr.Value = XmlConvert.ToString(Value); 67 node.Attributes.Append(valueAttr); 68 return node; 69 } 70 71 public override void Populate(XmlNode node, IDictionary<System.Guid, IStorable> restoredObjects) { 72 base.Populate(node, restoredObjects); 73 Value = XmlConvert.ToDouble(node.Attributes["Value"].Value); 60 74 } 61 75 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Differential.cs
r2212 r2218 21 21 22 22 23 using HeuristicLab.GP.Interfaces; 23 24 namespace HeuristicLab.GP.StructureIdentification { 24 25 public sealed class Differential : Variable { … … 31 32 32 33 public Differential() : base() { } 34 35 public override IFunctionTree GetTreeNode() { 36 return new VariableFunctionTree(this); 37 } 33 38 } 34 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Variable.cs
r2212 r2218 40 40 } 41 41 } 42 42 43 43 44 public override IFunctionTree GetTreeNode() { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/VariableFunctionTree.cs
r2216 r2218 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.GP.Interfaces; 26 using System.Xml; 26 27 27 28 namespace HeuristicLab.GP.StructureIdentification { … … 66 67 } 67 68 68 public override IFunctionTreeClone() {69 public override object Clone() { 69 70 return new VariableFunctionTree(this); 71 } 72 73 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) { 74 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 75 XmlAttribute weightAttr = document.CreateAttribute("Weight"); 76 weightAttr.Value = XmlConvert.ToString(Weight); 77 XmlAttribute variableAttr = document.CreateAttribute("Variable"); 78 variableAttr.Value = VariableName; 79 XmlAttribute sampleOffsetAttr = document.CreateAttribute("SampleOffset"); 80 sampleOffsetAttr.Value = XmlConvert.ToString(SampleOffset); 81 node.Attributes.Append(weightAttr); 82 node.Attributes.Append(sampleOffsetAttr); 83 node.Attributes.Append(variableAttr); 84 return node; 85 } 86 87 public override void Populate(XmlNode node, IDictionary<System.Guid, IStorable> restoredObjects) { 88 base.Populate(node, restoredObjects); 89 Weight = XmlConvert.ToDouble(node.Attributes["Weight"].Value); 90 SampleOffset = XmlConvert.ToInt32(node.Attributes["SampleOffset"].Value); 91 VariableName = node.Attributes["Variable"].Value; 70 92 } 71 93 -
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.