Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11881 for branches


Ignore:
Timestamp:
02/04/15 00:43:44 (9 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
Location:
branches/HeuristicLab.EvolutionTracking
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs

    r11864 r11881  
    4343    private Dictionary<Tuple<VisualGenealogyGraphNode, VisualGenealogyGraphNode>, VisualGenealogyGraphArc> arcMap;
    4444
     45    #region chart modes
     46    public bool SimpleLineages { get; set; }
     47    public bool LockGenealogy { get; set; }
     48    public bool TraceFragments { get; set; }
     49    #endregion
     50
     51    private bool DrawInProgress { get; set; } // do not try to update the chart while the drawing is not finished
     52
    4553    public IGenealogyGraph GenealogyGraph {
    4654      get { return genealogyGraph; }
     
    7987    }
    8088
    81     #region chart modes
    82     public bool SimpleLineages { get; set; }
    83     public bool LockGenealogy { get; set; }
    84     public bool TraceFragments { get; set; }
    85     #endregion
    86 
    8789    private Visualization.Rectangle TargetRectangle { get; set; }
    88     private bool DrawInProgress { get; set; } // do not try to update the chart while the drawing is not finished
    8990    protected VisualGenealogyGraphNode SelectedVisualNode { get; set; }
    9091
     
    163164        }
    164165      }
    165       // TODO: connect elites
    166166
    167167      Chart.UpdateEnabled = true;
     
    200200      base.pictureBox_MouseMove(sender, e);
    201201    }
     202
    202203    protected override void pictureBox_MouseUp(object sender, MouseEventArgs e) {
    203204      Cursor = Cursors.Default;
     
    252253    #endregion
    253254
     255    #region drawing routines
    254256    private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector) {
    255257      var brush = (SolidBrush)node.Brush;
     
    269271    }
    270272
    271     public void HighlightHotPaths() {
    272       Chart.UpdateEnabled = false;
    273       ClearPrimitives();
    274       var arcs = GenealogyGraph.Vertices.SelectMany(n => n.InArcs).ToList();
    275       foreach (var arc in arcs) { arc.Weight = 1.0; } // reset weights
    276       var rank = GenealogyGraph.Ranks.Max(x => x.Key);
    277       foreach (var graphNode in GenealogyGraph.GetByRank(rank)) {
    278         foreach (var ancestor in graphNode.Ancestors) {
    279           foreach (var arc in ancestor.InArcs) {
    280             arc.Weight++;
    281           }
    282         }
    283       }
    284       double max = arcs.Max(a => a.Weight);
    285       double min = arcs.Min(a => a.Weight);
    286 
    287       if (min.IsAlmost(max)) return;
    288       //translate interval (min,max) to interval (0,255)
    289       foreach (var arc in arcs) {
    290         var vArc = GetMappedArc(arc.Source, arc.Target);
    291         int colorIndex = (int)Math.Round((arc.Weight - min) * 255 / (max - min));
    292         if (colorIndex > 254) colorIndex = 254;
    293         vArc.Pen = new Pen(ColorGradient.Colors[colorIndex]);
    294         //        vArc.Pen.Brush = new SolidBrush(ColorGradient.Colors[colorIndex]);
    295       }
    296       Chart.UpdateEnabled = true;
    297       Chart.EnforceUpdate();
    298     }
    299 
    300273    void MarkSelectedNode() {
    301274      var center = SelectedVisualNode.Center;
     
    342315          primitive.Brush = new SolidBrush(Color.Transparent);
    343316          primitive.Pen = new Pen(Color.DarkGray);
    344           //          primitive.Pen = Pens.Transparent; // remove the node contour
    345317        }
    346318      }
     
    387359      arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
    388360    }
     361    #endregion
    389362  }
    390363
  • 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    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r11866 r11881  
    5858      tc.Trace(node, subtreeIndex);
    5959      return tc.TraceGraph;
    60     }
    61 
    62     public IGenealogyGraph<ISymbolicExpressionTree> PartialTrace(IGenealogyGraphNode<ISymbolicExpressionTree> node,
    63       int subtreeIndex, ISymbolicExpressionTreeNode subtree) {
    64       traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();
    65       traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();
    66       return null;
    6760    }
    6861
     
    9790    private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) {
    9891      var g = node;
    99       int si = subtreeIndex;
     92      int si = subtreeIndex; // subtree index
     93      int fi = 0; // fragment index
    10094      while (g.Parents.Any()) {
    10195        Debug.Assert(si < g.Data.Length);
     
    109103        }
    110104
    111         int fi = fragment.Index1;               // fragment index
     105        fi = fragment.Index1;               // fragment index
    112106        int fl = fragment.Root.GetLength();     // fragment length
    113107        int sl = NodeAt(g.Data, si).GetLength(); // subtree length
     
    137131            if (fi < si + sl) {
    138132              // subtree contains fragment => branching point in the fragment graph
    139               var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
     133              var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
    140134              TraceRecursive(parent0, si, n);
    141135              TraceRecursive(parent1, fragment.Index2, n);
     
    157151          // check if the subtree and the fragment overlap => branch out
    158152          if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) {
    159             var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
     153            var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent
    160154            int i = si < fi ? si : fi;
    161155            TraceRecursive(parent0, i, n);
     
    173167      }
    174168      // when we are out of the while the last vertex must be connected with the current one
    175       ConnectLast(g, si, last);
     169      // if there is no last vertex, it means the tracing reached the top of the genealogy graph
     170      var current = AddTraceNode(g, si, fi);
     171      if (last != null)
     172        ConnectLast(current, last, si, fi);
    176173    }
    177174
     
    184181    /// <param name="fi">The fragment index</param>
    185182    /// <returns></returns>
    186     private IGenealogyGraphNode<ISymbolicExpressionTree> GetTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) {
     183    private IGenealogyGraphNode<ISymbolicExpressionTree> AddTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) {
    187184      var n = traceGraph.GetByContent(g.Data);
    188185      if (n == null) {
     
    211208    /// of the genealogy graph node @g. 
    212209    /// </summary>
    213     /// <param name="g">The current node in the genealogy graph</param>
     210    /// <param name="current">The current node in the genealogy graph</param>
     211    /// <param name="last">The last added node in the trace graph</param>   
    214212    /// <param name="si">The index of the traced subtree</param>
    215     /// <param name="last">The last added node in the trace graph</param>
    216     private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last) {
    217       var inArcs = (List<IArc>)((IVertex)g).InArcs;
    218       var fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data : null;
    219       int fi = fragment == null ? 0 : fragment.Index1; // fragment index
    220       var n = GetTraceNode(g, si, fi); // will append n to the trace graph if it does not exist
    221       if (last == null)
    222         return;
     213    /// <param name="fi">The index of the fragment</param>
     214    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) {
    223215      var lastTraceData = traceMap[last];
    224216      int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node)
    225217      int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node)
    226218      var td = new TraceData(si, fi, lastSi, lastFi); // trace data
    227       var arc = n.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td));
     219      var arc = current.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td));
    228220      if (arc == null) {
    229         arc = new GenealogyGraphArc(n, last) { Data = td };
     221        arc = new GenealogyGraphArc(current, last) { Data = td };
    230222        traceGraph.AddArc(arc);
    231223      }
     
    233225  }
    234226  // this class is here to help clarify the semantics
    235   internal class TraceData : Tuple<int, int, int, int> {
     227  public class TraceData : Tuple<int, int, int, int> {
    236228    public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex)
    237229      : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Tracking.sln

    r11864 r11881  
    184184    HideSolutionNode = FALSE
    185185  EndGlobalSection
    186   GlobalSection(Performance) = preSolution
    187     HasPerformanceSessions = true
    188   EndGlobalSection
    189186  GlobalSection(TestCaseManagementSettings) = postSolution
    190187    CategoryFile = HeuristicLab.Tracking.vsmdi
Note: See TracChangeset for help on using the changeset viewer.