Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 00:43:44 (10 years ago)
Author:
bburlacu
Message:

#1772:

  • TraceGraph: Improved saving of trace data, changed GetTraceNode method to AddTraceNode and made the code more clear.
  • SymbolicDataAnalysisGenealogyGraphView: added highlighting of trace information (when visualizing trace graphs)
  • GenealogyGraphChart: removed useless code
File:
1 edited

Legend:

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

    r11864 r11881  
    2626using System.Windows.Forms;
    2727using HeuristicLab.Common;
     28using HeuristicLab.Core;
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2930using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
     
    8182        // get the ancestors into a new view
    8283        var cloner = new Cloner();
    83 
     84        // clone arcs and vertices and use them to create a new graph
     85        // that will include just the individual and its ancestors
    8486        var graph = new GenealogyGraph<ISymbolicExpressionTree>();
    8587        var ancestors = new[] { graphNode }.Concat(graphNode.Ancestors);
     
    8991          graph.AddArc(cloner.Clone(arc));
    9092        }
    91         //        graph.AddVertices(graphNode.Ancestors);
    9293        MainFormManager.MainForm.ShowContent(graph);
    9394      }
    9495
    9596      if (graphNode.InArcs.Any()) {
    96         var fragment = graphNode.InArcs.Last().Data as IFragment<ISymbolicExpressionTreeNode>;
     97        var data = graphNode.InArcs.Last().Data;
     98        var fragment = data as IFragment<ISymbolicExpressionTreeNode>;
     99        var td = data as TraceData;
    97100        if (fragment != null) {
    98101          treeChart_HighlightSubtree(graphNode.Data.NodeAt(fragment.Index1));
    99         }
    100       }
    101       if (graphNode.OutArcs.Any()) {
    102         var td = graphNode.OutArcs.Last().Data as Tuple<int, int, int, int>;
    103         if (td != null) {
    104           var s = graphNode.Data.NodeAt(td.Item3); // subtree index
    105           var f = graphNode.Data.NodeAt(td.Item4); // fragment index
    106           treeChart_HighlightSubtree(s, Color.Orange);
    107           treeChart_HighlightSubtree(f, Color.RoyalBlue);
     102        } else if (td != null) {
     103          var nodes = graphNode.Data.IterateNodesPrefix().ToList();
     104          treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange);
     105          treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.DodgerBlue);
    108106        }
    109107      }
     
    127125          genealogyGraphChart.UpdateEnabled = false;
    128126          genealogyGraphChart.ClearArcs();
    129           //          genealogyGraphChart.ClearPrimitives();
    130127          var genealogyNodes = traceGraph.Vertices.Select(v => Content.GetByContent(v.Data));
    131           //          genealogyGraphChart.HighlightNodes(graphNode.Ancestors, Color.Gray, false);
    132128          genealogyGraphChart.HighlightNodes(genealogyNodes, Color.Black, false);
    133           //          foreach (var a in traceGraph.Arcs) {
    134           //            genealogyGraphChart.HighlightArc(Content.GetByContent(a.Target.Data), Content.GetByContent(a.Source.Data));
    135           //          }
    136129          genealogyGraphChart.UpdateEnabled = true;
    137130          genealogyGraphChart.EnforceUpdate();
     
    184177    private void navigateLeftButton_Click(object sender, EventArgs e) {
    185178      var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
    186       if (graphNode.Parents.Any()) {
    187         genealogyGraphChart.SelectedGraphNode = graphNode.Parents.First();
     179      var inArcs = (List<IArc>)((IVertex)graphNode).InArcs;
     180      if (inArcs.Count > 0) {
     181        genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
    188182      }
    189183    }
     
    191185    private void navigateRightButton_Click(object sender, EventArgs e) {
    192186      var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
    193       if (graphNode.Parents.Any()) {
    194         genealogyGraphChart.SelectedGraphNode = graphNode.Parents.Last(); // this will only work for genealogy graphs (not trace graphs)
     187      var inArcs = (List<IArc>)((IVertex)graphNode).InArcs;
     188      if (inArcs.Count > 0) {
     189        var data = inArcs.Last().Data;
     190        var fragment = (data as IFragment<ISymbolicExpressionTreeNode>);
     191        var td = data as TraceData;
     192        if (fragment != null) {
     193          genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs.Last().Source;
     194        } else if (td != null) {
     195          if (inArcs.Count == 1) {
     196            genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
     197            return;
     198          }
     199          // the first arc from inArcs will always represent the connection to the root parent
     200          // (tracing the body of the traced subtree)
     201          // therefore, in order to follow the correct non-root parent, we have to find the correct arc
     202          // But, the FragmentIndex recorded in the TraceData of the first arc has to match the SubtreeIndex recorded in the TraceData of the searched arc
     203          td = (TraceData)inArcs[0].Data;
     204          var f1 = (graphNode.Data).NodeAt(td.LastFragmentIndex);
     205          for (int i = 1; i < inArcs.Count; ++i) {
     206            td = (TraceData)inArcs[i].Data;
     207            var f2 = ((ISymbolicExpressionTree)inArcs[i].Source.Data).NodeAt(td.SubtreeIndex);
     208            // if the subtrees are the same we have found a match
     209            // note: this is not necessarily 100% correct if in the trace graph we have identical fragments on different arcs
     210            if (f1.Difference(f2) == null) {
     211              genealogyGraphChart.SelectedGraphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source;
     212              return;
     213            }
     214          }
     215          throw new InvalidOperationException("Error calculating the next step.");
     216        }
    195217      }
    196218    }
Note: See TracChangeset for help on using the changeset viewer.