Changeset 12225
- Timestamp:
- 03/19/15 01:10:21 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphView.cs
r11817 r12225 35 35 protected override void OnContentChanged() { 36 36 base.OnContentChanged(); 37 if (Content != null ) { genealogyGraphChart.GenealogyGraph = Content; }37 if (Content != null && Content != genealogyGraphChart.GenealogyGraph) { genealogyGraphChart.GenealogyGraph = Content; } 38 38 } 39 39 #endregion -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r12208 r12225 368 368 <SubType>Designer</SubType> 369 369 </EmbeddedResource> 370 <EmbeddedResource Include="Tracking\SymbolicDataAnalysisGenealogyGraphView.resx">371 <DependentUpon>SymbolicDataAnalysisGenealogyGraphView.cs</DependentUpon>372 </EmbeddedResource>373 370 </ItemGroup> 374 371 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
r12208 r12225 41 41 private ISymbolicExpressionTreeNode selectedSubtree; 42 42 private ISymbolicExpressionTreeNode SelectedSubtree { 43 get { 44 return selectedSubtree; 45 } 43 get { return selectedSubtree; } 46 44 set { 47 if ( selectedSubtree == value) return;45 if (value == null || selectedSubtree == value) return; 48 46 selectedSubtree = value; 49 47 ClonedSubtree = (ISymbolicExpressionTreeNode)selectedSubtree.Clone(); 50 48 } 51 49 } 52 50 // the clone is necessary in order to deselect parts of a tree (by removing subtrees) 51 // and do "high level" matching of the remaining part 53 52 private ISymbolicExpressionTreeNode ClonedSubtree { get; set; } 53 54 // we use the symbolic expression tree chart to call the drawing routines 55 // and highlight relevant tree parts 56 public SymbolicExpressionTreeChart SymbolicExpressionTreeChart { 57 get { 58 var view = (GraphicalSymbolicExpressionTreeView)base.viewHost.ActiveView; 59 return view == null ? null : view.SymbolicExpressionTreeChart; 60 } 61 } 54 62 55 63 public SymbolicDataAnalysisGenealogyGraphView() { … … 61 69 protected override void OnContentChanged() { 62 70 base.OnContentChanged(); 63 if (Content != null) { genealogyGraphChart.GenealogyGraph = Content; } 64 } 65 #endregion 66 67 public SymbolicExpressionTreeChart SymbolicExpressionTreeChart { 68 get { 69 var view = (GraphicalSymbolicExpressionTreeView)base.viewHost.ActiveView; 70 return view == null ? null : view.SymbolicExpressionTreeChart; 71 } 72 } 73 74 protected override void RegisterContentEvents() { 75 base.RegisterContentEvents(); 76 if (SymbolicExpressionTreeChart != null) 77 SymbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked += treeChart_SymbolicExpressionTreeNodeClicked; 78 } 79 80 protected override void DeregisterContentEvents() { 81 if (SymbolicExpressionTreeChart != null) 82 SymbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked -= treeChart_SymbolicExpressionTreeNodeClicked; 83 base.DeregisterContentEvents(); 71 if (Content != null && Content != genealogyGraphChart.GenealogyGraph) { 72 genealogyGraphChart.GenealogyGraph = Content; 73 } 84 74 } 85 75 … … 110 100 var fragment = data as IFragment<ISymbolicExpressionTreeNode>; 111 101 var td = data as TraceData; 102 // double max = Content.Vertices.SelectMany(x => x.Data.IterateNodesPrefix()).Max(x => x.NodeWeight); 103 112 104 if (fragment != null) { 113 treeChart_HighlightSubtree(graphNode.Data.NodeAt(fragment.Index1)); 105 // treeChart_HighlightSubtree(graphNode.Data.NodeAt(fragment.Index1)); 106 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 107 int c = ColorGradient.Colors.Count - 1; 108 foreach (var n in nodes.Skip(1)) { // skip program root symbol 109 // var i = (int)Math.Round(n.NodeWeight / max * c); 110 // const int alpha = 50; 111 // var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 112 113 // treeChart_HighlightSubtree(n, null, fillColor); 114 } 114 115 } else if (td != null) { 116 115 117 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 118 int c = ColorGradient.Colors.Count - 1; 119 foreach (var n in nodes.Skip(1)) { // skip program root symbol 120 // var i = (int)Math.Round(n.NodeWeight / max * c); 121 // const int alpha = 50; 122 // var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 123 124 // treeChart_HighlightSubtree(n, null, fillColor); 125 } 126 116 127 treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange); 117 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], null, Color.PowderBlue);128 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue); 118 129 } 119 130 } … … 125 136 // highlight the selected subtree inside the displayed tree on the right hand side 126 137 treeChart_ClearColors(); 127 treeChart_HighlightSubtree(subtree );138 treeChart_HighlightSubtree(subtree, Color.Black, Color.RoyalBlue); 128 139 129 140 bool trace = genealogyGraphChart.TraceFragments; // check whether we are in 'trace' or 'match' mode … … 136 147 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 137 148 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree); 138 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex );149 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: true, updateSubtreeWeights: true, cacheTraceNodes: true); 139 150 if (traceGraph.Vertices.Any()) { 140 151 genealogyGraphChart.UpdateEnabled = false; 141 genealogyGraphChart.ClearArcs(); 142 var genealogyNodes = traceGraph.Vertices.Select(v => Content.GetByContent(v.Data)); 143 genealogyGraphChart.HighlightNodes(genealogyNodes, Color.Black, false); 152 genealogyGraphChart.ClearPrimitives(); 153 var traceVertices = traceGraph.Vertices.ToList(); 154 var genealogyNodes = traceVertices.Select(v => Content.GetByContent(v.Data)).ToList(); 155 // color graph vertices according to their weight 156 double max = traceGraph.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(n => x.Weight)); 157 for (int i = 0; i < genealogyNodes.Count; ++i) { 158 var g = genealogyNodes[i]; 159 g.Weight = traceVertices[i].Weight; 160 var v = genealogyGraphChart.GetMappedNode(g); 161 if (v != null) { 162 v.Brush = new SolidBrush(ColorGradient.Colors[(int)Math.Round(g.Weight * (ColorGradient.Colors.Count - 1) / max)]); 163 } 164 } 165 144 166 genealogyGraphChart.UpdateEnabled = true; 145 167 genealogyGraphChart.EnforceUpdate(); 168 146 169 if (openNew_CheckBox.Checked) 147 170 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen 148 149 var max = traceGraph.Vertices.Max(x => x.Weight);150 151 genealogyGraphChart.UpdateEnabled = false;152 foreach (var traceNode in traceGraph.Vertices) {153 var g = Content.GetByContent(traceNode.Data);154 g.Weight = traceNode.Weight;155 var v = genealogyGraphChart.GetMappedNode(g);156 if (v != null) {157 int i = (int)Math.Round(g.Weight * (ColorGradient.Colors.Count - 1) / max);158 159 v.Brush = new SolidBrush(ColorGradient.Colors[i]);160 }161 }162 genealogyGraphChart.UpdateEnabled = true;163 genealogyGraphChart.EnforceUpdate();164 171 } 165 172 } else { … … 188 195 break; 189 196 } 197 } 198 #endregion 199 200 protected override void RegisterContentEvents() { 201 base.RegisterContentEvents(); 202 if (SymbolicExpressionTreeChart != null) 203 SymbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked += treeChart_SymbolicExpressionTreeNodeClicked; 204 } 205 206 protected override void DeregisterContentEvents() { 207 if (SymbolicExpressionTreeChart != null) 208 SymbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked -= treeChart_SymbolicExpressionTreeNodeClicked; 209 base.DeregisterContentEvents(); 190 210 } 191 211 … … 210 230 211 231 private void treeChart_HighlightSubtree(ISymbolicExpressionTreeNode subtree, Color? lineColor = null, Color? fillColor = null) { 212 var lc = lineColor ?? Color.RoyalBlue; 213 var fc = fillColor ?? Color.White; 232 if (lineColor == null && fillColor == null) 233 return; 234 214 235 foreach (var s in subtree.IterateNodesPrefix()) { 215 236 var visualNode = SymbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(s); 216 visualNode.LineColor = lc;217 visualNode.FillColor = fc;218 219 foreach (var c in s.Subtrees) {220 var visualArc = SymbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNodeConnection(s, c);221 visualArc.LineColor = lc;237 if (lineColor != null) { 238 visualNode.LineColor = (Color)lineColor; 239 foreach (var c in s.Subtrees) { 240 var visualArc = SymbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNodeConnection(s, c); 241 visualArc.LineColor = (Color)lineColor; 242 } 222 243 } 244 if (fillColor != null) 245 visualNode.FillColor = (Color)fillColor; 223 246 } 224 247 SymbolicExpressionTreeChart.RepaintNodes(); 225 248 } 226 249 250 #region navigate the genealogy / trace graph 227 251 private void navigateLeftButton_Click(object sender, EventArgs e) { 228 252 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; … … 267 291 } 268 292 } 293 #endregion 269 294 } 295 296 // bogus class needed in order to be able to "design" the view 270 297 public class SymbolicDataAnalysisGenealogyGraphViewDesignable : GenealogyGraphView<ISymbolicExpressionTree> { } 271 298 299 #region helper methods 272 300 internal static class Util { 273 301 internal static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) { … … 278 306 } 279 307 } 308 #endregion 280 309 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r12208 r12225 309 309 <Compile Include="Symbols\VariableTreeNode.cs" /> 310 310 <Compile Include="Tracking\Analyzers\SymbolicDataAnalysisFragmentLengthAnalyzer.cs" /> 311 <Compile Include="Tracking\Analyzers\SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs" /> 311 312 <Compile Include="Tracking\Analyzers\SymbolicDataAnalysisTraceOverlapAnalyzer.cs" /> 312 313 <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11979 r12225 39 39 public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get; private set; } 40 40 41 public bool UpdateVertexWeights { get; set; } 42 public bool UpdateSubtreeWeights { get; set; } 43 public bool CacheTraceNodes { get; set; } 44 41 45 public TraceCalculator() { 46 ResetState(); 47 } 48 49 protected TraceCalculator(TraceCalculator original, Cloner cloner) 50 : base(original, cloner) { 51 } 52 53 public override IDeepCloneable Clone(Cloner cloner) { 54 return new TraceCalculator(this, cloner); 55 } 56 57 public void ResetState() { 42 58 TraceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 43 59 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>(); … … 46 62 } 47 63 48 protected TraceCalculator(TraceCalculator original, Cloner cloner) 49 : base(original, cloner) { 50 } 51 52 public override IDeepCloneable Clone(Cloner cloner) { 53 return new TraceCalculator(this, cloner); 54 } 55 56 public static IGenealogyGraph<ISymbolicExpressionTree> TraceSubtree( 57 IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) { 58 var tc = new TraceCalculator(); 64 public static IGenealogyGraph<ISymbolicExpressionTree> TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, bool updateVertexWeights = false, bool updateSubtreeWeights = false, bool cacheTraceNodes = true) { 65 var tc = new TraceCalculator { 66 UpdateVertexWeights = updateSubtreeWeights, 67 UpdateSubtreeWeights = updateSubtreeWeights, 68 CacheTraceNodes = cacheTraceNodes 69 }; 59 70 tc.Trace(node, subtreeIndex); 60 71 return tc.TraceGraph; 61 72 } 62 73 63 public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex) { 64 TraceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 65 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>(); 66 nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>(); 67 traceCache = new HashSet<Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>>(); 74 public IGenealogyGraph<ISymbolicExpressionTree> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, bool resetState = true) { 75 if (resetState) ResetState(); 68 76 TraceRecursive(node, subtreeIndex); 69 77 return TraceGraph; … … 90 98 /// <param name="subtreeIndex">The index of the traced subtree</param> 91 99 /// <param name="last">The last added node in the trace graph</param> 92 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, 93 IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 100 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 94 101 var g = node; 95 102 int si = subtreeIndex; // subtree index 96 103 int fi = 0; // fragment index 97 104 while (((List<IArc>)((IVertex)g).InArcs).Count > 0) { 98 // while (g.Parents.Any()) {99 105 Debug.Assert(si < g.Data.Length); 100 106 var inArcs = (List<IArc>)((IVertex)g).InArcs; … … 138 144 var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 139 145 var t0 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent0, n, si); 140 if (! traceCache.Contains(t0)) {146 if (!(CacheTraceNodes && traceCache.Contains(t0))) { 141 147 TraceRecursive(parent0, si, n); 142 148 traceCache.Add(t0); 143 } else { 149 } 150 if (UpdateVertexWeights) 144 151 n.Weight++; 145 }146 152 var t1 = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent1, n, fragment.Index2); 147 if (! traceCache.Contains(t1)) {153 if (!(CacheTraceNodes && traceCache.Contains(t1))) { 148 154 TraceRecursive(parent1, fragment.Index2, n); 149 155 traceCache.Add(t1); 150 } else { 156 } 157 // gather statistics about sampled individuals and sampled subtrees 158 if (UpdateVertexWeights) 151 159 n.Weight++; 160 if (UpdateSubtreeWeights) { 161 var arcs = (List<IArc>)((IVertex)n).InArcs; // at this moment n will have been added as a child to the next trace node 162 for (int i = 0; i < arcs.Count; ++i) { 163 var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data; 164 var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source; 165 // TODO: the first part of the check below represents a necessary but not sufficient condition 166 // TODO: therefore, a Difference check is also performed, it would be nice to make this code more ellegant 167 if (td.LastFragmentIndex == td.SubtreeIndex && fragment.Root.Difference(NodeAt(p.Data, td.SubtreeIndex)) == null) { 168 arcs[i].Weight++; 169 break; 170 } 171 } 152 172 } 153 173 break; … … 171 191 int i = si < fi ? si : fi; 172 192 var t = new Tuple<IGenealogyGraphNode<ISymbolicExpressionTree>, IGenealogyGraphNode<ISymbolicExpressionTree>, int>(parent0, n, i); 173 if (! traceCache.Contains(t)) {193 if (!(CacheTraceNodes && traceCache.Contains(t))) { 174 194 TraceRecursive(parent0, i, n); 175 195 traceCache.Add(t); 176 } else { 196 } 197 if (UpdateVertexWeights) 177 198 n.Weight++; 178 }179 199 break; 180 200 } else { … … 204 224 /// <param name="fi">The fragment index</param> 205 225 /// <returns></returns> 206 private IGenealogyGraphNode<ISymbolicExpressionTree> AddTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, 207 int si, int fi) { 226 private IGenealogyGraphNode<ISymbolicExpressionTree> AddTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) { 208 227 var n = TraceGraph.GetByContent(g.Data); 209 228 if (n == null) { … … 239 258 IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) { 240 259 var lastTraceData = traceMap[last]; 241 int lastSi = lastTraceData.SubtreeIndex; 242 // last subtree index (index of the traced subtree in the previous trace node) 243 int lastFi = lastTraceData.FragmentIndex; 244 // last fragment index (index of the fragment in the previous trace node) 260 int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node) 261 int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node) 245 262 var td = new TraceData(si, fi, lastSi, lastFi); // trace data 246 263 // using the inArcs seems to be slightly more efficient than using the outArcs
Note: See TracChangeset
for help on using the changeset viewer.