Changeset 11881 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
- Timestamp:
- 02/04/15 00:43:44 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.