Changeset 2218 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
- Timestamp:
- 07/31/09 12:31:32 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note: See TracChangeset
for help on using the changeset viewer.