Changeset 8236 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views
- Timestamp:
- 07/05/12 16:01:37 (12 years ago)
- 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
r8213 r8236 67 67 if (_graph == null) return; 68 68 Chart.UpdateEnabled = false; 69 var layers = Graph.Values.GroupBy(node => node.Rank).OrderBy(g => g.Key); 70 // show elites in every graph level 71 List<GenealogyGraphNode> currLayer = null, prevLayer = null; 72 double currRank = 0.0; 73 int count = layers.Count(); 74 for (int i = 0; i != count; ++i) { 75 // propagate elites from successive layers 76 bool f = currRank % 1 == 0; 77 if (f) // if the rank is an integer, then we need to propagate elites 78 prevLayer = currLayer; 79 currRank = layers.ElementAt(i).Key; 80 currLayer = layers.ElementAt(i).ToList(); 81 if (i > 0 && f) { 82 // this following code injects elites that propagate from the previous generation into the current graph layer, 83 // so that they can be represented as visual nodes 84 int prevEliteCount = prevLayer.Count(node => node.IsElite); 85 int currEliteCount = currLayer.Count(node => node.IsElite); 86 for (int j = currEliteCount; j < prevEliteCount; ++j) 87 currLayer.Add(prevLayer.ElementAt(j)); 88 } 89 currLayer.Sort(); // uses the CompareTo() method inside the GenealogyGraphNode class 90 foreach (var node in currLayer) { 69 70 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(); 72 List<GenealogyGraphNode> currentLayer = null; 73 List<GenealogyGraphNode> previousLayer = null; 74 75 for (int i = 0; i != layers.Count(); ++i) { 76 var layer = layers[i]; 77 double currentRank = layer.Item1; 78 if (i > 0 && currentRank % 1 == 0) { 79 previousLayer = currentLayer; 80 currentLayer = layer.Item2; 81 int d = previousLayer.Count - currentLayer.Count; 82 if (d > 0) 83 currentLayer.AddRange(previousLayer.Take(d)); 84 } else { 85 currentLayer = layer.Item2; 86 } 87 currentLayer.Sort(); // sort descending by quality (using comparison defined in GenealogyGraphNode class) 88 89 x = 0; // reset horizontal coordinate 90 // start laying out visual nodes 91 foreach (var node in currentLayer) { 91 92 var pen = new Pen(Color.LightGray); 92 93 var nl = Environment.NewLine; … … 102 103 _visualNodeMap[node] = new List<VisualGenealogyGraphNode>(); 103 104 _visualNodeMap[node].Add(visualNode); 104 // connect visual nodes that actually represent the same individual 105 // in the genealogy graph (this applies for elites) with a dashed line 106 if (_visualNodeMap[node].Count > 1) { 107 for (int c = _visualNodeMap[node].Count; c >= 2; --c) { 108 var n1 = _visualNodeMap[node][c - 1]; 109 var n2 = _visualNodeMap[node][c - 2]; 110 var visualArc = AddArc(Chart, n1, n2, new Pen(Color.LightGray) { DashStyle = DashStyle.Dash }); 111 _visualArcMap[Tuple.Create(n1, n2)] = visualArc; 112 } 113 } 105 114 106 x += Cx; // increment horizontal coordinate 115 if (node.InEdges == null && _visualNodeMap.ContainsKey(node)) continue; 116 // add visual edges 117 foreach (var arc in node.InEdges) { 118 var parent = arc.Target; 119 // find the visual parent node that is closest to the current node in terms of vertical distance 120 var visualParent = _visualNodeMap[parent].Where(p => p.Center.Y >= visualNode.Center.Y).OrderByDescending(p => p.Center.Y).Last(); 121 DashStyle style; 122 if (visualParent.Data == visualNode.Data) { // if the graph nodes represent the same elite individual 123 style = DashStyle.Dash; 124 } else { 125 style = node.InEdges.Count == 2 ? DashStyle.Solid : DashStyle.Dash; 126 } 127 var arcPen = new Pen(Color.Transparent) { DashStyle = style }; 128 _visualArcMap[Tuple.Create(visualParent, visualNode)] = AddArc(Chart, visualParent, visualNode, arcPen); 129 } 130 } 107 } 108 131 109 y -= Cy; // decrement vertical coordinate (because the origin is upside down) 132 x = 0; // reset horizontal coordinate 110 } 111 // add arcs separately (to avoid some ordering problems) 112 foreach (var node in _visualNodeMap.Keys) { 113 var visualNode = _visualNodeMap[node][0]; 114 if (node.InEdges == null) continue; 115 116 foreach (var arc in node.InEdges) { 117 var visualParent = _visualNodeMap[arc.Target][0]; 118 var pen = new Pen(Color.Transparent); 119 _visualArcMap[Tuple.Create(visualParent, visualNode)] = AddArc(Chart, visualParent, visualNode, pen); 120 } 121 } 122 // connect visual nodes representing the same elite individual with a line 123 foreach (var list in _visualNodeMap.Values.Where(l => l.Count > 1)) { 124 for (int i = 1; i != list.Count; ++i) { 125 var pen = new Pen(Color.LightGray); 126 _visualArcMap[Tuple.Create(list[i - 1], list[i])] = AddArc(Chart, list[i - 1], list[i], pen); 127 } 133 128 } 134 129 … … 187 182 node.Brush = new SolidBrush(node.ToColor()); 188 183 if (node.IncomingArcs != null) 189 foreach (var arc in node.IncomingArcs) 190 if (arc.Source.Data != arc.Target.Data && arc.Source == _visualNodeMap[arc.Source.Data][0]) { 184 foreach (var arc in node.IncomingArcs) { 185 // check if, in case of elites, the target node is the first visual representation of the elite 186 // (for purposes of display consistency) 187 bool isFirst = arc.Source == _visualNodeMap[arc.Source.Data][0]; 188 if (arc.Source.Data != arc.Target.Data && isFirst) { 191 189 var start = new Point((int)arc.Start.X, (int)arc.Start.Y); 192 190 var end = new Point((int)arc.End.X, (int)arc.End.Y); 193 191 arc.Pen.Brush = new LinearGradientBrush(start, end, arc.Source.ToColor(), arc.Target.ToColor()); 194 192 } 193 } 195 194 } 196 195 // highlight descendants … … 198 197 node.Brush = new SolidBrush(node.ToColor()); 199 198 if (node.OutgoingArcs != null) 200 foreach (var arc in node.OutgoingArcs) 201 if (arc.Source.Data != arc.Target.Data && arc.Target == _visualNodeMap[arc.Target.Data][0]) { 199 foreach (var arc in node.OutgoingArcs) { 200 // check if, in case of elites, the target node is the first visual representation of the elite 201 // (for purposes of display consistency) 202 bool isFirst = arc.Target == _visualNodeMap[arc.Target.Data][0]; 203 if (arc.Source.Data != arc.Target.Data && isFirst) { 202 204 var start = new Point((int)arc.Start.X, (int)arc.Start.Y); 203 205 var end = new Point((int)arc.End.X, (int)arc.End.Y); 204 206 arc.Pen.Brush = new LinearGradientBrush(start, end, arc.Source.ToColor(), arc.Target.ToColor()); 205 207 } 208 } 206 209 } 207 210 } else { -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/GenealogyGraphView.cs
r8213 r8236 115 115 foreach (var node in fragment.IterateNodesBreadth()) { 116 116 var visualNode = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node); 117 if (visualNode == null) 118 continue; 117 119 visualNode.FillColor = Color.LightGreen; 118 120 } -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/VisualGenealogyGraphNode.cs
r8213 r8236 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Visualization; 26 27 … … 76 77 77 78 public Color ToColor() { 78 return Color.FromArgb((int)((1 - Data.Quality) * 255), (int)(Data.Quality * 255), 0); 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]; 79 83 } 80 84
Note: See TracChangeset
for help on using the changeset viewer.