[10650] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
| 29 | using HeuristicLab.EvolutionTracking;
|
---|
| 30 | using HeuristicLab.EvolutionTracking.Views;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
| 35 | [View("SymboldDataAnalysisGenealogyView")]
|
---|
| 36 | [Content(typeof(IGenealogyGraph<ISymbolicExpressionTree>), IsDefaultView = true)]
|
---|
| 37 | public partial class SymboldDataAnalysisGenealogyView : ItemView {
|
---|
| 38 | private readonly ISymbolicExpressionTreeNodeSimilarityComparer comparer;
|
---|
| 39 |
|
---|
| 40 | public SymboldDataAnalysisGenealogyView() {
|
---|
| 41 | InitializeComponent();
|
---|
| 42 |
|
---|
| 43 | comparer = new SymbolicExpressionTreeNodeSimilarityComparer();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public new IGenealogyGraph<ISymbolicExpressionTree> Content {
|
---|
| 47 | get { return (IGenealogyGraph<ISymbolicExpressionTree>)base.Content; }
|
---|
| 48 | set { base.Content = value; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | #region event handlers
|
---|
| 52 |
|
---|
| 53 | protected override void OnContentChanged() {
|
---|
| 54 | base.OnContentChanged();
|
---|
| 55 | if (Content != null) {
|
---|
| 56 | genealogyGraphChart.GenealogyGraph = Content;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #endregion
|
---|
| 61 |
|
---|
| 62 | protected override void RegisterContentEvents() {
|
---|
| 63 | genealogyGraphChart.GenealogyGraphNodeClicked += graphChart_GenealogyGraphNodeClicked;
|
---|
| 64 | symbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked += treeChart_SymbolicExpressionNodeClicked;
|
---|
| 65 | base.RegisterContentEvents();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override void DeregisterContentEvents() {
|
---|
| 69 | base.DeregisterContentEvents();
|
---|
| 70 | genealogyGraphChart.GenealogyGraphNodeClicked -= graphChart_GenealogyGraphNodeClicked;
|
---|
| 71 | symbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked -= treeChart_SymbolicExpressionNodeClicked;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public void graphChart_GenealogyGraphNodeClicked(object sender, MouseEventArgs args) {
|
---|
| 75 | var visualNode = (VisualGenealogyGraphNode)sender;
|
---|
| 76 | var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)visualNode.Data;
|
---|
| 77 | var tree = graphNode.Content;
|
---|
| 78 | symbolicExpressionTreeChart.Tree = tree;
|
---|
[10656] | 79 |
|
---|
[10730] | 80 | if (graphNode.InArcs.Any()) {
|
---|
[10656] | 81 | var fragment = (IFragment<ISymbolicExpressionTreeNode>)graphNode.InArcs.Last().Data;
|
---|
[10752] | 82 | if (fragment != null) {
|
---|
[10755] | 83 | treeChart_HighlightSubtree(graphNode.Content.NodeAt(fragment.Index1));
|
---|
[10752] | 84 | }
|
---|
[10656] | 85 | }
|
---|
[10650] | 86 | }
|
---|
| 87 |
|
---|
| 88 | public void treeChart_SymbolicExpressionNodeClicked(object sender, MouseEventArgs args) {
|
---|
| 89 | var visualNode = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender;
|
---|
| 90 | var subtree = visualNode.Content;
|
---|
| 91 |
|
---|
| 92 | // highlight the selected subtree inside the displayed tree on the right hand side
|
---|
| 93 | treeChart_ClearColors();
|
---|
| 94 | treeChart_HighlightSubtree(subtree);
|
---|
| 95 |
|
---|
| 96 | bool trace = genealogyGraphChart.TraceFragments; // check whether the mode is 'trace' or 'match'
|
---|
| 97 |
|
---|
| 98 | if (trace) {
|
---|
| 99 | // perform fragment tracing
|
---|
[10752] | 100 | var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
|
---|
| 101 | var subtreeIndex = graphNode.Content.IterateNodesPrefix().ToList().IndexOf(subtree);
|
---|
| 102 | var fragmentGraph = SymbolicDataAnalysisExpressionTracing.TraceSubtree(graphNode, subtreeIndex);
|
---|
[10755] | 103 | if (fragmentGraph.Nodes.Any()) {
|
---|
| 104 | MainFormManager.MainForm.ShowContent(fragmentGraph); // display the fragment graph on the screen
|
---|
| 105 | }
|
---|
[10650] | 106 | } else {
|
---|
[10654] | 107 | // perform matching like it was done before
|
---|
| 108 | // currently there is no possibility to specify the subtree matching criteria
|
---|
[10685] | 109 | var trees = Content.Nodes.Select(x => x.Content);
|
---|
[10650] | 110 | var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
|
---|
| 111 |
|
---|
[10755] | 112 | var matchingVertices = matchingTrees.Select(x => Content[x]).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>();
|
---|
[10650] | 113 | graphChart_highlightMatchingVertices(matchingVertices);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | private void graphChart_highlightMatchingVertices(IEnumerable<IGenealogyGraphNode> vertices) {
|
---|
| 118 | genealogyGraphChart.Chart.UpdateEnabled = false;
|
---|
| 119 | genealogyGraphChart.ClearPrimitives();
|
---|
| 120 | genealogyGraphChart.HighlightNodes(vertices);
|
---|
| 121 | genealogyGraphChart.Chart.UpdateEnabled = true;
|
---|
| 122 | genealogyGraphChart.Chart.EnforceUpdate();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | private void treeChart_ClearColors() {
|
---|
| 126 | foreach (var node in symbolicExpressionTreeChart.Tree.IterateNodesPrefix()) {
|
---|
| 127 | var visualNode = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node);
|
---|
| 128 | if (visualNode != null) {
|
---|
| 129 | visualNode.LineColor = Color.Black;
|
---|
| 130 | visualNode.FillColor = Color.Transparent;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | symbolicExpressionTreeChart.RepaintNodes();
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | private void treeChart_HighlightSubtree(ISymbolicExpressionTreeNode subtree) {
|
---|
| 137 | foreach (var s in subtree.IterateNodesPrefix()) {
|
---|
| 138 | var visualNode = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(s);
|
---|
| 139 | visualNode.LineColor = Color.RoyalBlue;
|
---|
| 140 | visualNode.FillColor = Color.LightBlue;
|
---|
| 141 |
|
---|
| 142 | foreach (var c in s.Subtrees) {
|
---|
| 143 | var visualArc = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNodeConnection(s, c);
|
---|
| 144 | visualArc.LineColor = Color.RoyalBlue;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | symbolicExpressionTreeChart.RepaintNodes();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | #region events for configuring the behavior of the genealogy chart (trace/match, simple lineages, etc)
|
---|
| 151 | private void trace_checkBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
| 152 | genealogyGraphChart.TraceFragments = trace_checkBox.Checked;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | private void simpleLineages_checkBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
| 156 | genealogyGraphChart.SimpleLineages = simpleLineages_checkBox.Checked;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | private void lockGraph_checkBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
| 160 | genealogyGraphChart.LockGenealogy = lockGraph_checkBox.Checked;
|
---|
| 161 | }
|
---|
| 162 | #endregion
|
---|
| 163 | }
|
---|
| 164 | }
|
---|