Changeset 13482 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters
- Timestamp:
- 12/17/15 20:43:07 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs
r12155 r13482 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Text; 23 24 using HeuristicLab.Common; … … 32 33 33 34 public bool Indent { get; set; } 35 public bool AppendNewLines { get; set; } 36 37 private static readonly Dictionary<string, string> PrettyNames = new Dictionary<string, string> { 38 { "Addition", "+"}, {"Subtraction", "-" }, {"Multiplication", "*" }, {"Division", "/" }, {"Logarithm", "log" }, {"Exponential", "exp" } 39 }; 34 40 35 41 [StorableConstructor] … … 60 66 if (node.SubtreeCount > 0) { 61 67 // symbol on same line as '(' 62 strBuilder.AppendLine(node.ToString()); 68 string name; 69 PrettyNames.TryGetValue(node.ToString(), out name); 70 if (name == null) name = node.ToString(); 71 strBuilder.Append(name); 72 if (AppendNewLines) 73 strBuilder.AppendLine(); 63 74 // each subtree expression on a new line 64 75 // and closing ')' also on new line 65 76 foreach (var subtree in node.Subtrees) { 66 strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2)); 77 strBuilder.Append(FormatRecursively(subtree, indentLength + 2)); 78 if (AppendNewLines) 79 strBuilder.AppendLine(); 67 80 } 68 81 if (Indent) strBuilder.Append(' ', indentLength); 69 strBuilder.Append(") ");82 strBuilder.Append(") "); 70 83 } else { 71 84 // symbol in the same line with as '(' and ')' 72 strBuilder.Append(node .ToString());73 strBuilder.Append(") ");85 strBuilder.Append(node); 86 strBuilder.Append(") "); 74 87 } 75 88 return strBuilder.ToString();
Note: See TracChangeset
for help on using the changeset viewer.