Changeset 10524


Ignore:
Timestamp:
02/28/14 15:21:02 (6 years ago)
Author:
bburlacu
Message:

#1772: Reverse-merged erroneous commit (booked on ticked #2076), and merged latest trunk changes.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
3 deleted
14 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj

    r10514 r10524  
    174174  </ItemGroup>
    175175  <ItemGroup>
     176    <Compile Include="Formatters\SymbolicExpressionTreeLatexFormatter.cs" />
     177    <Compile Include="LayoutEngines\BoxesLayoutEngine.cs" />
     178    <Compile Include="LayoutEngines\ILayoutEngine.cs" />
     179    <Compile Include="LayoutEngines\LayoutNode.cs" />
     180    <Compile Include="LayoutEngines\ReingoldTilfordLayoutEngine.cs" />
    176181    <Compile Include="Plugin.cs" />
    177182    <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.cs">
     
    225230      <DependentUpon>SymbolicExpressionView.cs</DependentUpon>
    226231    </Compile>
    227     <Compile Include="VisualSymbolicExpressionTreeNode.cs" />
    228     <Compile Include="VisualSymbolicExpressionTreeNodeConnection.cs" />
     232    <Compile Include="VisualTreeNode.cs" />
     233    <Compile Include="VisualTreeNodeConnection.cs" />
    229234  </ItemGroup>
    230235  <ItemGroup>
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs

    r9456 r10524  
    2929using HeuristicLab.PluginInfrastructure;
    3030
     31using VisualSymbolicExpressionTreeNode = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.VisualTreeNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>;
     32
    3133namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    3234  public sealed partial class SymbolicExpressionGrammarAllowedChildSymbolsControl : UserControl {
     
    162164
    163165      VisualSymbolicExpressionTreeNode clickedNode = (VisualSymbolicExpressionTreeNode)sender;
    164       var selectedNode = clickedNode.SymbolicExpressionTreeNode;
     166      var selectedNode = clickedNode.Content;
    165167      if (selectedNode.SubtreeCount == 0) {
    166168        if (!selectedSymbolicExpressionTreeNodes.Contains(selectedNode))
     
    207209        var visualNode = symbolicExpressionTreeChart.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y);
    208210        if (visualNode != null) {
    209           var node = visualNode.SymbolicExpressionTreeNode;
     211          var node = visualNode.Content;
    210212          var root = symbolicExpressionTreeChart.Tree.Root;
    211213          if (node == root || node.Parent == root) e.Effect = DragDropEffects.Copy;
     
    223225      var symbols = data as IEnumerable<ISymbol>;
    224226
    225       if (node.SymbolicExpressionTreeNode == root) {
     227      if (node.Content == root) {
    226228        if (symbol != null)
    227229          Grammar.AddAllowedChildSymbol(root.Symbol, symbol);
     
    229231          foreach (var s in symbols) Grammar.AddAllowedChildSymbol(root.Symbol, s);
    230232      } else {
    231         int argumentIndex = root.IndexOfSubtree(node.SymbolicExpressionTreeNode);
     233        int argumentIndex = root.IndexOfSubtree(node.Content);
    232234        if (symbol != null)
    233235          Grammar.AddAllowedChildSymbol(root.Symbol, symbol, argumentIndex);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs

    r10501 r10524  
    4949      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    5050      this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     51      this.exportPgfLaTeXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     52      this.layoutEngineToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     53      this.reingoldTilfordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     54      this.boxesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5155      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    52       this.exportPgfLaTeXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5356      this.contextMenuStrip.SuspendLayout();
    5457      this.SuspendLayout();
     
    5861      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    5962            this.saveImageToolStripMenuItem,
    60             this.exportPgfLaTeXToolStripMenuItem});
     63            this.exportPgfLaTeXToolStripMenuItem,
     64            this.layoutEngineToolStripMenuItem});
    6165      this.contextMenuStrip.Name = "contextMenuStrip";
    6266      this.contextMenuStrip.Size = new System.Drawing.Size(166, 70);
     
    6569      //
    6670      this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem";
    67       this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     71      this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    6872      this.saveImageToolStripMenuItem.Text = "Save Image";
    6973      this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
    70       //
    71       // saveFileDialog
    72       //
    73       this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|EMF (*.emf)|*.emf";
    7474      //
    7575      // exportPgfLaTeXToolStripMenuItem
     
    7979      this.exportPgfLaTeXToolStripMenuItem.Text = "Export Pgf/LaTeX";
    8080      this.exportPgfLaTeXToolStripMenuItem.Click += new System.EventHandler(this.exportLatexToolStripMenuItem_Click);
     81      //
     82      // layoutEngineToolStripMenuItem
     83      //
     84      this.layoutEngineToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
     85            this.reingoldTilfordToolStripMenuItem,
     86            this.boxesToolStripMenuItem});
     87      this.layoutEngineToolStripMenuItem.Name = "layoutEngineToolStripMenuItem";
     88      this.layoutEngineToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
     89      this.layoutEngineToolStripMenuItem.Text = "Layout Engine:";
     90      //
     91      // reingoldTilfordToolStripMenuItem
     92      //
     93      this.reingoldTilfordToolStripMenuItem.Name = "reingoldTilfordToolStripMenuItem";
     94      this.reingoldTilfordToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
     95      this.reingoldTilfordToolStripMenuItem.Text = "Reingold-Tilford";
     96      this.reingoldTilfordToolStripMenuItem.Click += new System.EventHandler(this.reingoldTilfordToolStripMenuItem_Click);
     97      //
     98      // boxesToolStripMenuItem
     99      //
     100      this.boxesToolStripMenuItem.Name = "boxesToolStripMenuItem";
     101      this.boxesToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
     102      this.boxesToolStripMenuItem.Text = "Boxes";
     103      this.boxesToolStripMenuItem.Click += new System.EventHandler(this.boxesToolStripMenuItem_Click);
     104      //
     105      // saveFileDialog
     106      //
     107      this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|EMF (*.emf)|*.emf";
    81108      //
    82109      // SymbolicExpressionTreeChart
     
    103130    protected System.Windows.Forms.SaveFileDialog saveFileDialog;
    104131    private System.Windows.Forms.ToolStripMenuItem exportPgfLaTeXToolStripMenuItem;
     132    private System.Windows.Forms.ToolStripMenuItem layoutEngineToolStripMenuItem;
     133    private System.Windows.Forms.ToolStripMenuItem reingoldTilfordToolStripMenuItem;
     134    private System.Windows.Forms.ToolStripMenuItem boxesToolStripMenuItem;
    105135  }
    106136}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r10501 r10524  
    3333    private Image image;
    3434    private readonly StringFormat stringFormat;
    35     private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
    36     private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines;
    37     private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> layoutEngine;
    38     private readonly SymbolicExpressionTreeLayoutAdapter layoutAdapter;
     35    private Dictionary<ISymbolicExpressionTreeNode, VisualTreeNode<ISymbolicExpressionTreeNode>> visualTreeNodes;
     36    private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection> visualLines;
     37    private ILayoutEngine<ISymbolicExpressionTreeNode> layoutEngine;
    3938
    4039    private const int preferredNodeWidth = 70;
    4140    private const int preferredNodeHeight = 46;
    42     private const int minHorizontalDistance = 20;
    43     private const int minVerticalDistance = 20;
    44 
     41    private const int minHorizontalDistance = 30;
     42    private const int minVerticalDistance = 30;
    4543
    4644    public SymbolicExpressionTreeChart() {
     
    5250      this.backgroundColor = Color.White;
    5351      this.textFont = new Font(FontFamily.GenericSansSerif, 12);
    54       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();
    55       layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
     52      //      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
     53      layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
     54        NodeWidth = preferredNodeWidth,
     55        NodeHeight = preferredNodeHeight,
     56        HorizontalSpacing = minHorizontalDistance,
     57        VerticalSpacing = minVerticalDistance
     58      };
    5659    }
    5760
    5861    public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree)
    5962      : this() {
    60       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();
    61       layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
    6263      this.Tree = tree;
    6364    }
     
    105106      set {
    106107        tree = value;
    107         visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode>();
    108         visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection>();
    109108        if (tree != null) {
    110           IEnumerable<ISymbolicExpressionTreeNode> nodes;
    111           if (tree.Root.SubtreeCount == 1) nodes = tree.Root.GetSubtree(0).IterateNodesPrefix();
    112           else nodes = tree.Root.IterateNodesPrefix();
    113           foreach (ISymbolicExpressionTreeNode node in nodes) {
    114             visualTreeNodes[node] = new VisualSymbolicExpressionTreeNode(node);
    115             if (node.Parent != null) visualLines[Tuple.Create(node.Parent, node)] = new VisualSymbolicExpressionTreeNodeConnection();
    116           }
    117         }
    118         Repaint();
     109          Repaint();
     110        }
    119111      }
    120112    }
     
    160152    }
    161153
    162     public void RepaintNode(VisualSymbolicExpressionTreeNode visualNode) {
     154    public void RepaintNode(VisualTreeNode<ISymbolicExpressionTreeNode> visualNode) {
    163155      if (!suspendRepaint) {
    164156        using (var graphics = Graphics.FromImage(image)) {
     
    182174    }
    183175
    184     public VisualSymbolicExpressionTreeNode GetVisualSymbolicExpressionTreeNode(ISymbolicExpressionTreeNode symbolicExpressionTreeNode) {
     176    public VisualTreeNode<ISymbolicExpressionTreeNode> GetVisualSymbolicExpressionTreeNode(ISymbolicExpressionTreeNode symbolicExpressionTreeNode) {
    185177      if (visualTreeNodes.ContainsKey(symbolicExpressionTreeNode))
    186178        return visualTreeNodes[symbolicExpressionTreeNode];
     
    188180    }
    189181
    190     public VisualSymbolicExpressionTreeNodeConnection GetVisualSymbolicExpressionTreeNodeConnection(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {
     182    public VisualTreeNodeConnection GetVisualSymbolicExpressionTreeNodeConnection(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {
    191183      if (child.Parent != parent) throw new ArgumentException();
    192184      var key = Tuple.Create(parent, child);
    193       VisualSymbolicExpressionTreeNodeConnection connection = null;
     185      VisualTreeNodeConnection connection = null;
    194186      visualLines.TryGetValue(key, out connection);
    195187      return connection;
     
    205197
    206198    protected virtual void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
    207       VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
     199      var visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    208200      if (visualTreeNode != null) {
    209201        OnSymbolicExpressionTreeNodeClicked(visualTreeNode, e);
     
    219211
    220212    protected virtual void SymbolicExpressionTreeChart_MouseDoubleClick(object sender, MouseEventArgs e) {
    221       VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
     213      VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    222214      if (visualTreeNode != null)
    223215        OnSymbolicExpressionTreeNodeDoubleClicked(visualTreeNode, e);
     
    231223    }
    232224
    233     private VisualSymbolicExpressionTreeNode draggedSymbolicExpressionTree;
     225    private VisualTreeNode<ISymbolicExpressionTreeNode> draggedSymbolicExpressionTree;
    234226    private MouseButtons dragButtons;
    235227    private void SymbolicExpressionTreeChart_MouseDown(object sender, MouseEventArgs e) {
     
    243235
    244236    private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) {
    245       VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
     237      VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    246238      if (draggedSymbolicExpressionTree != null &&
    247239        draggedSymbolicExpressionTree != visualTreeNode) {
     
    258250    }
    259251
    260     public VisualSymbolicExpressionTreeNode FindVisualSymbolicExpressionTreeNodeAt(int x, int y) {
     252    public VisualTreeNode<ISymbolicExpressionTreeNode> FindVisualSymbolicExpressionTreeNodeAt(int x, int y) {
    261253      foreach (var visualTreeNode in visualTreeNodes.Values) {
    262254        if (x >= visualTreeNode.X && x <= visualTreeNode.X + visualTreeNode.Width &&
     
    269261
    270262    #region methods for painting the symbolic expression tree
    271     private void DrawFunctionTree(ISymbolicExpressionTree symbolicExpressionTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
    272       var layoutNodes = layoutAdapter.Convert(symbolicExpressionTree).ToList();
    273       if (symbolicExpressionTree.Root.SubtreeCount == 1) layoutNodes.RemoveAt(0);
    274       layoutEngine.Reset();
    275       layoutEngine.Root = layoutNodes[0];
    276       layoutEngine.AddNodes(layoutNodes);
    277       layoutEngine.MinHorizontalSpacing = (preferredWidth + minHDistance);
    278       layoutEngine.MinVerticalSpacing = (preferredHeight + minVDistance);
    279       layoutEngine.CalculateLayout();
    280       var bounds = layoutEngine.Bounds();
    281 
    282       double verticalScalingFactor = 1.0;
    283       double layoutHeight = (bounds.Height + preferredHeight);
    284       if (this.Height < layoutHeight)
    285         verticalScalingFactor = this.Height / layoutHeight;
    286 
    287       double horizontalScalingFactor = 1.0;
    288       double layoutWidth = (bounds.Width + preferredWidth);
    289       if (this.Width < layoutWidth)
    290         horizontalScalingFactor = this.Width / layoutWidth;
    291 
    292       double horizontalOffset;
    293       if (this.Width > layoutWidth)
    294         horizontalOffset = (this.Width - layoutWidth) / 2.0;
    295       else
    296         horizontalOffset = preferredWidth / 2.0;
    297 
    298       var levels = layoutNodes.GroupBy(n => n.Level, n => n).ToList();
    299       for (int i = levels.Count - 1; i >= 0; --i) {
    300         var nodes = levels[i].ToList();
    301 
    302         double minSpacing = double.MaxValue;
    303         if (nodes.Count > 1) {
    304           for (int j = 1; j < nodes.Count() - 1; ++j) {
    305             var distance = nodes[j].X - nodes[j - 1].X; // guaranteed to be > 0
    306             if (minSpacing > distance) minSpacing = distance;
    307           }
    308         }
    309         minSpacing *= horizontalScalingFactor;
    310 
    311         int minWidth = (int)Math.Round(preferredWidth * horizontalScalingFactor);
    312         int width = (int)Math.Min(minSpacing, preferredWidth) - 2; // leave some pixels so that node margins don't overlap
    313 
    314         foreach (var layoutNode in nodes) {
    315           var visualNode = visualTreeNodes[layoutNode.Content];
    316           visualNode.Width = width;
    317           visualNode.Height = (int)Math.Round(preferredHeight * verticalScalingFactor);
    318           visualNode.X = (int)Math.Round((layoutNode.X + horizontalOffset) * horizontalScalingFactor + (minWidth - width) / 2.0);
    319           visualNode.Y = (int)Math.Round(layoutNode.Y * verticalScalingFactor);
    320           DrawTreeNode(graphics, visualNode);
    321         }
    322       }
    323       // draw node connections
    324       foreach (var visualNode in visualTreeNodes.Values) {
    325         var node = visualNode.SymbolicExpressionTreeNode;
     263    private void DrawFunctionTree(ISymbolicExpressionTree symbExprTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
     264      var root = symbExprTree.Root;
     265      var actualRoot = root.SubtreeCount == 1 ? root.GetSubtree(0) : root;
     266      layoutEngine.NodeWidth = preferredWidth;
     267      layoutEngine.NodeHeight = preferredHeight;
     268      layoutEngine.HorizontalSpacing = minHDistance;
     269      layoutEngine.VerticalSpacing = minVDistance;
     270      layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth());
     271      layoutEngine.CalculateLayout(Width, Height);
     272
     273      var visualNodes = layoutEngine.GetVisualNodes().ToList();
     274      visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x);
     275      visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>();
     276      foreach (var node in visualNodes.Select(n => n.Content)) {
     277        foreach (var subtree in node.Subtrees) {
     278          visualLines.Add(new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree), new VisualTreeNodeConnection());
     279        }
     280      }
     281      // draw nodes and connections
     282      foreach (var visualNode in visualNodes) {
     283        DrawTreeNode(visualNode);
     284        var node = visualNode.Content;
    326285        foreach (var subtree in node.Subtrees) {
    327286          var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree);
     
    338297    }
    339298
    340     protected void DrawTreeNode(VisualSymbolicExpressionTreeNode visualTreeNode) {
     299    protected void DrawTreeNode(VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) {
    341300      using (var graphics = Graphics.FromImage(image)) {
    342301        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
     
    346305    }
    347306
    348     protected void DrawTreeNode(Graphics graphics, VisualSymbolicExpressionTreeNode visualTreeNode) {
     307    protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) {
    349308      graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
    350309      graphics.Clear(backgroundColor);
    351       var node = visualTreeNode.SymbolicExpressionTreeNode;
     310      var node = visualTreeNode.Content;
    352311      using (var textBrush = new SolidBrush(visualTreeNode.TextColor))
    353312      using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
     
    408367    }
    409368    #endregion
     369
     370    private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) {
     371      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
     372        NodeWidth = preferredNodeWidth,
     373        NodeHeight = preferredNodeHeight,
     374        HorizontalSpacing = minHorizontalDistance,
     375        VerticalSpacing = minVerticalDistance
     376      };
     377      Repaint();
     378    }
     379
     380    private void boxesToolStripMenuItem_Click(object sender, EventArgs e) {
     381      layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
     382        NodeWidth = preferredNodeWidth,
     383        NodeHeight = preferredNodeHeight,
     384        HorizontalSpacing = minHorizontalDistance,
     385        VerticalSpacing = minVerticalDistance
     386      };
     387      Repaint();
     388    }
    410389  }
    411390}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10517 r10524  
    2424using System.Linq;
    2525using HeuristicLab.Visualization;
    26 using HeuristicLab.Visualization.Primitives;
     26
     27using Rectangle = HeuristicLab.Visualization.Rectangle;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    4041
    4142    public ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> LayoutEngine { get; set; }
    42     public SymbolicExpressionTreeLayoutAdapter LayoutAdapter { get; set; }
    4343    public SymbolicExpressionTreeTile(IChart chart) : base(chart) { }
    4444    public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree)
     
    5050    private void GeneratePrimitives(double preferredNodeWidth, double preferredNodeHeight) {
    5151      Clear();
    52       var layoutNodes = LayoutAdapter.Convert(SymbolicExpressionTree).ToList();
    53       layoutNodes.RemoveAt(0);
    54       LayoutEngine.Root = layoutNodes[0];
     52      LayoutEngine.Initialize(SymbolicExpressionTree.Root, node => node.Subtrees);
    5553      LayoutEngine.CalculateLayout();
    5654
    57       var primitivesMap = new Dictionary<LayoutNode<ISymbolicExpressionTreeNode>, IPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase
     55      var primitivesMap = new Dictionary<ISymbolicExpressionTreeNode, IPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase
    5856      var font = new Font(FontFamily.GenericSansSerif, 10, GraphicsUnit.Pixel);
    5957
    60       foreach (var node in layoutNodes) {
    61         var lowerLeft = new PointD(node.X, node.Y);
    62         var upperRight = new PointD(node.X + preferredNodeWidth, node.Y + preferredNodeHeight);
     58      var visualNodes = LayoutEngine.GetVisualNodes().ToList();
     59      var visualNodeMap = visualNodes.ToDictionary(x => x.Content, x => x);
    6360
     61      foreach (var visualNode in visualNodes) {
     62        var lowerLeft = new PointD(visualNode.X, visualNode.Y);
     63        var upperRight = new PointD(visualNode.X + preferredNodeWidth, visualNode.Y + preferredNodeHeight);
     64        var node = visualNode.Content;
    6465        RectangularPrimitiveBase rectangularPrimitive;
    65         if (node.IsLeaf) {
    66           rectangularPrimitive = new LabeledRectangle(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };
     66        if (node.SubtreeCount == 0) {
     67          rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) { Font = font, Text = visualNode.Content.ToString() };
    6768        } else {
    68           rectangularPrimitive = new LabeledEllipse(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };
     69          rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) { Font = font, Text = visualNode.Content.ToString() };
    6970        }
    7071
     
    7374      }
    7475
    75       foreach (var node in layoutNodes.Where(n => n.Children != null)) {
    76         foreach (var child in node.Children) {
     76      foreach (var node in visualNodes.Where(n => n.Content.SubtreeCount > 0)) {
     77        var parent = node.Content;
     78        foreach (var child in parent.Subtrees.Select(x => visualNodeMap[x])) {
    7779          var start = new PointD(node.X + preferredNodeWidth / 2, node.Y + preferredNodeHeight);
    7880          var end = new PointD(child.X + preferredNodeWidth / 2, child.Y);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r10514 r10524  
    187187    <Compile Include="Formatters\SymbolicExpressionTreeGraphvizFormatter.cs" />
    188188    <Compile Include="Formatters\SymbolicExpressionTreeHierarchicalFormatter.cs" />
    189     <Compile Include="Formatters\SymbolicExpressionTreeLatexFormatter.cs" />
    190     <Compile Include="Interfaces\ILayoutAdapter.cs" />
    191189    <Compile Include="Interfaces\IReadOnlySymbol.cs" />
    192190    <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" />
     
    210208    <Compile Include="Interfaces\ISymbolicExpressionTreeStringFormatter.cs" />
    211209    <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeSizeConstraintOperator.cs" />
    212     <Compile Include="LayoutEngines\LayoutNode.cs" />
    213     <Compile Include="LayoutEngines\ReingoldTilfordLayoutEngine.cs" />
    214     <Compile Include="LayoutEngines\SymbolicExpressionTreeLayoutAdapter.cs" />
    215210    <Compile Include="Manipulators\ChangeNodeTypeManipulation.cs" />
    216211    <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeManipulator.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r10501 r10524  
    9797
    9898    private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
    99       var visualNode = (VisualSymbolicExpressionTreeNode)sender;
    100       var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.SymbolicExpressionTreeNode;
     99      var visualNode = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender;
     100      var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.Content;
    101101      if (symbExprTreeNode == null) return;
    102102      var tree = Content.Model.SymbolicExpressionTree;
     
    126126      double max = impacts.Max();
    127127      double min = impacts.Min();
    128       foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) {
    129         VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
     128      foreach (var treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) {
     129        VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
    130130
    131131        if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs

    r9456 r10524  
    3333  internal sealed partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart {
    3434    private ISymbolicExpressionTreeNode tempNode; // node in clipboard (to be cut/copy/pasted etc)
    35     private VisualSymbolicExpressionTreeNode currSelected; // currently selected node
     35    private VisualTreeNode<ISymbolicExpressionTreeNode> currSelected; // currently selected node
    3636    private enum EditOp { NoOp, CopySubtree, CutSubtree }
    3737    private EditOp lastOp = EditOp.NoOp;
     
    6565        pasteToolStripMenuItem.Visible = false;
    6666      } else {
    67         var node = currSelected.SymbolicExpressionTreeNode;
     67        var node = currSelected.Content;
    6868        insertNodeToolStripMenuItem.Visible = true;
    6969        changeNodeToolStripMenuItem.Visible = true;
     
    7777        pasteToolStripMenuItem.Enabled = tempNode != null && insertNodeToolStripMenuItem.Enabled
    7878                                                          && !(lastOp == EditOp.CutSubtree
    79                                                                && tempNode.IterateNodesBreadth().Contains(currSelected.SymbolicExpressionTreeNode));
     79                                                               && tempNode.IterateNodesBreadth().Contains(currSelected.Content));
    8080      }
    8181    }
    8282
    8383    protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    84       currSelected = (VisualSymbolicExpressionTreeNode)sender; ;
     84      currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; ;
    8585      if (currSelected != null) {
    8686        currSelected.LineColor = Color.FromArgb(130, currSelected.LineColor);
     
    104104
    105105    private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e) {
    106       if (currSelected == null || currSelected.SymbolicExpressionTreeNode is SymbolicExpressionTreeTerminalNode) return;
    107       var parent = currSelected.SymbolicExpressionTreeNode;
     106      if (currSelected == null || currSelected.Content is SymbolicExpressionTreeTerminalNode) return;
     107      var parent = currSelected.Content;
    108108
    109109      using (var dialog = new InsertNodeDialog()) {
     
    138138      if (currSelected == null) return;
    139139
    140       var node = (ISymbolicExpressionTreeNode)currSelected.SymbolicExpressionTreeNode.Clone();
    141       var originalNode = currSelected.SymbolicExpressionTreeNode;
     140      var node = (ISymbolicExpressionTreeNode)currSelected.Content.Clone();
     141      var originalNode = currSelected.Content;
    142142
    143143      ISymbolicExpressionTreeNode newNode = null;
     
    180180        }
    181181      }
    182       tempNode = currSelected.SymbolicExpressionTreeNode;
     182      tempNode = currSelected.Content;
    183183      foreach (var node in tempNode.IterateNodesPostfix()) {
    184184        var visualNode = GetVisualSymbolicExpressionTreeNode(node);
     
    194194    }
    195195    private void removeNodeToolStripMenuItem_Click(object sender, EventArgs e) {
    196       var node = currSelected.SymbolicExpressionTreeNode;
     196      var node = currSelected.Content;
    197197      if (node == tempNode) tempNode = null;
    198198      ModifyTree(Tree, node.Parent, node, null, removeSubtree: false);
     
    200200    }
    201201    private void removeSubtreeToolStripMenuItem_Click(object sender, EventArgs e) {
    202       var node = currSelected.SymbolicExpressionTreeNode;
     202      var node = currSelected.Content;
    203203      if (node.IterateNodesPostfix().Contains(tempNode)) tempNode = null;
    204204      ModifyTree(Tree, node.Parent, node, null, removeSubtree: true);
     
    209209      if (!(lastOp == EditOp.CopySubtree || lastOp == EditOp.CutSubtree)) return;
    210210      // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node
    211       var node = currSelected.SymbolicExpressionTreeNode;
     211      var node = currSelected.Content;
    212212      if (node is ConstantTreeNode || node is VariableTreeNode) return;
    213213      // check if the currently selected node can accept the copied node as a child
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerView.cs

    r10517 r10524  
    1515  public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView {
    1616    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionTreeNodeLayoutEngine;
    17     private readonly SymbolicExpressionTreeLayoutAdapter symbolicExpressionTreeLayoutAdapter;
    1817
    1918    private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap;
     
    3231      InitializeComponent();
    3332      symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
    34         MinHorizontalSpacing = MinHorizontalSpacing + PreferredNodeWidth,
    35         MinVerticalSpacing = MinVerticalSpacing + PreferredNodeHeight
     33        HorizontalSpacing = MinHorizontalSpacing,
     34        VerticalSpacing = MinVerticalSpacing,
     35        NodeWidth = PreferredNodeWidth,
     36        NodeHeight = PreferredNodeHeight
    3637      };
    37       symbolicExpressionTreeLayoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
    3838      treeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>();
    3939      double width = lineageExplorerChart.PreferredSize.Width;
     
    7474      var chart = lineageExplorerChart.Chart;
    7575      var tile = new SymbolicExpressionTreeTile(chart) {
    76         LayoutAdapter = symbolicExpressionTreeLayoutAdapter,
    7776        LayoutEngine = symbolicExpressionTreeNodeLayoutEngine,
    7877        PreferredNodeWidth = PreferredNodeWidth,
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TextualSymbolicDataAnalysisModelView.designer.cs

    r9456 r10524  
    4848      this.SuspendLayout();
    4949      //
    50       // expressionTreeView
     50      // symbolicExpressionTreeView
    5151      //
    5252      this.symbolicExpressionTreeView.AllowDrop = true;
     
    5454      this.symbolicExpressionTreeView.Content = null;
    5555      this.symbolicExpressionTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
     56      this.symbolicExpressionTreeView.Font = new System.Drawing.Font("Consolas", 8.25F);
    5657      this.symbolicExpressionTreeView.Location = new System.Drawing.Point(0, 0);
    57       this.symbolicExpressionTreeView.Name = "expressionTreeView";
     58      this.symbolicExpressionTreeView.Name = "symbolicExpressionTreeView";
    5859      this.symbolicExpressionTreeView.ReadOnly = false;
    5960      this.symbolicExpressionTreeView.Size = new System.Drawing.Size(352, 413);
    6061      this.symbolicExpressionTreeView.TabIndex = 0;
    6162      //
    62       // SymbolicExpressionModelView
     63      // TextualSymbolicDataAnalysisModelView
    6364      //
    6465      this.AllowDrop = true;
    65       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    6666      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    6767      this.Controls.Add(this.symbolicExpressionTreeView);
    68       this.Name = "SymbolicExpressionModelView";
     68      this.Name = "TextualSymbolicDataAnalysisModelView";
    6969      this.Size = new System.Drawing.Size(352, 413);
    7070      this.ResumeLayout(false);
Note: See TracChangeset for help on using the changeset viewer.