Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10685


Ignore:
Timestamp:
03/31/14 17:24:36 (11 years ago)
Author:
bburlacu
Message:

#1772: Tracking building blocks: worked on tracking logic and on the FragmentView.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
5 edited

Legend:

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

    r10649 r10685  
    4949      this.lineColor = Color.Black;
    5050      this.backgroundColor = Color.White;
    51       this.textFont = new Font(FontFamily.GenericSansSerif, 12);
     51      this.textFont = new Font(FontFamily.GenericSansSerif, 10);
    5252
    5353      visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualTreeNode<ISymbolicExpressionTreeNode>>();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10677 r10685  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.Linq;
     26using HeuristicLab.Common;
    2527using HeuristicLab.Visualization;
    2628
     
    3537    public double PreferredNodeWidth { get; set; }
    3638    public double PreferredNodeHeight { get; set; }
     39
     40    public Size Size {
     41      get {
     42        int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
     43
     44        foreach (var p in Primitives.OfType<RectangularPrimitiveBase>()) {
     45          if (xmin > p.LowerLeft.X) xmin = (int)Math.Floor(p.LowerLeft.X);
     46          if (xmax < p.UpperRight.X) xmax = (int)Math.Ceiling(p.UpperRight.X);
     47          if (ymin > p.LowerLeft.Y) ymin = (int)Math.Floor(p.LowerLeft.Y);
     48          if (ymax < p.UpperRight.Y) ymax = (int)Math.Ceiling(p.UpperRight.Y);
     49        }
     50
     51        return new Size(xmax - xmin, ymax - ymin);
     52      }
     53    }
     54
     55    private Point position;
     56    public Point Position {
     57      get { return position; }
     58      set {
     59        var oldpos = position;
     60        position = value;
     61        int ox = position.X - oldpos.X;
     62        int oy = position.Y - oldpos.Y;
     63        // translate all primitives to the new position
     64        foreach (var p in Primitives) {
     65          var rpb = p as RectangularPrimitiveBase;
     66          if (rpb != null) {
     67            var lowerLeft = new Point((int)Math.Floor(rpb.LowerLeft.X) + ox, (int)Math.Floor(rpb.LowerLeft.Y + oy));
     68            var upperRight = new PointD(lowerLeft.X + rpb.Size.Width, lowerLeft.Y + rpb.Size.Height);
     69            rpb.SetPosition(lowerLeft, upperRight);
     70          }
     71          var line = p as LinearPrimitiveBase;
     72          if (line != null) {
     73            var start = new Point((int)Math.Floor(line.Start.X) + ox, (int)Math.Floor(line.Start.Y) + oy);
     74            var end = new Point(start.X + (int)line.Size.Width, start.Y + (int)line.Size.Height);
     75            line.SetPosition(start, end);
     76          }
     77        }
     78      }
     79    }
     80
    3781    private ISymbolicExpressionTree symbolicExpressionTree;
    3882    public ISymbolicExpressionTree SymbolicExpressionTree {
     
    63107      : base(chart) {
    64108      primitiveMap = new Dictionary<IPrimitive, ISymbolicExpressionTreeNode>();
    65 
     109      PreferredNodeWidth = 80;
     110      PreferredNodeHeight = 40;
    66111      Group = new Group(chart);
    67112    }
    68113    public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree)
    69114      : this(chart) {
    70       PreferredNodeWidth = 80;
    71       PreferredNodeHeight = 40;
    72115      SymbolicExpressionTree = tree;
    73116    }
     
    95138        primitiveMap.Add(rectangularPrimitive, node); // to be able to retrieve nodes via primitives
    96139        this.Add(rectangularPrimitive);
     140
     141        //        int x = Position.X, y = Position.Y;
     142        //        if (x > rectangularPrimitive.LowerLeft.X) {
     143        //          x = (int)Math.Floor(rectangularPrimitive.LowerLeft.X);
     144        //        }
     145        //        if (y > rectangularPrimitive.LowerLeft.Y) {
     146        //          y = (int)Math.Floor(rectangularPrimitive.LowerLeft.Y);
     147        //        }
     148        //        Position = new Point(x, y);
     149        //        int w = Size.Width, h = Size.Height;
     150
     151
     152        if (rectangularPrimitive.Size.Width.IsAlmost(0) || rectangularPrimitive.Size.Height.IsAlmost(0)) {
     153          throw new Exception("Primitive size cannot be zero.");
     154        }
    97155      }
    98156
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs

    r10677 r10685  
    4242
    4343    public new IEnumerable<IGenealogyGraphArc> InArcs {
    44       get {
    45         return base.InArcs.Cast<IGenealogyGraphArc>().ToList();
    46       }
     44      get { return base.InArcs.Cast<IGenealogyGraphArc>().ToList(); }
    4745      set { base.InArcs = value; }
    4846    }
    4947    public new IEnumerable<IGenealogyGraphArc> OutArcs {
    50       get {
    51         return base.OutArcs.Cast<IGenealogyGraphArc>().ToList();
    52       }
     48      get { return base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); }
    5349      set { base.InArcs = value; }
    5450    }
     
    111107      return Quality.CompareTo(other.Quality);
    112108    }
    113 
    114109    public new void AddForwardArc(IVertex target, double w = 0.0, object data = null) {
    115110      var arc = new GenealogyGraphArc { Source = this, Target = (IGenealogyGraphNode)target, Data = data, Weight = w };
     
    120115      base.AddReverseArc(arc);
    121116    }
    122 
    123117    public IEnumerable<IGenealogyGraphNode> Parents {
    124       get {
    125         return InArcs == null ? Enumerable.Empty<IGenealogyGraphNode>() : InArcs.Select(a => a.Source);
    126       }
     118      get { return InArcs.Select(a => a.Source); }
    127119    }
    128 
    129120    public IEnumerable<IGenealogyGraphNode> Children {
    130       get { return OutArcs == null ? Enumerable.Empty<IGenealogyGraphNode>() : OutArcs.Select(a => a.Source); }
     121      get { return OutArcs.Select(a => a.Target); }
    131122    }
    132123  }
     
    147138      return new GenealogyGraphNode<T>(this, cloner);
    148139    }
    149 
    150140    public new IEnumerable<IGenealogyGraphNode<T>> Parents {
    151       get {
    152         return base.Parents.Select(p => (IGenealogyGraphNode<T>)p);
    153       }
     141      get { return base.Parents.Select(p => (IGenealogyGraphNode<T>)p); }
    154142    }
    155 
    156143    public new IEnumerable<IGenealogyGraphNode<T>> Children {
    157       get {
    158         return base.Children.Select(c => (IGenealogyGraphNode<T>)c);
    159       }
     144      get { return base.Children.Select(c => (IGenealogyGraphNode<T>)c); }
    160145    }
    161 
    162146    public new IEnumerable<IGenealogyGraphNode<T>> Ancestors {
    163147      get { return base.Ancestors.Select(x => (IGenealogyGraphNode<T>)x); }
    164148    }
    165 
    166149    public new IEnumerable<IGenealogyGraphNode<T>> Descendants {
    167150      get { return base.Descendants.Select(x => (IGenealogyGraphNode<T>)x); }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/FragmentGraphView.cs

    r10677 r10685  
    11using System.Collections.Generic;
     2using System.Drawing;
    23using System.Linq;
    34using HeuristicLab.Core.Views;
     
    1112  [Content(typeof(IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>), IsDefaultView = true)]
    1213  public sealed partial class FragmentGraphView : ItemView {
     14    private int PreferredSpacing = 50;
     15
    1316    private ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine;
    1417    private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine;
     
    3841        tile.LayoutEngine = symbolicExpressionEngine;
    3942        tile.Root = node.Content.Root;
    40         var tileNode = new TileLayoutNode {
    41           Tile = tile
    42         };
     43        var tileNode = new TileLayoutNode { Tile = tile };
    4344        tileDictionary.Add(node, tileNode);
    4445      }
    45 
    46 
    4746      foreach (var node in Content.Nodes.Where(n => n.Children.Any())) {
    4847        var layoutNode = tileDictionary[node];
    49         layoutNode.Children = new List<TileLayoutNode>();
    50         foreach (var child in node.Children) {
    51           layoutNode.Children.Add(tileDictionary[child]);
    52         }
     48        layoutNode.Children = new List<TileLayoutNode>(node.Children.Select(x => tileDictionary[x]));
    5349      }
    5450    }
     
    6359      foreach (var visualNode in visualNodes) {
    6460        var tile = visualNode.Content.Tile;
     61        tile.Position = new Point(visualNode.X, visualNode.Y);
    6562        symbolicExpressionChartControl.Add(tile);
    6663      }
     
    104101  internal class TileLayoutNode {
    105102    public SymbolicExpressionTreeTile Tile { get; set; }
    106     public List<TileLayoutNode> Children { get; set; }
     103
     104    private List<TileLayoutNode> children;
     105    public IEnumerable<TileLayoutNode> Children {
     106      get { return children ?? Enumerable.Empty<TileLayoutNode>(); }
     107      set { children = value.ToList(); }
     108    }
    107109  }
    108110}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymboldDataAnalysisGenealogyView.cs

    r10677 r10685  
    3434
    3535using FragmentGraph = HeuristicLab.EvolutionTracking.IGenealogyGraph<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;
    36 
    3736using FragmentNode = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;
    3837
     
    102101        // perform fragment tracing
    103102        var fragmentGraph = TraceSubtree(subtree);
    104         MainFormManager.MainForm.ShowContent(fragmentGraph);
    105         //        var fragmentGraphView = MainFormManager.MainForm.ShowContent(fragmentGraph);
    106         //        fragmentGraphView.Content = fragmentGraph;
    107         //        fragmentGraphView.Show();
    108 
    109         // open a FragmentGraphView displaying this fragmentGraph
     103        MainFormManager.MainForm.ShowContent(fragmentGraph); // display the fragment graph on the screen
    110104      } else {
    111105        // perform matching like it was done before
    112106        // currently there is no possibility to specify the subtree matching criteria
    113         var trees = Content.Nodes.Select(x => (ISymbolicExpressionTree)x.Content);
     107        var trees = Content.Nodes.Select(x => x.Content);
    114108        var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
    115109
     
    167161
    168162    #region fragment tracing
    169     #region helper methods to shorten the code
    170 
    171     #endregion
    172 
    173163    private FragmentGraph TraceSubtree(ISymbolicExpressionTreeNode subtree) {
    174164      var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
     
    192182        var fragmentLength = fragment.Root.GetLength();
    193183
    194         FragmentNode node = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank };
     184        var fragmentNode = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank };
    195185        if (parentNode != null) {
    196           AddChild(parentNode, node);
    197         }
    198         fragmentGraph.AddVertex(node);
     186          if (parentNode == fragmentNode)
     187            throw new Exception("Node cannot be a child of itself!");
     188          var arc = new GenealogyGraphArc { Source = parentNode, Target = fragmentNode };
     189          parentNode.AddForwardArc(arc);
     190        }
     191        fragmentGraph.AddVertex(fragmentNode);
     192        parentNode = fragmentNode;
    199193
    200194        // if the selected subtree is the actual fragment
     
    204198          tree = graphNode.Content;
    205199          subtree = tree.NodeAt(fragment.OldIndex);
    206           parentNode = node;
    207200          continue;
    208201        }
     
    215208          var i = fragment.Root.IndexOf(subtree); // get the index of the selected subtree, relative to the fragment root
    216209          subtree = tree.NodeAt(fragment.OldIndex + i);
    217           parentNode = node;
    218210          continue;
    219211        }
     
    226218          subtree = tree.NodeAt(subtreeIndex);
    227219          // track subtree
    228           Trace(graphNode, subtree, fragmentGraph, node);
     220          Trace(graphNode, subtree, fragmentGraph, fragmentNode);
    229221
    230222          // track fragment
     
    233225            tree = graphNode.Content;
    234226            subtree = tree.NodeAt(fragment.OldIndex);
    235             parentNode = node;
    236227            continue;
    237228          }
     
    241232          tree = graphNode.Content;
    242233          subtree = tree.NodeAt(subtreeIndex);
    243           parentNode = node;
    244234          continue;
    245235        }
    246236        break;
    247237      }
    248     }
    249 
    250     private void AddChild(FragmentNode parent, FragmentNode child) {
    251       child.Rank = parent.Rank - 1;
    252       parent.AddForwardArc(child);
    253       child.AddReverseArc(parent);
    254238    }
    255239    #endregion
     
    262246      return writer.ToString();
    263247    }
     248    #region some helper methods for shortening the tracing code
     249
     250    internal static void AddChild(this IGenealogyGraphNode parent, IGenealogyGraphNode child) {
     251      parent.AddForwardArc(child);
     252      child.AddReverseArc(parent);
     253      child.Rank = parent.Rank - 1;
     254    }
    264255    internal static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) {
    265256      return NodeAt(tree.Root, position);
     
    272263    }
    273264    internal static int IndexOf(this ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node) {
    274       return root.IterateNodesPrefix().ToList().IndexOf(node); // not too worried about efficiency here
    275     }
     265      int i = 0;
     266      foreach (var n in root.IterateNodesPrefix()) {
     267        if (n == node) return i;
     268        ++i;
     269      }
     270      return -1;
     271    }
     272    #endregion
    276273  }
    277274}
Note: See TracChangeset for help on using the changeset viewer.