- Timestamp:
- 06/21/13 21:04:20 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicExpressionTreeSmalltalkStringFormatter.cs
r9647 r9649 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 25 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable; 28 27 29 28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Formatters { 30 29 31 [Item("S ymbolicExpressionTreeSmalltalkStringFormatter", "String formatter for string representations of symbolic expression trees in Smalltalk syntax.")]30 [Item("Smalltalk String Formatter", "String formatter for string representations of symbolic expression trees in Smalltalk syntax.")] 32 31 public class SymbolicExpressionTreeSmalltalkStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter { 33 32 34 33 protected SymbolicExpressionTreeSmalltalkStringFormatter(SymbolicExpressionTreeSmalltalkStringFormatter original, Cloner cloner) : base(original, cloner) { } 35 34 public SymbolicExpressionTreeSmalltalkStringFormatter() 36 35 : base() { 37 36 Name = "Smalltalk String Formatter"; 38 37 } 39 38 40 public string Format( SymbolicExpressionTree symbolicExpressionTree) {39 public string Format(ISymbolicExpressionTree symbolicExpressionTree) { 41 40 return FormatRecursively(symbolicExpressionTree.Root); 42 41 } 43 42 44 private string FormatRecursively( SymbolicExpressionTreeNode node) {43 private string FormatRecursively(ISymbolicExpressionTreeNode node) { 45 44 46 Symbol symbol = node.Symbol;45 ISymbol symbol = node.Symbol; 47 46 48 47 if (symbol is ProgramRootSymbol || symbol is StartSymbol) 49 return FormatRecursively(node. SubTrees[0]);48 return FormatRecursively(node.GetSubtree(0)); 50 49 51 50 StringBuilder stringBuilder = new StringBuilder(); … … 54 53 55 54 if (symbol is Addition) { 56 for (int i = 0; i < node.Sub Trees.Count; i++) {55 for (int i = 0; i < node.SubtreeCount; i++) { 57 56 if (i > 0) stringBuilder.Append("+"); 58 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));57 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 59 58 } 60 59 } else if (symbol is And) { 61 60 stringBuilder.Append("("); 62 for (int i = 0; i < node.Sub Trees.Count; i++) {61 for (int i = 0; i < node.SubtreeCount; i++) { 63 62 if (i > 0) stringBuilder.Append("&"); 64 63 stringBuilder.Append("(("); 65 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));64 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 66 65 stringBuilder.Append(")>=0)"); 67 66 } … … 69 68 } else if (symbol is Average) { 70 69 stringBuilder.Append("(1/"); 71 stringBuilder.Append(node.Sub Trees.Count);70 stringBuilder.Append(node.SubtreeCount); 72 71 stringBuilder.Append(")*("); 73 for (int i = 0; i < node.Sub Trees.Count; i++) {72 for (int i = 0; i < node.SubtreeCount; i++) { 74 73 if (i > 0) stringBuilder.Append("+"); 75 74 stringBuilder.Append("("); 76 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));75 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 77 76 stringBuilder.Append(")"); 78 77 } … … 82 81 stringBuilder.Append(constantTreeNode.Value.ToString().Replace(",", ".")); 83 82 } else if (symbol is Cosine) { 84 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));83 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 85 84 stringBuilder.Append(" cos"); 86 85 } else if (symbol is Division) { 87 if (node.Sub Trees.Count == 1) {86 if (node.SubtreeCount == 1) { 88 87 stringBuilder.Append("1/"); 89 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));88 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 90 89 } else { 91 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));90 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 92 91 stringBuilder.Append("/("); 93 for (int i = 1; i < node.Sub Trees.Count; i++) {92 for (int i = 1; i < node.SubtreeCount; i++) { 94 93 if (i > 1) stringBuilder.Append("*"); 95 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));94 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 96 95 } 97 96 stringBuilder.Append(")"); 98 97 } 99 98 } else if (symbol is Exponential) { 100 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));99 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 101 100 stringBuilder.Append(" exp"); 102 101 } else if (symbol is GreaterThan) { 103 102 stringBuilder.Append("("); 104 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));103 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 105 104 stringBuilder.Append(" > "); 106 stringBuilder.Append(FormatRecursively(node. SubTrees[1]));105 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 107 106 stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]"); 108 107 } else if (symbol is IfThenElse) { 109 108 stringBuilder.Append("("); 110 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));109 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 111 110 stringBuilder.Append(" > 0) ifTrue: ["); 112 stringBuilder.Append(FormatRecursively(node. SubTrees[1]));111 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 113 112 stringBuilder.Append("] ifFalse: ["); 114 stringBuilder.Append(FormatRecursively(node. SubTrees[2]));113 stringBuilder.Append(FormatRecursively(node.GetSubtree(2))); 115 114 stringBuilder.Append("]"); 116 115 } else if (symbol is LaggedVariable) { … … 118 117 } else if (symbol is LessThan) { 119 118 stringBuilder.Append("("); 120 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));119 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 121 120 stringBuilder.Append(" < "); 122 stringBuilder.Append(FormatRecursively(node. SubTrees[1]));121 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 123 122 stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]"); 124 123 } else if (symbol is Logarithm) { 125 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));124 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 126 125 stringBuilder.Append("ln"); 127 126 } else if (symbol is Multiplication) { 128 for (int i = 0; i < node.Sub Trees.Count; i++) {127 for (int i = 0; i < node.SubtreeCount; i++) { 129 128 if (i > 0) stringBuilder.Append("*"); 130 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));129 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 131 130 } 132 131 } else if (symbol is Not) { 133 132 stringBuilder.Append("-1*"); 134 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));133 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 135 134 } else if (symbol is Or) { 136 135 stringBuilder.Append("("); 137 for (int i = 0; i < node.Sub Trees.Count; i++) {136 for (int i = 0; i < node.SubtreeCount; i++) { 138 137 if (i > 0) stringBuilder.Append("|"); 139 138 stringBuilder.Append("(("); 140 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));139 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 141 140 stringBuilder.Append(")>=0)"); 142 141 } 143 142 stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]"); 144 143 } else if (symbol is Sine) { 145 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));144 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 146 145 stringBuilder.Append(" sin"); 147 146 } else if (symbol is Subtraction) { 148 if (node.Sub Trees.Count == 1) {147 if (node.SubtreeCount == 1) { 149 148 stringBuilder.Append("-1*"); 150 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));149 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 151 150 } else { 152 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));153 for (int i = 1; i < node.Sub Trees.Count; i++) {151 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 152 for (int i = 1; i < node.SubtreeCount; i++) { 154 153 stringBuilder.Append("-"); 155 stringBuilder.Append(FormatRecursively(node. SubTrees[i]));154 stringBuilder.Append(FormatRecursively(node.GetSubtree(i))); 156 155 } 157 156 } 158 157 } else if (symbol is Tangent) { 159 stringBuilder.Append(FormatRecursively(node. SubTrees[0]));158 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 160 159 stringBuilder.Append("tan"); 161 } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable) {160 } else if (symbol is Variable) { 162 161 VariableTreeNode variableTreeNode = node as VariableTreeNode; 163 162 stringBuilder.Append(variableTreeNode.Weight.ToString().Replace(",", ".")); 164 163 stringBuilder.Append("*"); 165 164 stringBuilder.Append(variableTreeNode.VariableName); 166 } 167 168 else { 165 } else { 169 166 stringBuilder.Append("ERROR"); 170 167 } … … 178 175 return new SymbolicExpressionTreeSmalltalkStringFormatter(this, cloner); 179 176 } 180 181 177 } 182 183 178 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r9587 r9649 140 140 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" /> 141 141 <Compile Include="Formatters\SymbolicDataAnalysisExpressionExcelFormatter.cs" /> 142 <Compile Include="Formatters\SymbolicExpressionTreeSmalltalkStringFormatter.cs" /> 142 143 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" /> 143 144 <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.