Changeset 12265 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking
- Timestamp:
- 03/29/15 23:40:57 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
r12231 r12265 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 84 84 nodeWeightLabel.Text = String.Format("{0:0.00}", graphNode.Weight); 85 85 86 if (!graphNode.InArcs.Any()) return; 87 86 88 if (openNew_CheckBox.Checked) { 87 89 // get the ancestors into a new view … … 96 98 } 97 99 98 if (graphNode.InArcs.Any()) { 99 var data = graphNode.InArcs.Last().Data; 100 var fragment = data as IFragment<ISymbolicExpressionTreeNode>; 101 var td = data as TraceData; 102 // double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 103 104 // calculate max only in the current generation 105 double max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 106 if (max.IsAlmost(0)) max = 1; 107 int c = ColorGradient.Colors.Count - 1; 108 const int alpha = 100; 109 if (fragment != null) { 110 // highlight the fragment with a blue line color 111 foreach (var n in graphNode.Data.NodeAt(fragment.Index1).IterateNodesPrefix()) { 112 treeChart_HighlightSubtree(n, Color.CornflowerBlue); 113 } 114 // highlight all the nodes according to their sample count 115 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 116 foreach (var n in nodes.Skip(1)) { 117 var i = (int)Math.Round(n.NodeWeight / max * c); 118 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 119 treeChart_HighlightSubtree(n, null, fillColor); 120 } 121 } else if (td != null) { 122 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 123 foreach (var n in nodes.Skip(1)) { // skip program root symbol 124 var i = (int)Math.Round(n.NodeWeight / max * c); 125 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 126 treeChart_HighlightSubtree(n, null, fillColor); 127 } 128 treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange); 129 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue); 130 } 131 } 132 } 100 var data = graphNode.InArcs.Last().Data; 101 var fragment = data as IFragment<ISymbolicExpressionTreeNode>; 102 var td = data as TraceData; 103 // calculate max only in the current generation 104 var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 105 // var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight); 106 107 if (max.IsAlmost(0)) 108 max = 1; 109 110 int colorCount = ColorGradient.Colors.Count - 1; 111 const int alpha = 100; 112 if (fragment != null) { 113 // highlight the fragment with a blue line color 114 foreach (var n in graphNode.Data.NodeAt(fragment.Index1).IterateNodesPrefix()) { 115 treeChart_HighlightSubtree(n, Color.CornflowerBlue); 116 } 117 // highlight all the nodes according to their sample count 118 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 119 foreach (var n in nodes.Skip(1)) { 120 var i = (int)Math.Round(n.NodeWeight / max * colorCount); 121 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 122 treeChart_HighlightSubtree(n, null, fillColor); 123 } 124 } else if (td != null) { 125 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 126 foreach (var n in nodes.Skip(1)) { // skip program root symbol 127 var i = (int)Math.Round(n.NodeWeight / max * colorCount); 128 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 129 treeChart_HighlightSubtree(n, null, fillColor); 130 } 131 treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange); 132 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue); 133 } 134 } 135 136 #region specific symbolic expression tree node click actions 137 private void OnTreeNodeLeftClicked(ISymbolicExpressionTreeNode node) { 138 SelectedSubtree = node; 139 bool trace = genealogyGraphChart.TraceFragments; 140 141 // check whether we are in 'trace' or 'match' mode 142 if (trace) { 143 // TODO: maybe highlight based on per generation maximum 144 // double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight)); 145 // perform fragment tracing 146 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 147 var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight); 148 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(node); 149 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true); 150 if (traceGraph.Vertices.Any()) { 151 var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)); 152 genealogyGraphChart.UpdateEnabled = false; 153 genealogyGraphChart.ClearPrimitives(); 154 foreach (var v in vertices) { 155 var vNode = genealogyGraphChart.GetMappedNode(v); 156 var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight); 157 // use a grayscale gradient 158 var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))]; 159 vNode.Brush = new SolidBrush(color); 160 } 161 genealogyGraphChart.UpdateEnabled = true; 162 genealogyGraphChart.EnforceUpdate(); 163 164 if (openNew_CheckBox.Checked) { 165 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen 166 } 167 } 168 } else { 169 // perform matching like it was done before 170 // currently there is no possibility to specify the subtree matching criteria 171 var trees = Content.Vertices.Select(x => x.Data); 172 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(node, comparer)); 173 174 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 175 graphChart_HighlightMatchingVertices(matchingVertices); 176 } 177 } 178 179 private void OnTreeNodeMiddleClicked(ISymbolicExpressionTreeNode node) { 180 var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(node); 181 if (index > 0) { 182 var s = ClonedSubtree.NodeAt(index); 183 s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s)); 184 185 var trees = Content.Vertices.Select(x => x.Data); 186 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer)); 187 188 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 189 treeChart_HighlightSubtree(node, Color.Black, Color.White); 190 graphChart_HighlightMatchingVertices(matchingVertices); 191 } 192 } 193 #endregion 133 194 134 195 public void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs args) { … … 139 200 treeChart_HighlightSubtree(subtree, Color.Black, Color.RoyalBlue); 140 201 141 bool trace = genealogyGraphChart.TraceFragments; // check whether we are in 'trace' or 'match' mode142 143 202 switch (args.Button) { 144 203 case MouseButtons.Left: { 145 SelectedSubtree = subtree; 146 if (trace) { 147 // TODO: maybe highlight based on per generation maximum 148 double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight)); 149 // perform fragment tracing 150 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 151 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree); 152 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true); 153 if (traceGraph.Vertices.Any()) { 154 var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)); 155 genealogyGraphChart.UpdateEnabled = false; 156 genealogyGraphChart.ClearPrimitives(); 157 foreach (var v in vertices) { 158 var vNode = genealogyGraphChart.GetMappedNode(v); 159 var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight); 160 // use a grayscal gradient 161 var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))]; 162 vNode.Brush = new SolidBrush(color); 163 } 164 genealogyGraphChart.UpdateEnabled = true; 165 genealogyGraphChart.EnforceUpdate(); 166 167 if (openNew_CheckBox.Checked) { 168 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen 169 } 170 } 171 } else { 172 // perform matching like it was done before 173 // currently there is no possibility to specify the subtree matching criteria 174 var trees = Content.Vertices.Select(x => x.Data); 175 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 176 177 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 178 graphChart_HighlightMatchingVertices(matchingVertices); 179 } 204 OnTreeNodeLeftClicked(subtree); 180 205 break; 181 206 } 182 207 case MouseButtons.Middle: { 183 var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(subtree); 184 if (index > 0) { 185 var s = ClonedSubtree.NodeAt(index); 186 s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s)); 187 188 var trees = Content.Vertices.Select(x => x.Data); 189 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer)); 190 191 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 192 treeChart_HighlightSubtree(subtree, Color.Black, Color.White); 193 graphChart_HighlightMatchingVertices(matchingVertices); 194 } 208 OnTreeNodeMiddleClicked(subtree); 195 209 break; 196 210 } … … 260 274 private void navigateRightButton_Click(object sender, EventArgs e) { 261 275 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 262 var inArcs = graphNode.InArcs.ToList();276 var inArcs = (List<IArc>)((IVertex)graphNode).InArcs; 263 277 if (inArcs.Count > 0) { 264 var data = inArcs.Last().Data; 265 var fragment = (data as IFragment<ISymbolicExpressionTreeNode>); 266 var td = data as TraceData; 278 if (inArcs.Count == 1) { 279 genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source; 280 return; 281 } 282 IGenealogyGraphNode<ISymbolicExpressionTree> source = null; 283 var fragment = ((IArc<IDeepCloneable>)inArcs.Last()).Data as IFragment<ISymbolicExpressionTreeNode>; 284 var traceData = ((IArc<IDeepCloneable>)inArcs[0]).Data as TraceData; 267 285 if (fragment != null) { 268 genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs.Last().Source; 269 } else if (td != null) { 270 if (inArcs.Count == 1) { 271 genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source; 272 return; 273 } 274 // the first arc from inArcs will always represent the connection to the root parent 275 // (tracing the body of the traced subtree) 276 // therefore, in order to follow the correct non-root parent, we have to find the correct arc 277 // But, the FragmentIndex recorded in the TraceData of the first arc has to match the SubtreeIndex recorded in the TraceData of the searched arc 278 td = (TraceData)inArcs[0].Data; 279 var f1 = (graphNode.Data).NodeAt(td.LastFragmentIndex); 280 for (int i = 1; i < inArcs.Count; ++i) { 281 td = (TraceData)inArcs[i].Data; 282 var f2 = ((IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source).Data.NodeAt(td.SubtreeIndex); 283 // if the subtrees are the same we have found a match 284 // note: this is not necessarily 100% correct if in the trace graph we have identical fragments on different arcs 285 if (f1.Difference(f2) == null) { 286 genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source; 287 return; 288 } 289 } 290 throw new InvalidOperationException("Error calculating the next step."); 291 } 286 source = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs.Last().Source; 287 } 288 if (traceData != null) { 289 var f = graphNode.Data.NodeAt(traceData.LastFragmentIndex); 290 var selected = inArcs.Skip(1).First(x => { 291 var td = (TraceData)((IArc<IDeepCloneable>)x).Data; 292 var s = (IGenealogyGraphNode<ISymbolicExpressionTree>)x.Source; 293 return f.Difference(s.Data.NodeAt(td.SubtreeIndex)) == null; 294 }); 295 source = (IGenealogyGraphNode<ISymbolicExpressionTree>)selected.Source; 296 } 297 if (source != null) 298 genealogyGraphChart.SelectedGraphNode = source; 292 299 } 293 300 }
Note: See TracChangeset
for help on using the changeset viewer.