Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/06/12 11:24:34 (12 years ago)
Author:
bburlacu
Message:

#1772: Separated instance-specific attributes of graph node objects from the generic genealogy graph, into metadata objects kept by the specific graph class which corresponds to the specific problem instance (so for instance the SymbolicExpressionTreeGenealogyGraph will keep info about node ranks and qualities etc because that info is specific to symbolic data analysis problems).

Location:
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4
Files:
3 edited

Legend:

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

    r8236 r8248  
    6969
    7070      var genealogyGraphNodes = Graph.Values.ToList();
    71       var layers = genealogyGraphNodes.GroupBy(n => n.Rank).OrderBy(g => g.Key).Select(g => Tuple.Create(g.Key, g.ToList())).ToList();
     71      var layers = genealogyGraphNodes.GroupBy(n => Graph[n].Ranks[0]).OrderBy(g => g.Key).Select(g => new { Rank = g.Key, Nodes = g.ToList() }).ToList();
    7272      List<GenealogyGraphNode> currentLayer = null;
    7373      List<GenealogyGraphNode> previousLayer = null;
     
    7575      for (int i = 0; i != layers.Count(); ++i) {
    7676        var layer = layers[i];
    77         double currentRank = layer.Item1;
     77        double currentRank = layer.Rank;
    7878        if (i > 0 && currentRank % 1 == 0) {
    7979          previousLayer = currentLayer;
    80           currentLayer = layer.Item2;
     80          currentLayer = layer.Nodes;
    8181          int d = previousLayer.Count - currentLayer.Count;
    8282          if (d > 0)
    8383            currentLayer.AddRange(previousLayer.Take(d));
    8484        } else {
    85           currentLayer = layer.Item2;
    86         }
    87         currentLayer.Sort(); // sort descending by quality (using comparison defined in GenealogyGraphNode class)
     85          currentLayer = layer.Nodes;
     86        }
     87        currentLayer.Sort((b, a) => {
     88          if (Graph[a].Quality.Equals(Graph[b].Quality)) {
     89            if (Graph[a].IsElite) return 1;
     90            if (Graph[b].IsElite) return -1;
     91          }
     92          return Graph[a].Quality.CompareTo(Graph[b].Quality);
     93        }); // sort descending by quality (using comparison defined in GenealogyGraphNode class)
    8894
    8995        x = 0; // reset horizontal coordinate
     
    95101            Data = node,
    96102            ToolTipText = "Id: " + node.Label + nl +
    97                           "Rank: " + node.Rank + nl +
    98                           "Quality: " + String.Format("{0:0.0000}", node.Quality) + nl +
    99                           "IsElite: " + node.IsElite
     103                          "Ranks: " + Graph[node].Ranks + nl +
     104                          "Quality: " + String.Format("{0:0.0000}", Graph[node].Quality) + nl +
     105                          "IsElite: " + Graph[node].IsElite
    100106          };
    101107          Chart.Group.Add(visualNode);
     
    171177          }
    172178          var gNode = _selectedGenealogyGraphNode.Data; // genealogy graph node (representing an individual in the population)
    173           double rank = gNode.Rank;
     179          double rank = Graph[gNode].Ranks[0];
    174180          // ancestors
    175           var ancestors = gNode.Ancestors().Where(a => a.Rank < rank).ToList();
     181          var ancestors = gNode.Ancestors().Where(n => Graph[n].Ranks.Last() < rank).ToList();
    176182          ancestors.Add(gNode);
    177183          // descendants
    178           var descendants = gNode.Descendants().Where(a => a.Rank > rank).ToList();
     184          var descendants = gNode.Descendants().Where(n => Graph[n].Ranks.Last() > rank).ToList();
    179185          descendants.Add(gNode);
    180186          // highlight ancestors
    181187          foreach (var node in ancestors.Select(n => _visualNodeMap[n][0])) {
    182             node.Brush = new SolidBrush(node.ToColor());
     188            node.Brush = new SolidBrush(Graph[node.Data].GetColor());
    183189            if (node.IncomingArcs != null)
    184190              foreach (var arc in node.IncomingArcs) {
     
    186192                // (for purposes of display consistency)
    187193                bool isFirst = arc.Source == _visualNodeMap[arc.Source.Data][0];
    188                 if (arc.Source.Data != arc.Target.Data && isFirst) {
    189                   var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
    190                   var end = new Point((int)arc.End.X, (int)arc.End.Y);
    191                   arc.Pen.Brush = new LinearGradientBrush(start, end, arc.Source.ToColor(), arc.Target.ToColor());
    192                 }
     194                if (arc.Source.Data == arc.Target.Data || !isFirst) continue;
     195                var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
     196                var end = new Point((int)arc.End.X, (int)arc.End.Y);
     197                arc.Pen.Brush = new LinearGradientBrush(start, end, Graph[arc.Source.Data].GetColor(), Graph[arc.Target.Data].GetColor());
    193198              }
    194199          }
    195200          // highlight descendants
    196201          foreach (var node in descendants.Select(n => _visualNodeMap[n][0])) {
    197             node.Brush = new SolidBrush(node.ToColor());
     202            node.Brush = new SolidBrush(Graph[node.Data].GetColor());
    198203            if (node.OutgoingArcs != null)
    199204              foreach (var arc in node.OutgoingArcs) {
     
    201206                // (for purposes of display consistency)
    202207                bool isFirst = arc.Target == _visualNodeMap[arc.Target.Data][0];
    203                 if (arc.Source.Data != arc.Target.Data && isFirst) {
    204                   var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
    205                   var end = new Point((int)arc.End.X, (int)arc.End.Y);
    206                   arc.Pen.Brush = new LinearGradientBrush(start, end, arc.Source.ToColor(), arc.Target.ToColor());
    207                 }
     208                if (arc.Source.Data == arc.Target.Data || !isFirst) continue;
     209                var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
     210                var end = new Point((int)arc.End.X, (int)arc.End.Y);
     211                arc.Pen.Brush = new LinearGradientBrush(start, end, Graph[arc.Source.Data].GetColor(), Graph[arc.Target.Data].GetColor());
    208212              }
    209213          }
     
    222226    public void ClearAllNodes() {
    223227      foreach (var primitive in Chart.Group.Primitives) {
    224         if (primitive.Brush != null)
    225           primitive.Brush = null;
     228        primitive.Brush = null;
    226229        if (primitive is VisualGenealogyGraphArc) {
    227230          var arc = primitive as VisualGenealogyGraphArc;
     
    234237    public void HighlightLineage(IEnumerable<GenealogyGraphNode> nodes) {
    235238      foreach (var node in nodes.SelectMany(n => _visualNodeMap[n])) {
    236         node.Brush = new SolidBrush(node.ToColor());
    237         if (node.IncomingArcs != null && node == _visualNodeMap[node.Data][0]) {
    238           foreach (var arc in node.IncomingArcs) {
    239             if (arc.Source.Data == node.Data) continue;
    240             var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
    241             var end = new Point((int)arc.End.X, (int)arc.End.Y);
    242             arc.Pen.Brush = new LinearGradientBrush(start, end, arc.Source.ToColor(), arc.Target.ToColor());
    243           }
     239        node.Brush = new SolidBrush(Graph[node.Data].GetColor());
     240        if (node.IncomingArcs == null || node != _visualNodeMap[node.Data][0]) continue;
     241        foreach (var arc in node.IncomingArcs) {
     242          if (arc.Source.Data == node.Data) continue;
     243          var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
     244          var end = new Point((int)arc.End.X, (int)arc.End.Y);
     245          arc.Pen.Brush = new LinearGradientBrush(start, end, Graph[arc.Source.Data].GetColor(), Graph[arc.Target.Data].GetColor());
    244246        }
    245247      }
     
    284286    }
    285287  }
     288
     289  internal static class Util {
     290    public static Color GetColor(this NodeMetadata nm) {
     291      var colorIndex = (int)(nm.Quality * ColorGradient.Colors.Count);
     292      if (colorIndex >= ColorGradient.Colors.Count) --colorIndex;
     293      return ColorGradient.Colors[colorIndex];
     294    }
     295  }
    286296}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/GenealogyGraphView.cs

    r8236 r8248  
    7171      else {
    7272        genealogyGraphChart.Graph = Content;
    73         var best = Content.Values.OrderByDescending(x => x.Quality).First();
     73        var best = Content.Values.OrderByDescending(x => genealogyGraphChart.Graph[x].Quality).First();
    7474        symbolicExpressionTreeChart.Tree = (ISymbolicExpressionTree)best.Data;
    7575      }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/VisualGenealogyGraphNode.cs

    r8236 r8248  
    2323using System.Collections.Generic;
    2424using System.Drawing;
    25 using HeuristicLab.Common;
    2625using HeuristicLab.Visualization;
    2726
     
    7574      get { return new PointD((LowerLeft.X + UpperRight.X) / 2, (LowerLeft.Y + UpperRight.Y) / 2); }
    7675    }
    77 
    78     public Color ToColor() {
    79       //      return Color.FromArgb((int)((1 - Data.Quality) * 255), (int)(Data.Quality * 255), 0);
    80       int i = (int)(Data.Quality * ColorGradient.Colors.Count);
    81       if (i == ColorGradient.Colors.Count) --i;
    82       return ColorGradient.Colors[i];
    83     }
    84 
    85     public override void Draw(Graphics graphics) {
    86       if (Data.IsElite) {
    87         Point p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
    88         Size s = Chart.TransformWorldToPixel(Size);
    89         if (Brush != null)
    90           graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height);
    91         graphics.DrawEllipse(Pen, p.X, p.Y, s.Width, s.Height);
    92         graphics.DrawEllipse(Pen, p.X + 2, p.Y + 2, s.Width - 4, s.Height - 4);
    93       } else {
    94         base.Draw(graphics);
    95       }
    96     }
    9776  }
    9877}
Note: See TracChangeset for help on using the changeset viewer.