Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
- Timestamp:
- 03/18/19 17:24:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
r12012 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 private const string INVOKESTART = "CALL"; 36 36 private const string TIMELAGSTART = "LAG"; 37 private Dictionary<string, Symbol> knownSymbols = new Dictionary<string, Symbol>() 37 private Dictionary<string, Symbol> knownSymbols = new Dictionary<string, Symbol>() 38 38 { 39 39 {"+", new Addition()}, … … 45 45 {"POW", new Power()}, 46 46 {"ROOT", new Root()}, 47 {"SQR", new Square()}, 48 {"SQRT", new SquareRoot()}, 47 49 {"SIN",new Sine()}, 48 50 {"COS", new Cosine()}, … … 74 76 {"PROG", new ProgramRootSymbol()}, 75 77 {"MAIN", new StartSymbol()}, 78 {"FACTOR", new FactorVariable() }, 79 {"BINFACTOR", new BinaryFactorVariable()} 76 80 }; 77 81 … … 82 86 TimeLag timeLag = new TimeLag(); 83 87 Integral integral = new Integral(); 88 FactorVariable factorVar = new FactorVariable(); 89 BinaryFactorVariable binFactorVar = new BinaryFactorVariable(); 84 90 85 91 ProgramRootSymbol programRootSymbol = new ProgramRootSymbol(); … … 136 142 tree.AddSubtree(ParseSexp(tokens)); 137 143 } 144 } else if (tokens.Peek().StringValue.StartsWith("FACTOR")) { 145 tree = ParseFactor(tokens); 146 } else if (tokens.Peek().StringValue.StartsWith("BINFACTOR")) { 147 tree = ParseBinaryFactor(tokens); 138 148 } else { 139 149 Token curToken = tokens.Dequeue(); … … 201 211 } 202 212 213 private ISymbolicExpressionTreeNode ParseFactor(Queue<Token> tokens) { 214 Token tok = tokens.Dequeue(); 215 Debug.Assert(tok.StringValue == "FACTOR"); 216 FactorVariableTreeNode t = (FactorVariableTreeNode)(new FactorVariable()).CreateTreeNode(); // create a new symbol each time on purpose 217 var varNameTok = tokens.Dequeue(); 218 Debug.Assert(tok.Symbol == TokenSymbol.SYMB); 219 t.VariableName = varNameTok.StringValue; 220 221 var weights = new List<double>(); 222 while (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 223 weights.Add(tokens.Dequeue().DoubleValue); 224 } 225 226 t.Weights = weights.ToArray(); 227 228 // create a set of (virtual) values to match the number of weights 229 t.Symbol.VariableNames = new string[] { t.VariableName }; 230 t.Symbol.VariableValues = new[] 231 { new KeyValuePair<string, Dictionary<string,int>>( 232 t.VariableName, 233 weights.Select((_, i) => Tuple.Create(_,i)).ToDictionary(tup=>"X" + tup.Item2, tup=>tup.Item2)) }; 234 return t; 235 } 236 237 private ISymbolicExpressionTreeNode ParseBinaryFactor(Queue<Token> tokens) { 238 Token tok = tokens.Dequeue(); 239 Debug.Assert(tok.StringValue == "BINFACTOR"); 240 var t = (BinaryFactorVariableTreeNode)binFactorVar.CreateTreeNode(); 241 var varNameTok = tokens.Dequeue(); 242 Debug.Assert(varNameTok.Symbol == TokenSymbol.SYMB); 243 t.VariableName = varNameTok.StringValue; 244 245 var varValTok = tokens.Dequeue(); 246 Debug.Assert(varValTok.Symbol == TokenSymbol.SYMB); 247 t.VariableValue = varValTok.StringValue; 248 249 var weightTok = tokens.Dequeue(); 250 Debug.Assert(weightTok.Symbol == TokenSymbol.NUMBER); 251 t.Weight = weightTok.DoubleValue; 252 253 return t; 254 } 255 256 203 257 private ISymbolicExpressionTreeNode ParseLaggedVariable(Queue<Token> tokens) { 204 258 Token varTok = tokens.Dequeue();
Note: See TracChangeset
for help on using the changeset viewer.