Changeset 17434 for branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/Formatters
- Timestamp:
- 02/11/20 13:36:02 (5 years ago)
- Location:
- branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Property svn:mergeinfo changed
-
branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/Formatters/SymbolicExpressionTreeLatexFormatter.cs
r16130 r17434 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2018Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 36 36 {"ProgramRootSymbol", "Prog"}, 37 37 {"StartSymbol","RPB"}, 38 {"Multiplication", "$\\times$"}, 39 {"Division", "$\\div$"}, 40 {"Addition", "$+$"}, 41 {"Subtraction", "$-$"}, 42 {"Exponential", "$\\exp$"}, 43 {"Logarithm", "$\\log$"} 38 // short form 39 {"Subtraction", "-" }, 40 {"Addition", "+" }, 41 {"Multiplication", "*" }, 42 {"Division", "/" }, 43 {"Absolute", "abs" }, 44 {"AnalyticQuotient", "AQ" }, 45 {"Sine", "sin" }, 46 {"Cosine", "cos" }, 47 {"Tanget", "tan" }, 48 {"HyperbolicTangent", "tanh" }, 49 {"Exponential", "exp" }, 50 {"Logarithm", "log" }, 51 {"SquareRoot", "sqrt" }, 52 {"Square", "sqr" }, 53 {"CubeRoot", "cbrt" }, 54 {"Cube", "cube" }, 55 {"GreaterThan", ">" }, 56 {"LessThan", "<" }, 44 57 }; 45 58 … … 65 78 66 79 public string Format(ISymbolicExpressionTree symbolicExpressionTree) { 67 string s;68 Format(symbolicExpressionTree, out s);69 return s;70 }71 72 public Dictionary<ISymbolicExpressionTreeNode, string> Format(ISymbolicExpressionTree symbolicExpressionTree, out string str, int offset = 0) {73 var nodeIds = new Dictionary<ISymbolicExpressionTreeNode, string>();74 80 var root = symbolicExpressionTree.Root; 75 81 var actualRoot = root.SubtreeCount == 0 ? root.GetSubtree(0) : root; … … 85 91 "\\begin{tikzpicture}" + nl + 86 92 "\\def\\ws{1}" + nl + 87 "\\def\\hs{0.7}" + nl + 88 "\\def\\offs{" + offset + "}" + nl); 93 "\\def\\hs{0.7}" + nl); 89 94 95 var nodeIndices = new Dictionary<ISymbolicExpressionTreeNode, int>(); 90 96 var nodes = symbolicExpressionTree.IterateNodesBreadth().ToList(); 91 97 for (int i = 0; i < nodes.Count; ++i) { 92 98 var node = nodes[i]; 93 var id = Guid.NewGuid().ToString(); 94 nodeIds[node] = id; 99 nodeIndices.Add(node, i); 95 100 var coord = nodeCoordinates[node]; 96 101 var nodeName = symbolNameMap.ContainsKey(node.Symbol.Name) ? symbolNameMap[node.Symbol.Name] : node.ToString(); 97 sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1} + \\offs,\\hs*{2}) {{{3}}};", nodeIds[node], ws * coord.X, -hs * coord.Y, EscapeLatexString(nodeName)));102 sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1},\\hs*{2}) {{{3}}};", i, ws * coord.X, -hs * coord.Y, EscapeLatexString(nodeName))); 98 103 } 99 104 100 105 for (int i = 0; i < nodes.Count; ++i) { 101 var n = nodes[i];102 106 foreach (var s in nodes[i].Subtrees) { 103 sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", nodeIds[n], nodeIds[s]));107 sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", i, nodeIndices[s])); 104 108 } 105 109 } … … 107 111 sb.Append("\\end{tikzpicture}" + nl + 108 112 "\\end{document}" + nl); 109 str = sb.ToString(); 110 return nodeIds; 113 return sb.ToString(); 111 114 } 112 115
Note: See TracChangeset
for help on using the changeset viewer.