Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/13/14 17:20:36 (10 years ago)
Author:
bburlacu
Message:

#1772: Added partially working implementation of a bottom-up distance calculator for symbolic expression trees. Changed latex formatter to also return a map of node ids (useful when wanting to display trees side by side).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/Formatters/SymbolicExpressionTreeLatexFormatter.cs

    r10655 r11015  
    6565
    6666    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>();
    6774      var root = symbolicExpressionTree.Root;
    6875      var actualRoot = root.SubtreeCount == 0 ? root.GetSubtree(0) : root;
     
    7885                "\\begin{tikzpicture}" + nl +
    7986                "\\def\\ws{1}" + nl +
    80                 "\\def\\hs{0.7}" + nl);
     87                "\\def\\hs{0.7}" + nl +
     88                "\\def\\offs{" + offset + "}" + nl);
    8189
    82       var nodeIndices = new Dictionary<ISymbolicExpressionTreeNode, int>();
    8390      var nodes = symbolicExpressionTree.IterateNodesBreadth().ToList();
    8491      for (int i = 0; i < nodes.Count; ++i) {
    8592        var node = nodes[i];
    86         nodeIndices.Add(node, i);
     93        var id = Guid.NewGuid().ToString();
     94        nodeIds[node] = id;
    8795        var coord = nodeCoordinates[node];
    8896        var nodeName = symbolNameMap.ContainsKey(node.Symbol.Name) ? symbolNameMap[node.Symbol.Name] : node.ToString();
    89         sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1},\\hs*{2}) {{{3}}};", i, ws * coord.X, -hs * coord.Y, EscapeLatexString(nodeName)));
     97        sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1} + {2},\\hs*{3}) {{{4}}};", nodeIds[node], ws * coord.X, offset, -hs * coord.Y, EscapeLatexString(nodeName)));
    9098      }
    9199
    92100      for (int i = 0; i < nodes.Count; ++i) {
     101        var n = nodes[i];
    93102        foreach (var s in nodes[i].Subtrees) {
    94           sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", i, nodeIndices[s]));
     103          sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", nodeIds[n], nodeIds[s]));
    95104        }
    96105      }
     
    98107      sb.Append("\\end{tikzpicture}" + nl +
    99108                "\\end{document}" + nl);
    100       return sb.ToString();
     109      str = sb.ToString();
     110      return nodeIds;
    101111    }
    102112
Note: See TracChangeset for help on using the changeset viewer.