Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/20/15 18:20:59 (8 years ago)
Author:
bburlacu
Message:

#1772: Changed the way node highlighting is performed (taking into account sampling count relative to current generation). Made NodeWeight field storable in the SymbolicExpressionTreeNode. Updated the statistics counting in the TraceCalculator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs

    r12225 r12231  
    100100        var fragment = data as IFragment<ISymbolicExpressionTreeNode>;
    101101        var td = data as TraceData;
    102         //        double max = Content.Vertices.SelectMany(x => x.Data.IterateNodesPrefix()).Max(x => x.NodeWeight);
    103 
     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;
    104109        if (fragment != null) {
    105           //          treeChart_HighlightSubtree(graphNode.Data.NodeAt(fragment.Index1));
     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
    106115          var nodes = graphNode.Data.IterateNodesPrefix().ToList();
    107           int c = ColorGradient.Colors.Count - 1;
     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();
    108123          foreach (var n in nodes.Skip(1)) { // skip program root symbol
    109             //            var i = (int)Math.Round(n.NodeWeight / max * c);
    110             //            const int alpha = 50;
    111             //            var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
    112 
    113             //            treeChart_HighlightSubtree(n, null, fillColor);
    114           }
    115         } else if (td != null) {
    116 
    117           var nodes = graphNode.Data.IterateNodesPrefix().ToList();
    118           int c = ColorGradient.Colors.Count - 1;
    119           foreach (var n in nodes.Skip(1)) { // skip program root symbol
    120             //            var i = (int)Math.Round(n.NodeWeight / max * c);
    121             //            const int alpha = 50;
    122             //            var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
    123 
    124             //            treeChart_HighlightSubtree(n, null, fillColor);
    125           }
    126 
     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          }
    127128          treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange);
    128129          treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue);
     
    141142
    142143      switch (args.Button) {
    143         case MouseButtons.Left:
    144           SelectedSubtree = subtree;
    145           if (trace) {
    146             // perform fragment tracing
    147             var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
    148             var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree);
    149             var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: true, updateSubtreeWeights: true, cacheTraceNodes: true);
    150             if (traceGraph.Vertices.Any()) {
    151               genealogyGraphChart.UpdateEnabled = false;
    152               genealogyGraphChart.ClearPrimitives();
    153               var traceVertices = traceGraph.Vertices.ToList();
    154               var genealogyNodes = traceVertices.Select(v => Content.GetByContent(v.Data)).ToList();
    155               // color graph vertices according to their weight
    156               double max = traceGraph.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(n => x.Weight));
    157               for (int i = 0; i < genealogyNodes.Count; ++i) {
    158                 var g = genealogyNodes[i];
    159                 g.Weight = traceVertices[i].Weight;
    160                 var v = genealogyGraphChart.GetMappedNode(g);
    161                 if (v != null) {
    162                   v.Brush = new SolidBrush(ColorGradient.Colors[(int)Math.Round(g.Weight * (ColorGradient.Colors.Count - 1) / max)]);
     144        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
    163169                }
    164170              }
    165 
    166               genealogyGraphChart.UpdateEnabled = true;
    167               genealogyGraphChart.EnforceUpdate();
    168 
    169               if (openNew_CheckBox.Checked)
    170                 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen
     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);
    171179            }
    172           } else {
    173             // perform matching like it was done before
    174             // currently there is no possibility to specify the subtree matching criteria
    175             var trees = Content.Vertices.Select(x => x.Data);
    176             var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
    177 
    178             var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x));
    179             graphChart_HighlightMatchingVertices(matchingVertices);
    180           }
    181           break;
    182         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           }
    195           break;
     180            break;
     181          }
     182        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            }
     195            break;
     196          }
    196197      }
    197198    }
Note: See TracChangeset for help on using the changeset viewer.