Changeset 9794
- Timestamp:
- 07/27/13 14:21:20 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicExpressionTreeSmalltalkStringFormatter.cs
r9649 r9794 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System.Globalization; 22 23 using System.Text; 23 24 using HeuristicLab.Core; … … 41 42 } 42 43 44 // returns the smalltalk expression corresponding to the node 45 // smalltalk expressions are always surrounded by parantheses "(<expr>)" 43 46 private string FormatRecursively(ISymbolicExpressionTreeNode node) { 44 47 … … 48 51 return FormatRecursively(node.GetSubtree(0)); 49 52 50 StringBuilder stringBuilder = new StringBuilder( );53 StringBuilder stringBuilder = new StringBuilder(20); 51 54 52 55 stringBuilder.Append("("); … … 61 64 for (int i = 0; i < node.SubtreeCount; i++) { 62 65 if (i > 0) stringBuilder.Append("&"); 63 stringBuilder.Append("( (");66 stringBuilder.Append("("); 64 67 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 65 stringBuilder.Append(" )>=0)");68 stringBuilder.Append(" > 0)"); 66 69 } 67 70 stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]"); … … 72 75 for (int i = 0; i < node.SubtreeCount; i++) { 73 76 if (i > 0) stringBuilder.Append("+"); 74 stringBuilder.Append("(");75 77 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 76 stringBuilder.Append(")");77 78 } 78 79 stringBuilder.Append(")"); 79 80 } else if (symbol is Constant) { 80 81 ConstantTreeNode constantTreeNode = node as ConstantTreeNode; 81 stringBuilder.Append(constantTreeNode.Value.ToString( ).Replace(",", "."));82 stringBuilder.Append(constantTreeNode.Value.ToString(CultureInfo.InvariantCulture)); 82 83 } else if (symbol is Cosine) { 83 84 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); … … 114 115 stringBuilder.Append("]"); 115 116 } else if (symbol is LaggedVariable) { 116 stringBuilder.Append(" not implemented");117 stringBuilder.Append("lagged variable not implemented"); 117 118 } else if (symbol is LessThan) { 118 119 stringBuilder.Append("("); … … 130 131 } 131 132 } else if (symbol is Not) { 132 stringBuilder.Append(" -1*");133 stringBuilder.Append("("); 133 134 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 135 stringBuilder.Append(">0) ifTrue: [-1] ifFalse: [1.0]"); 134 136 } else if (symbol is Or) { 135 137 stringBuilder.Append("("); 136 138 for (int i = 0; i < node.SubtreeCount; i++) { 137 139 if (i > 0) stringBuilder.Append("|"); 138 stringBuilder.Append("( (");140 stringBuilder.Append("("); 139 141 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 140 stringBuilder.Append(" )>=0)");142 stringBuilder.Append(">0)"); 141 143 } 142 144 stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]"); … … 151 153 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 152 154 for (int i = 1; i < node.SubtreeCount; i++) { 153 stringBuilder.Append(" -");155 stringBuilder.Append(" - "); 154 156 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 155 157 } … … 157 159 } else if (symbol is Tangent) { 158 160 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 159 stringBuilder.Append(" tan");161 stringBuilder.Append(" tan"); 160 162 } else if (symbol is Variable) { 161 163 VariableTreeNode variableTreeNode = node as VariableTreeNode; 162 stringBuilder.Append(variableTreeNode.Weight.ToString( ).Replace(",", "."));164 stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture)); 163 165 stringBuilder.Append("*"); 164 166 stringBuilder.Append(variableTreeNode.VariableName); 165 167 } else { 166 stringBuilder.Append("ERROR"); 168 stringBuilder.Append("("); 169 for (int i = 0; i < node.SubtreeCount; i++) { 170 if (i > 0) stringBuilder.Append(", "); 171 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 172 } 173 stringBuilder.AppendFormat(" {0} [Not Supported] )", node.Symbol.Name); 167 174 } 168 175
Note: See TracChangeset
for help on using the changeset viewer.