Changeset 3462 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs
- Timestamp:
- 04/21/10 15:21:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs
r3442 r3462 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 29 29 using System.Diagnostics; … … 38 38 /// </summary> 39 39 public class SymbolicSimplifier { 40 private Addition addSymbol = new Addition(); 41 private Multiplication mulSymbol = new Multiplication(); 42 private Division divSymbol = new Division(); 43 private Constant constSymbol = new Constant(); 44 private Variable varSymbol = new Variable(); 45 40 46 public SymbolicExpressionTree Simplify(SymbolicExpressionTree originalTree) { 41 47 var clone = (SymbolicExpressionTreeNode)originalTree.Root.Clone(); … … 194 200 return a; 195 201 } else { 196 var div = (new Division()).CreateTreeNode();202 var div = divSymbol.CreateTreeNode(); 197 203 div.SubTrees.Add(a); 198 204 div.SubTrees.Add(b); … … 215 221 } else if (IsAddition(a) && IsAddition(b)) { 216 222 // merge additions 217 var add = (new Addition()).CreateTreeNode();223 var add = addSymbol.CreateTreeNode(); 218 224 for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]); 219 225 for (int i = 0; i < b.SubTrees.Count - 1; i++) add.AddSubTree(b.SubTrees[i]); … … 232 238 return MakeAddition(b, a); 233 239 } else if (IsAddition(a) && IsConstant(b)) { 234 var add = (new Addition()).CreateTreeNode();240 var add = addSymbol.CreateTreeNode(); 235 241 for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]); 236 242 if (IsConstant(a.SubTrees.Last())) … … 242 248 return add; 243 249 } else if (IsAddition(a)) { 244 var add = (new Addition()).CreateTreeNode();250 var add = addSymbol.CreateTreeNode(); 245 251 add.AddSubTree(b); 246 252 foreach (var subTree in a.SubTrees) { … … 250 256 return add; 251 257 } else { 252 var add = (new Addition()).CreateTreeNode();258 var add = addSymbol.CreateTreeNode(); 253 259 add.SubTrees.Add(a); 254 260 add.SubTrees.Add(b); … … 296 302 return MakeDivision(MakeMultiplication(b.SubTrees[0], a), b.SubTrees[1]); 297 303 } else if (IsMultiplication(a) && IsMultiplication(b)) { 298 var mul = (new Multiplication()).CreateTreeNode();304 var mul = mulSymbol.CreateTreeNode(); 299 305 for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]); 300 306 for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]); … … 302 308 return mul; 303 309 } else if (IsMultiplication(a)) { 304 var mul = (new Multiplication()).CreateTreeNode();310 var mul = mulSymbol.CreateTreeNode(); 305 311 for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]); 306 312 mul.AddSubTree(MakeMultiplication(a.SubTrees.Last(), b)); 307 313 return mul; 308 314 } else if (IsMultiplication(b)) { 309 var mul = (new Multiplication()).CreateTreeNode();315 var mul = mulSymbol.CreateTreeNode(); 310 316 for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]); 311 317 mul.AddSubTree(MakeMultiplication(b.SubTrees.Last(), a)); 312 318 return mul; 313 319 } else { 314 var mul = (new Multiplication()).CreateTreeNode();320 var mul = mulSymbol.CreateTreeNode(); 315 321 mul.SubTrees.Add(a); 316 322 mul.SubTrees.Add(b); … … 346 352 347 353 private SymbolicExpressionTreeNode MakeConstant(double value) { 348 ConstantTreeNode constantTreeNode = (ConstantTreeNode)( new Constant().CreateTreeNode());354 ConstantTreeNode constantTreeNode = (ConstantTreeNode)(constSymbol.CreateTreeNode()); 349 355 constantTreeNode.Value = value; 350 356 return (SymbolicExpressionTreeNode)constantTreeNode; … … 352 358 353 359 private SymbolicExpressionTreeNode MakeVariable(double weight, string name) { 354 var tree = (VariableTreeNode) (new Variable().CreateTreeNode());360 var tree = (VariableTreeNode)varSymbol.CreateTreeNode(); 355 361 tree.Weight = weight; 356 362 tree.VariableName = name;
Note: See TracChangeset
for help on using the changeset viewer.