Changeset 10685
- Timestamp:
- 03/31/14 17:24:36 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r10649 r10685 49 49 this.lineColor = Color.Black; 50 50 this.backgroundColor = Color.White; 51 this.textFont = new Font(FontFamily.GenericSansSerif, 1 2);51 this.textFont = new Font(FontFamily.GenericSansSerif, 10); 52 52 53 53 visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualTreeNode<ISymbolicExpressionTreeNode>>(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs
r10677 r10685 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; 24 25 using System.Linq; 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Visualization; 26 28 … … 35 37 public double PreferredNodeWidth { get; set; } 36 38 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 37 81 private ISymbolicExpressionTree symbolicExpressionTree; 38 82 public ISymbolicExpressionTree SymbolicExpressionTree { … … 63 107 : base(chart) { 64 108 primitiveMap = new Dictionary<IPrimitive, ISymbolicExpressionTreeNode>(); 65 109 PreferredNodeWidth = 80; 110 PreferredNodeHeight = 40; 66 111 Group = new Group(chart); 67 112 } 68 113 public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree) 69 114 : this(chart) { 70 PreferredNodeWidth = 80;71 PreferredNodeHeight = 40;72 115 SymbolicExpressionTree = tree; 73 116 } … … 95 138 primitiveMap.Add(rectangularPrimitive, node); // to be able to retrieve nodes via primitives 96 139 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 } 97 155 } 98 156 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10677 r10685 42 42 43 43 public new IEnumerable<IGenealogyGraphArc> InArcs { 44 get { 45 return base.InArcs.Cast<IGenealogyGraphArc>().ToList(); 46 } 44 get { return base.InArcs.Cast<IGenealogyGraphArc>().ToList(); } 47 45 set { base.InArcs = value; } 48 46 } 49 47 public new IEnumerable<IGenealogyGraphArc> OutArcs { 50 get { 51 return base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); 52 } 48 get { return base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); } 53 49 set { base.InArcs = value; } 54 50 } … … 111 107 return Quality.CompareTo(other.Quality); 112 108 } 113 114 109 public new void AddForwardArc(IVertex target, double w = 0.0, object data = null) { 115 110 var arc = new GenealogyGraphArc { Source = this, Target = (IGenealogyGraphNode)target, Data = data, Weight = w }; … … 120 115 base.AddReverseArc(arc); 121 116 } 122 123 117 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); } 127 119 } 128 129 120 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); } 131 122 } 132 123 } … … 147 138 return new GenealogyGraphNode<T>(this, cloner); 148 139 } 149 150 140 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); } 154 142 } 155 156 143 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); } 160 145 } 161 162 146 public new IEnumerable<IGenealogyGraphNode<T>> Ancestors { 163 147 get { return base.Ancestors.Select(x => (IGenealogyGraphNode<T>)x); } 164 148 } 165 166 149 public new IEnumerable<IGenealogyGraphNode<T>> Descendants { 167 150 get { return base.Descendants.Select(x => (IGenealogyGraphNode<T>)x); } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/FragmentGraphView.cs
r10677 r10685 1 1 using System.Collections.Generic; 2 using System.Drawing; 2 3 using System.Linq; 3 4 using HeuristicLab.Core.Views; … … 11 12 [Content(typeof(IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>), IsDefaultView = true)] 12 13 public sealed partial class FragmentGraphView : ItemView { 14 private int PreferredSpacing = 50; 15 13 16 private ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine; 14 17 private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine; … … 38 41 tile.LayoutEngine = symbolicExpressionEngine; 39 42 tile.Root = node.Content.Root; 40 var tileNode = new TileLayoutNode { 41 Tile = tile 42 }; 43 var tileNode = new TileLayoutNode { Tile = tile }; 43 44 tileDictionary.Add(node, tileNode); 44 45 } 45 46 47 46 foreach (var node in Content.Nodes.Where(n => n.Children.Any())) { 48 47 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])); 53 49 } 54 50 } … … 63 59 foreach (var visualNode in visualNodes) { 64 60 var tile = visualNode.Content.Tile; 61 tile.Position = new Point(visualNode.X, visualNode.Y); 65 62 symbolicExpressionChartControl.Add(tile); 66 63 } … … 104 101 internal class TileLayoutNode { 105 102 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 } 107 109 } 108 110 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymboldDataAnalysisGenealogyView.cs
r10677 r10685 34 34 35 35 using FragmentGraph = HeuristicLab.EvolutionTracking.IGenealogyGraph<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>; 36 37 36 using FragmentNode = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>; 38 37 … … 102 101 // perform fragment tracing 103 102 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 110 104 } else { 111 105 // perform matching like it was done before 112 106 // 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); 114 108 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 115 109 … … 167 161 168 162 #region fragment tracing 169 #region helper methods to shorten the code170 171 #endregion172 173 163 private FragmentGraph TraceSubtree(ISymbolicExpressionTreeNode subtree) { 174 164 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; … … 192 182 var fragmentLength = fragment.Root.GetLength(); 193 183 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 }; 195 185 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; 199 193 200 194 // if the selected subtree is the actual fragment … … 204 198 tree = graphNode.Content; 205 199 subtree = tree.NodeAt(fragment.OldIndex); 206 parentNode = node;207 200 continue; 208 201 } … … 215 208 var i = fragment.Root.IndexOf(subtree); // get the index of the selected subtree, relative to the fragment root 216 209 subtree = tree.NodeAt(fragment.OldIndex + i); 217 parentNode = node;218 210 continue; 219 211 } … … 226 218 subtree = tree.NodeAt(subtreeIndex); 227 219 // track subtree 228 Trace(graphNode, subtree, fragmentGraph, node);220 Trace(graphNode, subtree, fragmentGraph, fragmentNode); 229 221 230 222 // track fragment … … 233 225 tree = graphNode.Content; 234 226 subtree = tree.NodeAt(fragment.OldIndex); 235 parentNode = node;236 227 continue; 237 228 } … … 241 232 tree = graphNode.Content; 242 233 subtree = tree.NodeAt(subtreeIndex); 243 parentNode = node;244 234 continue; 245 235 } 246 236 break; 247 237 } 248 }249 250 private void AddChild(FragmentNode parent, FragmentNode child) {251 child.Rank = parent.Rank - 1;252 parent.AddForwardArc(child);253 child.AddReverseArc(parent);254 238 } 255 239 #endregion … … 262 246 return writer.ToString(); 263 247 } 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 } 264 255 internal static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) { 265 256 return NodeAt(tree.Root, position); … … 272 263 } 273 264 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 276 273 } 277 274 }
Note: See TracChangeset
for help on using the changeset viewer.