- Timestamp:
- 02/04/15 00:43:44 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs
r11864 r11881 43 43 private Dictionary<Tuple<VisualGenealogyGraphNode, VisualGenealogyGraphNode>, VisualGenealogyGraphArc> arcMap; 44 44 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 45 53 public IGenealogyGraph GenealogyGraph { 46 54 get { return genealogyGraph; } … … 79 87 } 80 88 81 #region chart modes82 public bool SimpleLineages { get; set; }83 public bool LockGenealogy { get; set; }84 public bool TraceFragments { get; set; }85 #endregion86 87 89 private Visualization.Rectangle TargetRectangle { get; set; } 88 private bool DrawInProgress { get; set; } // do not try to update the chart while the drawing is not finished89 90 protected VisualGenealogyGraphNode SelectedVisualNode { get; set; } 90 91 … … 163 164 } 164 165 } 165 // TODO: connect elites166 166 167 167 Chart.UpdateEnabled = true; … … 200 200 base.pictureBox_MouseMove(sender, e); 201 201 } 202 202 203 protected override void pictureBox_MouseUp(object sender, MouseEventArgs e) { 203 204 Cursor = Cursors.Default; … … 252 253 #endregion 253 254 255 #region drawing routines 254 256 private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector) { 255 257 var brush = (SolidBrush)node.Brush; … … 269 271 } 270 272 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 weights276 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 300 273 void MarkSelectedNode() { 301 274 var center = SelectedVisualNode.Center; … … 342 315 primitive.Brush = new SolidBrush(Color.Transparent); 343 316 primitive.Pen = new Pen(Color.DarkGray); 344 // primitive.Pen = Pens.Transparent; // remove the node contour345 317 } 346 318 } … … 387 359 arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor()); 388 360 } 361 #endregion 389 362 } 390 363 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
r11864 r11881 26 26 using System.Windows.Forms; 27 27 using HeuristicLab.Common; 28 using HeuristicLab.Core; 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; … … 81 82 // get the ancestors into a new view 82 83 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 84 86 var graph = new GenealogyGraph<ISymbolicExpressionTree>(); 85 87 var ancestors = new[] { graphNode }.Concat(graphNode.Ancestors); … … 89 91 graph.AddArc(cloner.Clone(arc)); 90 92 } 91 // graph.AddVertices(graphNode.Ancestors);92 93 MainFormManager.MainForm.ShowContent(graph); 93 94 } 94 95 95 96 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; 97 100 if (fragment != null) { 98 101 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); 108 106 } 109 107 } … … 127 125 genealogyGraphChart.UpdateEnabled = false; 128 126 genealogyGraphChart.ClearArcs(); 129 // genealogyGraphChart.ClearPrimitives();130 127 var genealogyNodes = traceGraph.Vertices.Select(v => Content.GetByContent(v.Data)); 131 // genealogyGraphChart.HighlightNodes(graphNode.Ancestors, Color.Gray, false);132 128 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 // }136 129 genealogyGraphChart.UpdateEnabled = true; 137 130 genealogyGraphChart.EnforceUpdate(); … … 184 177 private void navigateLeftButton_Click(object sender, EventArgs e) { 185 178 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; 188 182 } 189 183 } … … 191 185 private void navigateRightButton_Click(object sender, EventArgs e) { 192 186 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 } 195 217 } 196 218 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11866 r11881 58 58 tc.Trace(node, subtreeIndex); 59 59 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;67 60 } 68 61 … … 97 90 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 98 91 var g = node; 99 int si = subtreeIndex; 92 int si = subtreeIndex; // subtree index 93 int fi = 0; // fragment index 100 94 while (g.Parents.Any()) { 101 95 Debug.Assert(si < g.Data.Length); … … 109 103 } 110 104 111 intfi = fragment.Index1; // fragment index105 fi = fragment.Index1; // fragment index 112 106 int fl = fragment.Root.GetLength(); // fragment length 113 107 int sl = NodeAt(g.Data, si).GetLength(); // subtree length … … 137 131 if (fi < si + sl) { 138 132 // 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 parent133 var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 140 134 TraceRecursive(parent0, si, n); 141 135 TraceRecursive(parent1, fragment.Index2, n); … … 157 151 // check if the subtree and the fragment overlap => branch out 158 152 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 parent153 var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 160 154 int i = si < fi ? si : fi; 161 155 TraceRecursive(parent0, i, n); … … 173 167 } 174 168 // 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); 176 173 } 177 174 … … 184 181 /// <param name="fi">The fragment index</param> 185 182 /// <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) { 187 184 var n = traceGraph.GetByContent(g.Data); 188 185 if (n == null) { … … 211 208 /// of the genealogy graph node @g. 212 209 /// </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> 214 212 /// <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) { 223 215 var lastTraceData = traceMap[last]; 224 216 int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node) 225 217 int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node) 226 218 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)); 228 220 if (arc == null) { 229 arc = new GenealogyGraphArc( n, last) { Data = td };221 arc = new GenealogyGraphArc(current, last) { Data = td }; 230 222 traceGraph.AddArc(arc); 231 223 } … … 233 225 } 234 226 // this class is here to help clarify the semantics 235 internalclass TraceData : Tuple<int, int, int, int> {227 public class TraceData : Tuple<int, int, int, int> { 236 228 public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex) 237 229 : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Tracking.sln
r11864 r11881 184 184 HideSolutionNode = FALSE 185 185 EndGlobalSection 186 GlobalSection(Performance) = preSolution187 HasPerformanceSessions = true188 EndGlobalSection189 186 GlobalSection(TestCaseManagementSettings) = postSolution 190 187 CategoryFile = HeuristicLab.Tracking.vsmdi
Note: See TracChangeset
for help on using the changeset viewer.