Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs	(revision 10561)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs	(revision 10565)
@@ -1,90 +1,74 @@
-﻿
+﻿#region License Information
+
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#endregion
+
 using System;
 using System.Collections.Generic;
-using System.Drawing;
 using System.Linq;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
   public class BoxesLayoutEngine<T> : ILayoutEngine<T> where T : class {
-    private readonly Dictionary<T, VisualTreeNode<T>> nodeMap;
-
     public int NodeWidth { get; set; }
     public int NodeHeight { get; set; }
     public int HorizontalSpacing { get; set; }
     public int VerticalSpacing { get; set; }
-    private VisualTreeNode<T> layoutRoot;
 
-    public int Width { get; private set; }
-    public int Height { get; private set; }
+    private readonly Func<T, IEnumerable<T>> GetChildren;
+    private readonly Func<T, int> GetLength;
+    private readonly Func<T, int> GetDepth;
 
-    public Func<T, IEnumerable<T>> GetChildren { get; set; }
-    public Func<T, int> GetLength { get; set; }
-    public Func<T, int> GetDepth { get; set; }
+    public BoxesLayoutEngine(Func<T, IEnumerable<T>> GetChildren, Func<T, int> GetLength, Func<T, int> GetDepth) {
+      if (GetChildren == null) throw new ArgumentNullException("GetChildren");
+      if (GetLength == null) throw new ArgumentNullException("GetLength");
+      if (GetDepth == null) throw new ArgumentNullException("GetDepth");
 
-    public BoxesLayoutEngine() {
-      nodeMap = new Dictionary<T, VisualTreeNode<T>>();
+      this.GetChildren = GetChildren;
+      this.GetLength = GetLength;
+      this.GetDepth = GetDepth;
     }
 
-    public void CalculateLayout() {
-      throw new Exception("The BoxesLayoutEngine does not support arbitrary bounds. Please use method CalculateLayout(Width, Height)");
+
+    public IEnumerable<VisualTreeNode<T>> CalculateLayout(T root, float width, float height) {
+      var nodeMap = new Dictionary<T, VisualTreeNode<T>>();
+      CreateVisualNodes(root, nodeMap);
+      RecursiveLayout(nodeMap, nodeMap[root], 0, 0, (int)Math.Round(width), (int)Math.Round(height) / GetDepth(root));
+      return nodeMap.Values;
     }
 
-    public void CalculateLayout(float width, float height) {
-      Width = (int)Math.Round(width);
-      Height = (int)Math.Round(height);
-      Reset();
-      RecursiveLayout(layoutRoot, 0, 0, Width, Height / GetDepth(layoutRoot.Content));
-    }
-
-    public void Initialize(T root, Func<T, IEnumerable<T>> getChildren, Func<T, int> getLength, Func<T, int> getDepth) {
-      if (getChildren == null || getLength == null || getDepth == null)
-        throw new ArgumentNullException("The BoxesLayoutEngine requires all of the lambdas: (getChildren, getLength and getDepth) to be defined.");
-      GetChildren = getChildren;
-      GetLength = getLength;
-      GetDepth = getDepth;
-      Clear();
-      Expand(root); // produce the nodeMap
-      layoutRoot = nodeMap[root];
-    }
-
-    private void Expand(T root) {
+    private void CreateVisualNodes(T root, Dictionary<T, VisualTreeNode<T>> map) {
       var node = new VisualTreeNode<T>(root) {
         PreferredWidth = NodeWidth,
         PreferredHeight = NodeHeight
       };
-      nodeMap.Add(root, node);
+
+      map.Add(root, node);
       var children = GetChildren(root).ToList();
       if (children.Any()) {
         foreach (var child in children) {
-          Expand(child);
+          CreateVisualNodes(child, map);
         }
       }
     }
 
-    public void Center(float width, float height) {
-      // does nothing because the BoxesLayout centers the tree by default
-    }
-
-    public void Clear() {
-      nodeMap.Clear();
-      layoutRoot = null;
-    }
-
-    public void Reset() {
-      foreach (var node in nodeMap.Values) {
-        node.X = 0;
-        node.Y = 0;
-      }
-    }
-
-    public Dictionary<T, PointF> GetCoordinates() {
-      return nodeMap.ToDictionary(x => x.Key, x => new PointF(x.Value.X, x.Value.Y));
-    }
-
-    public void FitToBounds(float width, float height) {
-      // does nothing because the BoxesLayout is by default stretched on the whole drawing area
-    }
-
-    private void RecursiveLayout(VisualTreeNode<T> visualTreeNode, int x, int y, int width, int height) {
+    private void RecursiveLayout(Dictionary<T, VisualTreeNode<T>> nodeMap, VisualTreeNode<T> visualTreeNode, int x, int y, int width, int height) {
       float center_x = x + width / 2;
       float center_y = y + height / 2;
@@ -127,14 +111,6 @@
       for (int i = 0; i < children.Count; i++) {
         xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)GetLength(children[i])) / (GetLength(node) - 1));
-        RecursiveLayout(nodeMap[children[i]], xBoundaries[i], y + height, xBoundaries[i + 1] - xBoundaries[i], height);
+        RecursiveLayout(nodeMap, nodeMap[children[i]], xBoundaries[i], y + height, xBoundaries[i + 1] - xBoundaries[i], height);
       }
-    }
-
-    public IEnumerable<T> GetContentNodes() {
-      return nodeMap.Keys;
-    }
-
-    public IEnumerable<VisualTreeNode<T>> GetVisualNodes() {
-      return nodeMap.Values;
     }
   }
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs	(revision 10561)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs	(revision 10565)
@@ -1,6 +1,26 @@
-﻿
-using System;
+﻿#region License Information
+
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#endregion
+
 using System.Collections.Generic;
-using System.Drawing;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
@@ -11,18 +31,5 @@
     int VerticalSpacing { get; set; }
 
-    void CalculateLayout();
-    void CalculateLayout(float width, float height);
-    void Initialize(T root, Func<T, IEnumerable<T>> getChildren, Func<T, int> getLength = null, Func<T, int> getDepth = null);
-    void Clear();
-    void Reset();
-
-    // function members necessary to navigate the tree structure
-    Func<T, IEnumerable<T>> GetChildren { get; set; }
-    Func<T, int> GetLength { get; set; }
-    Func<T, int> GetDepth { get; set; }
-
-    IEnumerable<T> GetContentNodes();
-    IEnumerable<VisualTreeNode<T>> GetVisualNodes();
-    Dictionary<T, PointF> GetCoordinates();
+    IEnumerable<VisualTreeNode<T>> CalculateLayout(T root, float width, float height);
   }
 }
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/LayoutNode.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/LayoutNode.cs	(revision 10561)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/LayoutNode.cs	(revision 10565)
@@ -25,5 +25,5 @@
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
-  public class LayoutNode<T> : object where T : class {
+  internal class LayoutNode<T> : object where T : class {
     public float Width { get; set; }
     public float Height { get; set; }
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs	(revision 10561)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs	(revision 10565)
@@ -7,5 +7,4 @@
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
   public class ReingoldTilfordLayoutEngine<T> : ILayoutEngine<T> where T : class {
-    private readonly Dictionary<T, LayoutNode<T>> nodeMap; // provides a reverse mapping T => LayoutNode
     public int NodeWidth { get; set; }
     public int NodeHeight { get; set; }
@@ -22,29 +21,38 @@
     }
 
-    public Func<T, IEnumerable<T>> GetChildren { get; set; }
-    public Func<T, int> GetLength { get; set; }
-    public Func<T, int> GetDepth { get; set; }
-    private LayoutNode<T> layoutRoot;
-
-    public ReingoldTilfordLayoutEngine() {
-      nodeMap = new Dictionary<T, LayoutNode<T>>();
-    }
-
-    public ReingoldTilfordLayoutEngine(T root, Func<T, IEnumerable<T>> childrenFunc)
-      : this() {
-      Initialize(root, childrenFunc);
-    }
-
-    public void Initialize(T root, Func<T, IEnumerable<T>> getChildren, Func<T, int> getLength = null, Func<T, int> getDepth = null) {
-      GetChildren = getChildren;
-      Clear();
-      var node = new LayoutNode<T> { Content = root, Width = NodeWidth, Height = NodeHeight };
-      node.Ancestor = node;
-      layoutRoot = node;
-      Expand(node);
-    }
-
-    private void Expand(LayoutNode<T> lRoot) {
-      nodeMap.Add(lRoot.Content, lRoot);
+    private readonly Func<T, IEnumerable<T>> GetChildren;
+
+    public ReingoldTilfordLayoutEngine(Func<T, IEnumerable<T>> GetChildren) {
+      this.GetChildren = GetChildren;
+    }
+
+    public IEnumerable<VisualTreeNode<T>> CalculateLayout(T root) {
+      return CalculateLayout(root, 0, 0);
+    }
+
+    public IEnumerable<VisualTreeNode<T>> CalculateLayout(T root, float width, float height) {
+      Dictionary<T, LayoutNode<T>> layoutNodeMap = new Dictionary<T, LayoutNode<T>>();
+      var layoutRoot = new LayoutNode<T> { Content = root, Width = NodeWidth, Height = NodeHeight, };
+      layoutRoot.Ancestor = layoutRoot;
+      Expand(layoutRoot, layoutNodeMap);
+
+      FirstWalk(layoutRoot);
+      SecondWalk(layoutRoot, -layoutRoot.Prelim);
+      NormalizeCoordinates(layoutNodeMap.Values);
+      if (height != 0 && width != 0) {
+        FitToBounds(width, height, layoutNodeMap.Values);
+        Center(width, height, layoutNodeMap.Values);
+      }
+
+      return layoutNodeMap.Values.Select(x => new VisualTreeNode<T>(x.Content) {
+        Width = (int)Math.Round(x.Width),
+        Height = (int)Math.Round(x.Height),
+        X = (int)Math.Round(x.X),
+        Y = (int)Math.Round(x.Y)
+      });
+    }
+
+    private void Expand(LayoutNode<T> lRoot, Dictionary<T, LayoutNode<T>> map) {
+      map.Add(lRoot.Content, lRoot);
       var children = GetChildren(lRoot.Content).ToList();
       if (!children.Any()) return;
@@ -61,63 +69,13 @@
         node.Ancestor = node;
         lRoot.Children.Add(node);
-        Expand(node);
-      }
-    }
-
-    public IEnumerable<T> GetContentNodes() {
-      return nodeMap.Keys;
-    }
-
-    public IEnumerable<VisualTreeNode<T>> GetVisualNodes() {
-      return nodeMap.Values.Select(x => new VisualTreeNode<T>(x.Content) {
-        Width = (int)Math.Round(x.Width),
-        Height = (int)Math.Round(x.Height),
-        X = (int)Math.Round(x.X),
-        Y = (int)Math.Round(x.Y)
-      });
-    }
-
-    public IEnumerable<LayoutNode<T>> GetLayoutNodes() {
-      return nodeMap.Values;
-    }
-
-    public void AddNode(T content) {
-      if (nodeMap.ContainsKey(content)) { throw new ArgumentException("Content already present in the dictionary."); }
-      var node = new LayoutNode<T> { Content = content };
-      nodeMap.Add(content, node);
-    }
-
-    public void AddNode(LayoutNode<T> node) {
-      var content = node.Content;
-      if (nodeMap.ContainsKey(content)) { throw new ArgumentException("Content already present in the dictionary."); }
-      nodeMap.Add(content, node);
-    }
-
-    public void AddNodes(IEnumerable<LayoutNode<T>> nodes) {
-      foreach (var node in nodes)
-        nodeMap.Add(node.Content, node);
-    }
-
-    public LayoutNode<T> GetNode(T content) {
-      LayoutNode<T> layoutNode;
-      nodeMap.TryGetValue(content, out layoutNode);
-      return layoutNode;
-    }
-
-    public void ResetCoordinates() {
-      foreach (var node in nodeMap.Values) {
-        node.ResetCoordinates();
-      }
-    }
-
-    public Dictionary<T, PointF> GetCoordinates() {
-      return nodeMap.ToDictionary(x => x.Key, x => new PointF(x.Value.X, x.Value.Y));
-    }
+        Expand(node, map);
+      }
+    }
+
 
     /// <summary>
     /// Transform LayoutNode coordinates so that all coordinates are positive and start from (0,0)
     /// </summary>
-    private void NormalizeCoordinates() {
-      var nodes = nodeMap.Values.ToList();
+    private static void NormalizeCoordinates(IEnumerable<LayoutNode<T>> nodes) {
       float xmin = 0, ymin = 0;
       foreach (var node in nodes) {
@@ -131,15 +89,15 @@
     }
 
-    public void Center(float width, float height) {
+    private void Center(float width, float height, IEnumerable<LayoutNode<T>> nodes) {
       // center layout on screen
-      var bounds = Bounds();
+      var bounds = Bounds(nodes);
       float dx = 0, dy = 0;
       if (width > bounds.Width) { dx = (width - bounds.Width) / 2f; }
       if (height > bounds.Height) { dy = (height - bounds.Height) / 2f; }
-      foreach (var node in nodeMap.Values) { node.Translate(dx, dy); }
-    }
-
-    public void FitToBounds(float width, float height) {
-      var bounds = Bounds();
+      foreach (var node in nodes) { node.Translate(dx, dy); }
+    }
+
+    private void FitToBounds(float width, float height, IEnumerable<LayoutNode<T>> nodes) {
+      var bounds = Bounds(nodes);
       var myWidth = bounds.Width;
       var myHeight = bounds.Height;
@@ -147,5 +105,5 @@
       if (myWidth <= width && myHeight <= height) return; // no need to fit since we are within bounds
 
-      var layers = nodeMap.Values.GroupBy(node => node.Level, node => node).ToList();
+      var layers = nodes.GroupBy(node => node.Level, node => node).ToList();
 
       if (myWidth > width) {
@@ -158,9 +116,9 @@
         float spacing = minHorizontalSpacing * x;
         foreach (var layer in layers) {
-          var nodes = layer.ToList();
+          var nodesLayer = layer.ToList();
           float minWidth = float.MaxValue;
-          for (int i = 0; i < nodes.Count - 1; ++i) { minWidth = Math.Min(minWidth, nodes[i + 1].X - nodes[i].X); }
+          for (int i = 0; i < nodesLayer.Count - 1; ++i) { minWidth = Math.Min(minWidth, nodesLayer[i + 1].X - nodesLayer[i].X); }
           float w = Math.Min(NodeWidth, minWidth - spacing);
-          foreach (var node in nodes) {
+          foreach (var node in nodesLayer) {
             node.X += (node.Width - w) / 2f;
             node.Width = w;
@@ -186,32 +144,4 @@
     }
 
-    public void Clear() {
-      layoutRoot = null;
-      nodeMap.Clear();
-    }
-
-    public void Reset() {
-      foreach (var layoutNode in nodeMap.Values) {
-        // reset layout-related parameters 
-        layoutNode.Reset();
-        // reset the width and height since they might have been affected by scaling
-        layoutNode.Width = NodeWidth;
-        layoutNode.Height = NodeHeight;
-      }
-    }
-
-    public void CalculateLayout() {
-      if (layoutRoot == null) throw new Exception("Layout layoutRoot cannot be null.");
-      Reset(); // reset node parameters like Mod, Shift etc. and set coordinates to 0
-      FirstWalk(layoutRoot);
-      SecondWalk(layoutRoot, -layoutRoot.Prelim);
-      NormalizeCoordinates();
-    }
-
-    public void CalculateLayout(float width, float height) {
-      CalculateLayout();
-      FitToBounds(width, height);
-      Center(width, height);
-    }
 
     /// <summary>
@@ -219,8 +149,7 @@
     /// </summary>
     /// <returns></returns>
-    public RectangleF Bounds() {
+    private RectangleF Bounds(IEnumerable<LayoutNode<T>> nodes) {
       float xmin = 0, xmax = 0, ymin = 0, ymax = 0;
-      var list = nodeMap.Values.ToList();
-      foreach (LayoutNode<T> node in list) {
+      foreach (LayoutNode<T> node in nodes) {
         float x = node.X, y = node.Y;
         if (xmin > x) xmin = x;
