Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9996 for branches


Ignore:
Timestamp:
09/20/13 10:10:41 (11 years ago)
Author:
bburlacu
Message:

#1772: Removed unnecessary subproject (not included in solution). Merged changes from tree layout branch.

Location:
branches/HeuristicLab.EvolutionaryTracking
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r9963 r9996  
    3535    private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
    3636    private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines;
    37     private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { MinHorizontalSpacing = 5, MinVerticalSpacing = 5 };
    38     private readonly SymbolicExpressionTreeLayoutAdapter layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
     37    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> layoutEngine;
     38    private readonly SymbolicExpressionTreeLayoutAdapter layoutAdapter;
     39
     40    private const int preferredNodeWidth = 70;
     41    private const int preferredNodeHeight = 46;
     42    private const int minHorizontalDistance = 20;
     43    private const int minVerticalDistance = 20;
    3944
    4045
     
    4651      this.lineColor = Color.Black;
    4752      this.backgroundColor = Color.White;
    48       this.textFont = new Font("Times New Roman", 8);
     53      this.textFont = new Font("Times New Roman", 12);
     54      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();
     55      layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
    4956    }
    5057
    5158    public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree)
    5259      : this() {
     60      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();
     61      layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
    5362      this.Tree = tree;
    5463    }
     
    165174        graphics.Clear(backgroundColor);
    166175        if (tree != null) {
    167           DrawFunctionTree(tree, graphics, 70, 46, 20, 50);
     176          DrawFunctionTree(tree, graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
    168177        }
    169178      }
     
    258267    #region methods for painting the symbolic expression tree
    259268
    260     private void DrawFunctionTree(ISymbolicExpressionTree tree, Graphics graphics, int preferredWidth, int preferredHeight, int minDistance, int maxDistance) {
     269    private void DrawFunctionTree(ISymbolicExpressionTree tree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
    261270      var layoutNodes = layoutAdapter.Convert(tree).ToList();
    262271      layoutEngine.Reset();
     
    264273      foreach (var ln in layoutNodes)
    265274        layoutEngine.AddNode(ln.Content, ln);
     275      layoutEngine.MinHorizontalSpacing = (preferredNodeWidth + minHDistance);
     276      layoutEngine.MinVerticalSpacing = (preferredNodeHeight + minVDistance);
    266277      layoutEngine.CalculateLayout();
    267       var nodePositions = layoutEngine.GetNodeCoordinates();
    268278      var bounds = layoutEngine.Bounds();
    269 
    270       double sx = Width / bounds.Width;
    271       double sy = Height / bounds.Height;
    272 
    273       double dx = layoutEngine.MinHorizontalSpacing * sx; // scaled horizontal distance
    274       double dy = layoutEngine.MinVerticalSpacing * sy; // scaled vertical distance
    275 
    276       int maxWidth = (int)Math.Round(dx);
    277       int maxHeight = (int)Math.Round(dy);
    278 
    279       // instead of using the preferred with/height of each node inside the foreach loop below,
    280       // we assume the same width/height for all nodes
    281       int w = Math.Min(preferredWidth, maxWidth - minDistance / 2);
    282       int h = Math.Min(preferredHeight, maxHeight - minDistance / 2);
    283       // adjust scaling factor so that nodes will be at most maxDistance far from each other on the horizontal axis
    284       double offset = 0;
    285       if (maxDistance + w < maxWidth) {
    286         sx *= (double)(maxDistance + w) / maxWidth;
    287         offset = (Width - (sx * bounds.Width)) / 2;
    288       }
    289       foreach (var node in visualTreeNodes.Keys) {
    290         var visualNode = visualTreeNodes[node];
    291         var pos = nodePositions[node];
    292         visualNode.Width = w;
    293         visualNode.Height = h;
    294         visualNode.X = (int)Math.Round(pos.X * sx + offset); ;
    295         visualNode.Y = (int)Math.Round(pos.Y * sy);
    296         DrawTreeNode(graphics, visualNode);
    297       }
     279      double sx = this.Width / (bounds.Width + preferredWidth);
     280      if (sx > 1) sx = 1;
     281      double sy = this.Height / bounds.Height;
     282      if (sy > 1) sy = 1;
     283      double dx = (this.Width - bounds.Width) / 2;
     284      if (dx < 0) dx = 0;
     285      double dy = (this.Height - bounds.Height) / 2;
     286      if (dy < 0) dy = 0;
     287
     288      var levels = layoutNodes.GroupBy(n => n.Level, n => n);
     289
     290      foreach (var level in levels) {
     291        var nodes = level.ToList();
     292        double min = 0;
     293        for (int i = 0; i < nodes.Count - 1; ++i) {
     294          var w = (nodes[i + 1].X - nodes[i].X) * sx - preferredWidth;
     295          if (w < min) min = w;
     296        }
     297        if (min > 0) min = 0;
     298
     299        foreach (var layoutNode in level) {
     300          var visualNode = visualTreeNodes[layoutNode.Content];
     301          visualNode.Width = (int)Math.Round(preferredWidth + min) - 2; // -2 to allow enough padding (1px on each side) for the node contour to be drawn
     302          visualNode.Height = (int)Math.Round(preferredHeight * sy);
     303          visualNode.X = (int)(Math.Round(layoutNode.X * sx + dx));
     304          visualNode.Y = (int)(Math.Round(layoutNode.Y * sy + dy));
     305          DrawTreeNode(graphics, visualNode);
     306        }
     307      }
     308
    298309      graphics.ResetClip(); // reset clip region
     310      // draw node connections
    299311      foreach (var visualNode in visualTreeNodes.Values) {
    300312        var node = visualNode.SymbolicExpressionTreeNode;
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Fragment.cs

    r9835 r9996  
    5656      Length = original.Length;
    5757      Index = original.Index;
     58      OldIndex = original.OldIndex;
    5859    }
    5960
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/GeneticExchange.cs

    r9835 r9996  
    2828  [StorableClass]
    2929  public class GeneticExchange : Item {
    30     public IFragment FragmentIn { get; set; }
    31     public IFragment FragmentOut { get; set; }
     30    [Storable]
     31    private IFragment inFragment;
     32    public IFragment FragmentIn {
     33      get { return inFragment; }
     34      set { inFragment = value; }
     35    }
     36    [Storable]
     37    private IFragment outFragment;
     38    public IFragment FragmentOut {
     39      get { return outFragment; }
     40      set { outFragment = value; }
     41    }
    3242
    3343    [StorableConstructor]
    3444    private GeneticExchange(bool serializing) : base(serializing) { }
    35     private GeneticExchange(GeneticExchange original, Cloner cloner) : base(original, cloner) { }
     45
     46    private GeneticExchange(GeneticExchange original, Cloner cloner)
     47      : base(original, cloner) {
     48      inFragment = (IFragment)original.inFragment.Clone();
     49      outFragment = (IFragment)original.outFragment.Clone();
     50    }
    3651    public GeneticExchange() { }
    3752
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs

    r9963 r9996  
    4646        root = value;
    4747      }
    48     }
    49 
    50     /// <summary>
    51     /// Returns a string containing all the coordinates (useful for debugging).
    52     /// </summary>
    53     /// <returns></returns>
    54     public string DumpCoordinates() {
    55       if (nodes == null || nodes.Count == 0) return string.Empty;
    56       return nodes.Values.Aggregate("", (current, node) => current + (node.X + " " + node.Y + Environment.NewLine));
    5748    }
    5849
     
    161152
    162153    private void SecondWalk(ILayoutNode<T> v, float m) {
    163       if (!nodes.Values.Contains(v)) throw new Exception("Layout node not present in dictionary!");
    164154      v.X = v.Prelim + m;
    165155      v.Y = v.Level * minVerticalSpacing;
Note: See TracChangeset for help on using the changeset viewer.