Changeset 18146 for branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
- Timestamp:
- 12/16/21 14:23:48 (3 years ago)
- Location:
- branches/3136_Structural_GP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
r17180 r18146 85 85 }; 86 86 87 Constant constant = new Constant();87 Number number = new Number(); 88 88 Variable variable = new Variable(); 89 89 LaggedVariable laggedVariable = new LaggedVariable(); … … 91 91 TimeLag timeLag = new TimeLag(); 92 92 Integral integral = new Integral(); 93 FactorVariable factorVar = new FactorVariable();94 93 BinaryFactorVariable binFactorVar = new BinaryFactorVariable(); 95 94 … … 98 97 99 98 public ISymbolicExpressionTree Import(string str) { 100 str = str.Replace("(", " ( ").Replace(")", " ) "); 99 str = str.Replace("(", " ( ").Replace(")", " ) ") 100 .Replace("<", " < ").Replace(">", " > ") 101 .Replace("=", " = "); 101 102 ISymbolicExpressionTreeNode root = programRootSymbol.CreateTreeNode(); 102 103 ISymbolicExpressionTreeNode start = startSymbol.CreateTreeNode(); … … 160 161 Expect(Token.RPAR, tokens); 161 162 return tree; 162 } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 163 ConstantTreeNode t = (ConstantTreeNode)constant.CreateTreeNode(); 164 t.Value = tokens.Dequeue().DoubleValue; 163 } else if (tokens.Peek().Symbol == TokenSymbol.CONSTANT) { 164 var value = tokens.Dequeue().DoubleValue; 165 var constant = new Constant() { Value = value }; 166 return constant.CreateTreeNode(); 167 } else if (tokens.Peek().Symbol == TokenSymbol.LBRACKET) { 168 Expect(Token.LBRACKET, tokens); 169 Expect(Token.NUM, tokens); 170 var t = (NumberTreeNode)number.CreateTreeNode(); 171 if (tokens.Peek().Symbol == TokenSymbol.EQ) { 172 Expect(Token.EQ, tokens); 173 var initValToken = tokens.Dequeue(); 174 if (initValToken.Symbol == TokenSymbol.CONSTANT) { 175 t.Value = initValToken.DoubleValue; 176 } else { 177 throw new FormatException("Expected a real value"); 178 } 179 } 180 Expect(Token.RBRACKET, tokens); 165 181 return t; 166 } else throw new FormatException("Expected function or constantsymbol");182 } else throw new FormatException("Expected function or number symbol"); 167 183 } 168 184 … … 225 241 226 242 var weights = new List<double>(); 227 while (tokens.Peek().Symbol == TokenSymbol. NUMBER) {243 while (tokens.Peek().Symbol == TokenSymbol.CONSTANT) { 228 244 weights.Add(tokens.Dequeue().DoubleValue); 229 245 } … … 253 269 254 270 var weightTok = tokens.Dequeue(); 255 Debug.Assert(weightTok.Symbol == TokenSymbol. NUMBER);271 Debug.Assert(weightTok.Symbol == TokenSymbol.CONSTANT); 256 272 t.Weight = weightTok.DoubleValue; 257 273 … … 271 287 272 288 private ISymbolicExpressionTreeNode CreateTree(Token token) { 273 if (token.Symbol != TokenSymbol.SYMB) throw new FormatException("Expected function symbol, but got: " + token.StringValue); 289 if (token.Symbol != TokenSymbol.SYMB && 290 token.Symbol != TokenSymbol.LBRACKET && // LBRACKET and RBRACKET are used for <num=..> and as LT, GT operators 291 token.Symbol != TokenSymbol.RBRACKET 292 ) throw new FormatException("Expected function symbol, but got: " + token.StringValue); 274 293 return knownSymbols[token.StringValue].CreateTreeNode(); 275 294 }
Note: See TracChangeset
for help on using the changeset viewer.